| Línea 18... |
Línea 18... |
| 18 |
|
18 |
|
| Línea 19... |
Línea 19... |
| 19 |
namespace core_role\reportbuilder\datasource;
|
19 |
namespace core_role\reportbuilder\datasource;
|
| 20 |
|
20 |
|
| 21 |
use core\context\course;
|
- |
|
| 22 |
use core_reportbuilder_generator;
|
21 |
use core\context\course;
|
| 23 |
use core_reportbuilder_testcase;
|
- |
|
| 24 |
use core_reportbuilder\local\filters\{date, select, text};
|
- |
|
| 25 |
|
- |
|
| 26 |
defined('MOODLE_INTERNAL') || die();
|
- |
|
| 27 |
|
22 |
use core_reportbuilder_generator;
|
| Línea 28... |
Línea 23... |
| 28 |
global $CFG;
|
23 |
use core_reportbuilder\local\filters\{date, select, text};
|
| 29 |
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
|
24 |
use core_reportbuilder\tests\core_reportbuilder_testcase;
|
| 30 |
|
25 |
|
| 31 |
/**
|
26 |
/**
|
| 32 |
* Unit tests for roles datasource
|
27 |
* Unit tests for roles datasource
|
| 33 |
*
|
28 |
*
|
| 34 |
* @package core_role
|
29 |
* @package core_role
|
| 35 |
* @covers \core_role\reportbuilder\datasource\roles;
|
30 |
* @covers \core_role\reportbuilder\datasource\roles
|
| 36 |
* @copyright 2024 Paul Holden <paulh@moodle.com>
|
31 |
* @copyright 2024 Paul Holden <paulh@moodle.com>
|
| Línea 102... |
Línea 97... |
| 102 |
$report = $generator->create_report(['name' => 'Roles', 'source' => roles::class, 'default' => 0]);
|
97 |
$report = $generator->create_report(['name' => 'Roles', 'source' => roles::class, 'default' => 0]);
|
| Línea 103... |
Línea 98... |
| 103 |
|
98 |
|
| 104 |
// Role.
|
99 |
// Role.
|
| 105 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:name']);
|
100 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:name']);
|
| - |
|
101 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:shortname']);
|
| 106 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:shortname']);
|
102 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:archetype']);
|
| Línea 107... |
Línea 103... |
| 107 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:description']);
|
103 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:description']);
|
| 108 |
|
104 |
|
| 109 |
// Role assignment.
|
105 |
// Role assignment.
|
| 110 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:timemodified']);
|
106 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:timemodified']);
|
| Línea 111... |
Línea 107... |
| 111 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:component']);
|
107 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:component']);
|
| 112 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:itemid']);
|
108 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role_assignment:itemid']);
|
| Línea -... |
Línea 109... |
| - |
|
109 |
|
| - |
|
110 |
$content = $this->get_custom_report_content($report->get('id'));
|
| - |
|
111 |
$this->assertCount(1, $content);
|
| - |
|
112 |
|
| - |
|
113 |
[
|
| - |
|
114 |
$rolename,
|
| - |
|
115 |
$roleshortname,
|
| - |
|
116 |
$rolearchetype,
|
| 113 |
|
117 |
$roledescription,
|
| Línea 114... |
Línea 118... |
| 114 |
$content = $this->get_custom_report_content($report->get('id'));
|
118 |
$timemodified,
|
| 115 |
$this->assertCount(1, $content);
|
119 |
$component,
|
| 116 |
|
120 |
$itemid,
|
| - |
|
121 |
] = array_values($content[0]);
|
| 117 |
[$rolename, $roleshortname, $roledescription, $timemodified, $component, $itemid] = array_values($content[0]);
|
122 |
|
| 118 |
|
123 |
// Role.
|
| Línea 119... |
Línea 124... |
| 119 |
// Role.
|
124 |
$this->assertEquals('Moocher (Manager)', $rolename);
|
| 120 |
$this->assertEquals('Moocher (Manager)', $rolename);
|
125 |
$this->assertEquals('manager', $roleshortname);
|
| Línea 142... |
Línea 147... |
| 142 |
'role:name_operator' => select::EQUAL_TO,
|
147 |
'role:name_operator' => select::EQUAL_TO,
|
| 143 |
'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'student']),
|
148 |
'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'student']),
|
| 144 |
], true],
|
149 |
], true],
|
| 145 |
'Filter role name (no match)' => ['role:name', [
|
150 |
'Filter role name (no match)' => ['role:name', [
|
| 146 |
'role:name_operator' => select::EQUAL_TO,
|
151 |
'role:name_operator' => select::EQUAL_TO,
|
| - |
|
152 |
'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'teacher']),
|
| - |
|
153 |
], false],
|
| - |
|
154 |
'Filter role archetype' => ['role:archetype', [
|
| - |
|
155 |
'role:archetype_operator' => select::EQUAL_TO,
|
| 147 |
'role:name_value' => -1,
|
156 |
'role:archetype_value' => 'student',
|
| - |
|
157 |
], true],
|
| - |
|
158 |
'Filter role archetype (no match)' => ['role:archetype', [
|
| - |
|
159 |
'role:archetype_operator' => select::EQUAL_TO,
|
| - |
|
160 |
'role:archetype_value' => 'teacher',
|
| 148 |
], false],
|
161 |
], false],
|
| Línea 149... |
Línea 162... |
| 149 |
|
162 |
|
| 150 |
// Role assignment.
|
163 |
// Role assignment.
|
| 151 |
'Filter role assignment time modified' => ['role_assignment:timemodified', [
|
164 |
'Filter role assignment time modified' => ['role_assignment:timemodified', [
|