1441 |
ariadna |
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 core_calendar;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Renderer testcase.
|
|
|
21 |
*
|
|
|
22 |
* @covers \core_calendar_renderer
|
|
|
23 |
* @package core_calendar
|
|
|
24 |
* @copyright 2025 The Open University
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
final class renderer_test extends \advanced_testcase {
|
|
|
28 |
/**
|
|
|
29 |
* Tests {@see \core_calendar_renderer::course_filter_selector()} shows course names correctly
|
|
|
30 |
* depending on admin settings.
|
|
|
31 |
*/
|
|
|
32 |
public function test_course_filter_selector_names(): void {
|
|
|
33 |
global $PAGE, $CFG;
|
|
|
34 |
|
|
|
35 |
require_once($CFG->dirroot . '/calendar/lib.php');
|
|
|
36 |
$this->resetAfterTest();
|
|
|
37 |
|
|
|
38 |
// Create 2 courses.
|
|
|
39 |
$generator = self::getDataGenerator();
|
|
|
40 |
$course1 = $generator->create_course(['shortname' => 'C1', 'fullname' => 'Course 1']);
|
|
|
41 |
$course2 = $generator->create_course(['shortname' => 'C2', 'fullname' => 'Course 2']);
|
|
|
42 |
|
|
|
43 |
// User is enrolled in both courses.
|
|
|
44 |
$user = $generator->create_user();
|
|
|
45 |
$generator->enrol_user($user->id, $course1->id, 'teacher');
|
|
|
46 |
$generator->enrol_user($user->id, $course2->id, 'teacher');
|
|
|
47 |
|
|
|
48 |
// Get course selector for user.
|
|
|
49 |
$this->setUser($user);
|
|
|
50 |
$renderer = $PAGE->get_renderer('core_calendar');
|
|
|
51 |
$html = $renderer->course_filter_selector(new \moodle_url('/'));
|
|
|
52 |
|
|
|
53 |
// It should contain courses by fullname.
|
|
|
54 |
$this->assertStringContainsString(
|
|
|
55 |
'<option value="' . $course1->id . '">Course 1</option>',
|
|
|
56 |
$html,
|
|
|
57 |
);
|
|
|
58 |
$this->assertStringContainsString(
|
|
|
59 |
'<option value="' . $course2->id . '">Course 2</option>',
|
|
|
60 |
$html,
|
|
|
61 |
);
|
|
|
62 |
|
|
|
63 |
// Turn on the option to show shortnames as well.
|
|
|
64 |
set_config('courselistshortnames', true);
|
|
|
65 |
|
|
|
66 |
$html = $renderer->course_filter_selector(new \moodle_url('/'));
|
|
|
67 |
|
|
|
68 |
// It should contain courses by fullname and shortname.
|
|
|
69 |
$this->assertStringContainsString(
|
|
|
70 |
'<option value="' . $course1->id . '">C1 Course 1</option>',
|
|
|
71 |
$html,
|
|
|
72 |
);
|
|
|
73 |
$this->assertStringContainsString(
|
|
|
74 |
'<option value="' . $course2->id . '">C2 Course 2</option>',
|
|
|
75 |
$html,
|
|
|
76 |
);
|
|
|
77 |
}
|
|
|
78 |
}
|