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 core\output;
|
|
|
18 |
use ReflectionMethod;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Participants tertiary navigation renderable test
|
|
|
22 |
*
|
|
|
23 |
* @package core
|
|
|
24 |
* @category output
|
|
|
25 |
* @copyright 2021 onwards Peter Dias
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class participants_action_bar_test extends \advanced_testcase {
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Test the get_content_for_select function
|
|
|
32 |
*
|
|
|
33 |
* @dataProvider get_content_for_select_provider
|
|
|
34 |
* @param string $type Whether we are checking content in the course/module
|
|
|
35 |
* @param int $expectedcount Expected number of 1st level tertiary items
|
|
|
36 |
* @param array $expecteditems Expected keys of the 1st level tertiary items.
|
|
|
37 |
*/
|
11 |
efrain |
38 |
public function test_get_content_for_select($type, $expectedcount, $expecteditems): void {
|
1 |
efrain |
39 |
global $PAGE;
|
|
|
40 |
$this->resetAfterTest();
|
|
|
41 |
$course = $this->getDataGenerator()->create_course();
|
|
|
42 |
$module = $this->getDataGenerator()->create_module('assign', [
|
|
|
43 |
'course' => $course->id
|
|
|
44 |
]);
|
|
|
45 |
if ($type == 'course') {
|
|
|
46 |
$context = \context_course::instance($course->id);
|
|
|
47 |
$url = new \moodle_url('/course/view.php', ['id' => $course->id]);
|
|
|
48 |
} else {
|
|
|
49 |
$url = new \moodle_url('/mod/assign/view.php', ['id' => $module->id]);
|
|
|
50 |
$context = \context_module::instance($module->cmid);
|
|
|
51 |
$cm = get_coursemodule_from_instance('assign', $module->id, $course->id);
|
|
|
52 |
$PAGE->set_cm($cm);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
$this->setAdminUser();
|
|
|
56 |
$PAGE->set_url($url);
|
|
|
57 |
$PAGE->set_context($context);
|
|
|
58 |
$output = new participants_action_bar($course, $PAGE, null);
|
|
|
59 |
$method = new ReflectionMethod('\core\output\participants_action_bar', 'get_content_for_select');
|
|
|
60 |
$renderer = $PAGE->get_renderer('core');
|
|
|
61 |
|
|
|
62 |
$response = $method->invoke($output, $renderer);
|
|
|
63 |
$this->assertCount($expectedcount, $response);
|
|
|
64 |
$this->assertSame($expecteditems, array_keys(array_merge(...$response)));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Provider for test_get_content_for_select
|
|
|
69 |
* @return array[]
|
|
|
70 |
*/
|
|
|
71 |
public function get_content_for_select_provider() {
|
|
|
72 |
return [
|
|
|
73 |
'Get dropdown content when in a course context' => [
|
|
|
74 |
'course', 3, ['Enrolments', 'Groups', 'Permissions']
|
|
|
75 |
],
|
|
|
76 |
'Get dropdown content when in a module context' => [
|
|
|
77 |
'module', 1, ['Permissions']
|
|
|
78 |
]
|
|
|
79 |
];
|
|
|
80 |
}
|
|
|
81 |
}
|