1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace block_accessreview;
|
|
|
18 |
|
|
|
19 |
use ReflectionClass;
|
|
|
20 |
use advanced_testcase;
|
|
|
21 |
use block_accessreview;
|
|
|
22 |
use context_course;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* PHPUnit block_accessibility_review tests
|
|
|
26 |
*
|
|
|
27 |
* @package block_accessreview
|
|
|
28 |
* @copyright 2020 onward: Learning Technology Services, www.lts.ie
|
|
|
29 |
* @author Jay Churchward (jay.churchward@poetopensource.org)
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
* @coversDefaultClass \block_accessreview
|
|
|
32 |
*/
|
|
|
33 |
class accessibility_review_test extends advanced_testcase {
|
|
|
34 |
public static function setUpBeforeClass(): void {
|
|
|
35 |
require_once(__DIR__ . '/../../moodleblock.class.php');
|
|
|
36 |
require_once(__DIR__ . '/../block_accessreview.php');
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public function test_get_toggle_link() {
|
|
|
40 |
$rc = new ReflectionClass(block_accessreview::class);
|
|
|
41 |
$rm = $rc->getMethod('get_toggle_link');
|
|
|
42 |
|
|
|
43 |
$block = new block_accessreview();
|
|
|
44 |
$output = $rm->invoke($block);
|
|
|
45 |
$this->assertNotEmpty($output);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public function test_get_download_link() {
|
|
|
49 |
$this->resetAfterTest();
|
|
|
50 |
|
|
|
51 |
$user1 = $this->getDataGenerator()->create_user();
|
|
|
52 |
$user2 = $this->getDataGenerator()->create_user();
|
|
|
53 |
|
|
|
54 |
$course = $this->getDataGenerator()->create_course();
|
|
|
55 |
|
|
|
56 |
// Enrol users in the course.
|
|
|
57 |
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
|
|
|
58 |
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
|
|
|
59 |
|
|
|
60 |
$rc = new ReflectionClass(block_accessreview::class);
|
|
|
61 |
$rm = $rc->getMethod('get_download_link');
|
|
|
62 |
$block = new block_accessreview();
|
|
|
63 |
|
|
|
64 |
$this->setUser($user1);
|
|
|
65 |
$result = $rm->invoke($block, context_course::instance($course->id));
|
|
|
66 |
$this->assertNotEmpty($result);
|
|
|
67 |
|
|
|
68 |
$this->setUser($user2);
|
|
|
69 |
$result = $rm->invoke($block, context_course::instance($course->id));
|
|
|
70 |
$this->assertEmpty($result);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public function test_get_report_link() {
|
|
|
74 |
$this->resetAfterTest();
|
|
|
75 |
|
|
|
76 |
$user1 = $this->getDataGenerator()->create_user();
|
|
|
77 |
$user2 = $this->getDataGenerator()->create_user();
|
|
|
78 |
|
|
|
79 |
$course = $this->getDataGenerator()->create_course();
|
|
|
80 |
|
|
|
81 |
// Enrol users in the course.
|
|
|
82 |
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
|
|
|
83 |
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
|
|
|
84 |
|
|
|
85 |
$rc = new ReflectionClass(block_accessreview::class);
|
|
|
86 |
$rm = $rc->getMethod('get_report_link');
|
|
|
87 |
$block = new block_accessreview();
|
|
|
88 |
|
|
|
89 |
$this->setUser($user1);
|
|
|
90 |
$result = $rm->invoke($block, context_course::instance($course->id));
|
|
|
91 |
$this->assertNotEmpty($result);
|
|
|
92 |
|
|
|
93 |
$this->setUser($user2);
|
|
|
94 |
$result = $rm->invoke($block, context_course::instance($course->id));
|
|
|
95 |
$this->assertEmpty($result);
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Test the behaviour of can_block_be_added() method.
|
|
|
100 |
*
|
|
|
101 |
* @covers ::can_block_be_added
|
|
|
102 |
*/
|
|
|
103 |
public function test_can_block_be_added(): void {
|
|
|
104 |
$this->resetAfterTest();
|
|
|
105 |
$this->setAdminUser();
|
|
|
106 |
|
|
|
107 |
// Create a course and prepare the page where the block will be added.
|
|
|
108 |
$course = $this->getDataGenerator()->create_course();
|
|
|
109 |
$page = new \moodle_page();
|
|
|
110 |
$page->set_context(context_course::instance($course->id));
|
|
|
111 |
$page->set_pagelayout('course');
|
|
|
112 |
|
|
|
113 |
$block = new block_accessreview();
|
|
|
114 |
|
|
|
115 |
// If the accessibility tools is enabled, the method should return true.
|
|
|
116 |
set_config('enableaccessibilitytools', true);
|
|
|
117 |
$this->assertTrue($block->can_block_be_added($page));
|
|
|
118 |
|
|
|
119 |
// However, if the accessibility tools is disabled, the method should return false.
|
|
|
120 |
set_config('enableaccessibilitytools', false);
|
|
|
121 |
$this->assertFalse($block->can_block_be_added($page));
|
|
|
122 |
}
|
|
|
123 |
}
|