Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 */
1441 ariadna 33
final class accessibility_review_test extends advanced_testcase {
1 efrain 34
    public static function setUpBeforeClass(): void {
35
        require_once(__DIR__ . '/../../moodleblock.class.php');
36
        require_once(__DIR__ . '/../block_accessreview.php');
1441 ariadna 37
        parent::setUpBeforeClass();
1 efrain 38
    }
39
 
11 efrain 40
    public function test_get_toggle_link(): void {
1 efrain 41
        $rc = new ReflectionClass(block_accessreview::class);
42
        $rm = $rc->getMethod('get_toggle_link');
43
 
44
        $block = new block_accessreview();
45
        $output = $rm->invoke($block);
46
        $this->assertNotEmpty($output);
47
    }
48
 
11 efrain 49
    public function test_get_download_link(): void {
1 efrain 50
        $this->resetAfterTest();
51
 
52
        $user1 = $this->getDataGenerator()->create_user();
53
        $user2 = $this->getDataGenerator()->create_user();
54
 
55
        $course = $this->getDataGenerator()->create_course();
56
 
57
        // Enrol users in the course.
58
        $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
59
        $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
60
 
61
        $rc = new ReflectionClass(block_accessreview::class);
62
        $rm = $rc->getMethod('get_download_link');
63
        $block = new block_accessreview();
64
 
65
        $this->setUser($user1);
66
        $result = $rm->invoke($block, context_course::instance($course->id));
67
        $this->assertNotEmpty($result);
68
 
69
        $this->setUser($user2);
70
        $result = $rm->invoke($block, context_course::instance($course->id));
71
        $this->assertEmpty($result);
72
    }
73
 
11 efrain 74
    public function test_get_report_link(): void {
1 efrain 75
        $this->resetAfterTest();
76
 
77
        $user1 = $this->getDataGenerator()->create_user();
78
        $user2 = $this->getDataGenerator()->create_user();
79
 
80
        $course = $this->getDataGenerator()->create_course();
81
 
82
        // Enrol users in the course.
83
        $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
84
        $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
85
 
86
        $rc = new ReflectionClass(block_accessreview::class);
87
        $rm = $rc->getMethod('get_report_link');
88
        $block = new block_accessreview();
89
 
90
        $this->setUser($user1);
91
        $result = $rm->invoke($block, context_course::instance($course->id));
92
        $this->assertNotEmpty($result);
93
 
94
        $this->setUser($user2);
95
        $result = $rm->invoke($block, context_course::instance($course->id));
96
        $this->assertEmpty($result);
97
    }
98
 
99
    /**
100
     * Test the behaviour of can_block_be_added() method.
101
     *
102
     * @covers ::can_block_be_added
103
     */
104
    public function test_can_block_be_added(): void {
105
        $this->resetAfterTest();
106
        $this->setAdminUser();
107
 
108
        // Create a course and prepare the page where the block will be added.
109
        $course = $this->getDataGenerator()->create_course();
110
        $page = new \moodle_page();
111
        $page->set_context(context_course::instance($course->id));
112
        $page->set_pagelayout('course');
113
 
114
        $block = new block_accessreview();
115
 
116
        // If the accessibility tools is enabled, the method should return true.
117
        set_config('enableaccessibilitytools', true);
118
        $this->assertTrue($block->can_block_be_added($page));
119
 
120
        // However, if the accessibility tools is disabled, the method should return false.
121
        set_config('enableaccessibilitytools', false);
122
        $this->assertFalse($block->can_block_be_added($page));
123
    }
124
}