| Línea 18... |
Línea 18... |
| 18 |
|
18 |
|
| Línea 19... |
Línea 19... |
| 19 |
namespace core_course\reportbuilder\datasource;
|
19 |
namespace core_course\reportbuilder\datasource;
|
| 20 |
|
20 |
|
| 21 |
use completion_completion;
|
- |
|
| 22 |
use completion_criteria_self;
|
- |
|
| 23 |
use core_reportbuilder\local\filters\boolean_select;
|
- |
|
| 24 |
use core_reportbuilder\local\filters\date;
|
- |
|
| 25 |
use core_reportbuilder\local\filters\duration;
|
- |
|
| 26 |
use core_reportbuilder\local\filters\select;
|
21 |
use completion_completion;
|
| - |
|
22 |
use completion_criteria_self;
|
| 27 |
use core_reportbuilder\local\filters\text;
|
23 |
use core_reportbuilder_generator;
|
| 28 |
use core_reportbuilder_generator;
|
24 |
use core_reportbuilder\local\filters\{boolean_select, date, duration, select, text};
|
| 29 |
use core_reportbuilder_testcase;
|
25 |
use core_reportbuilder\tests\core_reportbuilder_testcase;
|
| Línea 30... |
Línea -... |
| 30 |
use core_user;
|
- |
|
| 31 |
use grade_item;
|
- |
|
| 32 |
|
- |
|
| 33 |
defined('MOODLE_INTERNAL') || die();
|
- |
|
| 34 |
|
- |
|
| 35 |
global $CFG;
|
26 |
use core\user;
|
| 36 |
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
|
27 |
use grade_item;
|
| 37 |
|
28 |
|
| 38 |
/**
|
29 |
/**
|
| 39 |
* Course participants datasource tests
|
30 |
* Course participants datasource tests
|
| 40 |
*
|
31 |
*
|
| 41 |
* @package core_course
|
32 |
* @package core_course
|
| 42 |
* @covers \core_course\reportbuilder\datasource\participants
|
33 |
* @covers \core_course\reportbuilder\datasource\participants
|
| 43 |
* @copyright 2022 David Matamoros <davidmc@moodle.com>
|
34 |
* @copyright 2022 David Matamoros <davidmc@moodle.com>
|
| Línea 44... |
Línea 35... |
| 44 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 45 |
*/
|
36 |
*/
|
| 46 |
class participants_test extends core_reportbuilder_testcase {
|
37 |
final class participants_test extends core_reportbuilder_testcase {
|
| 47 |
|
38 |
|
| 48 |
/**
|
39 |
/**
|
| Línea 49... |
Línea 40... |
| 49 |
* Load required test libraries
|
40 |
* Load required test libraries
|
| 50 |
*/
|
41 |
*/
|
| - |
|
42 |
public static function setUpBeforeClass(): void {
|
| 51 |
public static function setUpBeforeClass(): void {
|
43 |
global $CFG;
|
| Línea 52... |
Línea 44... |
| 52 |
global $CFG;
|
44 |
|
| 53 |
|
45 |
require_once("{$CFG->libdir}/gradelib.php");
|
| 54 |
require_once("{$CFG->libdir}/gradelib.php");
|
46 |
require_once("{$CFG->dirroot}/completion/criteria/completion_criteria_self.php");
|
| Línea 85... |
Línea 77... |
| 85 |
|
77 |
|
| 86 |
// Default columns are course, user, method. Sorted by each.
|
78 |
// Default columns are course, user, method. Sorted by each.
|
| 87 |
$courseoneurl = course_get_url($courseone);
|
79 |
$courseoneurl = course_get_url($courseone);
|
| Línea 88... |
Línea 80... |
| 88 |
$coursetwourl = course_get_url($coursetwo);
|
80 |
$coursetwourl = course_get_url($coursetwo);
|
| 89 |
|
81 |
|
| Línea 90... |
Línea 82... |
| 90 |
$useroneurl = core_user::get_profile_url($userone);
|
82 |
$useroneurl = user::get_profile_url($userone);
|
| 91 |
$usertwourl = core_user::get_profile_url($usertwo);
|
83 |
$usertwourl = user::get_profile_url($usertwo);
|
| 92 |
|
84 |
|
| 93 |
$this->assertEquals([
|
85 |
$this->assertEquals([
|
| Línea 139... |
Línea 131... |
| 139 |
|
131 |
|
| 140 |
// Update final grade for the user.
|
132 |
// Update final grade for the user.
|
| 141 |
$courseitem = grade_item::fetch_course_item($course->id);
|
133 |
$courseitem = grade_item::fetch_course_item($course->id);
|
| Línea -... |
Línea 134... |
| - |
|
134 |
$courseitem->update_final_grade($user1->id, 42.5);
|
| - |
|
135 |
|
| - |
|
136 |
// Add some cohort data.
|
| - |
|
137 |
$cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
|
| 142 |
$courseitem->update_final_grade($user1->id, 42.5);
|
138 |
cohort_add_member($cohort->id, $user1->id);
|
| 143 |
|
139 |
|
| 144 |
// Set some last access value for the user in the course.
|
140 |
// Set some last access value for the user in the course.
|
| Línea 145... |
Línea 141... |
| 145 |
$DB->insert_record('user_lastaccess',
|
141 |
$DB->insert_record('user_lastaccess',
|
| Línea 169... |
Línea 165... |
| 169 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:shortname']);
|
165 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:shortname']);
|
| 170 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:description']);
|
166 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:description']);
|
| Línea 171... |
Línea 167... |
| 171 |
|
167 |
|
| 172 |
$generator->create_column(['reportid' => $report->get('id'),
|
168 |
$generator->create_column(['reportid' => $report->get('id'),
|
| - |
|
169 |
'uniqueidentifier' => 'group:name']);
|
| 173 |
'uniqueidentifier' => 'group:name']);
|
170 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);
|
| 174 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'completion:criteria']);
|
171 |
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'completion:criteria']);
|
| 175 |
$generator->create_column(['reportid' => $report->get('id'),
|
172 |
$generator->create_column(['reportid' => $report->get('id'),
|
| 176 |
'uniqueidentifier' => 'completion:completed']);
|
173 |
'uniqueidentifier' => 'completion:completed']);
|
| 177 |
$generator->create_column(['reportid' => $report->get('id'),
|
174 |
$generator->create_column(['reportid' => $report->get('id'),
|
| Línea 191... |
Línea 188... |
| 191 |
$generator->create_column(['reportid' => $report->get('id'),
|
188 |
$generator->create_column(['reportid' => $report->get('id'),
|
| 192 |
'uniqueidentifier' => 'completion:daysuntilcompletion']);
|
189 |
'uniqueidentifier' => 'completion:daysuntilcompletion']);
|
| 193 |
$generator->create_column(['reportid' => $report->get('id'),
|
190 |
$generator->create_column(['reportid' => $report->get('id'),
|
| 194 |
'uniqueidentifier' => 'completion:grade']);
|
191 |
'uniqueidentifier' => 'completion:grade']);
|
| Línea 195... |
Línea -... |
| 195 |
|
- |
|
| 196 |
// Add filter to the report.
|
- |
|
| 197 |
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:plugin']);
|
- |
|
| 198 |
|
- |
|
| 199 |
$content = $this->get_custom_report_content($report->get('id'));
|
- |
|
| 200 |
|
192 |
|
| - |
|
193 |
// It should get 3 records (manual enrolment, self and guest).
|
| 201 |
// It should get 3 records (manual enrolment, self and guest).
|
194 |
$content = $this->get_custom_report_content($report->get('id'));
|
| Línea 202... |
Línea 195... |
| 202 |
$this->assertCount(3, $content);
|
195 |
$this->assertCount(3, $content);
|
| - |
|
196 |
|
| 203 |
|
197 |
// Filter by Manual enrolment method.
|
| 204 |
// Filter by Manual enrolment method.
|
198 |
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:plugin']);
|
| 205 |
$content = $this->get_custom_report_content($report->get('id'), 30, [
|
199 |
$content = $this->get_custom_report_content($report->get('id'), 30, [
|
| 206 |
'enrol:plugin_operator' => select::EQUAL_TO,
|
200 |
'enrol:plugin_operator' => select::EQUAL_TO,
|
| Línea 221... |
Línea 215... |
| 221 |
'', // Enrolment end date.
|
215 |
'', // Enrolment end date.
|
| 222 |
'Student', // Role name.
|
216 |
'Student', // Role name.
|
| 223 |
'student', // Role shortname.
|
217 |
'student', // Role shortname.
|
| 224 |
'Students generally have fewer privileges within a course.', // Role description.
|
218 |
'Students generally have fewer privileges within a course.', // Role description.
|
| 225 |
$group->name, // Group name.
|
219 |
$group->name, // Group name.
|
| - |
|
220 |
$cohort->name, // Cohort name.
|
| 226 |
"All criteria below are required<ul>\n<li>Self completion: Self completion</li>\n</ul>", // Completion criteria.
|
221 |
"All criteria below are required<ul>\n<li>Self completion: Self completion</li>\n</ul>", // Completion criteria.
|
| 227 |
'Yes', // Course completed.
|
222 |
'Yes', // Course completed.
|
| 228 |
userdate($timelastaccess), // Time last access.
|
223 |
userdate($timelastaccess), // Time last access.
|
| 229 |
'100.0%', // Progress percentage.
|
224 |
'100.0%', // Progress percentage.
|
| 230 |
userdate($timestart), // Time enrolled.
|
225 |
userdate($timestart), // Time enrolled.
|
| 231 |
'', // Time started.
|
226 |
'', // Time started.
|
| 232 |
userdate($timecompleted), // Time completed.
|
227 |
userdate($timecompleted), // Time completed.
|
| 233 |
'', // Reagreggate.
|
228 |
'', // Reagreggate.
|
| 234 |
2, // Days taking course.
|
229 |
'2 days', // Days taking course.
|
| 235 |
2, // Days until completion.
|
230 |
'2 days', // Days until completion.
|
| 236 |
'42.50', // Grade.
|
231 |
'42.50', // Grade.
|
| 237 |
], array_values($content[0]));
|
232 |
], array_values($content[0]));
|
| 238 |
}
|
233 |
}
|
| Línea 304... |
Línea 299... |
| 304 |
'aggregation' => 'avg',
|
299 |
'aggregation' => 'avg',
|
| 305 |
]);
|
300 |
]);
|
| Línea 306... |
Línea 301... |
| 306 |
|
301 |
|
| 307 |
$content = $this->get_custom_report_content($report->get('id'));
|
302 |
$content = $this->get_custom_report_content($report->get('id'));
|
| 308 |
$this->assertEquals([
|
303 |
$this->assertEquals([
|
| 309 |
[$courseone->fullname, '2.5'],
|
304 |
[$courseone->fullname, '2 days 12 hours'],
|
| 310 |
[$coursetwo->fullname, ''],
|
305 |
[$coursetwo->fullname, ''],
|
| 311 |
], array_map('array_values', $content));
|
306 |
], array_map('array_values', $content));
|
| Línea 312... |
Línea 307... |
| 312 |
}
|
307 |
}
|
| 313 |
|
308 |
|
| 314 |
/**
|
309 |
/**
|
| 315 |
* Data provider for {@see test_datasource_filters}
|
310 |
* Data provider for {@see test_datasource_filters}
|
| 316 |
*
|
311 |
*
|
| 317 |
* @return array
|
312 |
* @return array
|
| 318 |
*/
|
313 |
*/
|
| Línea 319... |
Línea 314... |
| 319 |
public function datasource_filters_provider(): array {
|
314 |
public static function datasource_filters_provider(): array {
|
| 320 |
global $DB;
|
315 |
global $DB;
|
| 321 |
|
316 |
|
| Línea 404... |
Línea 399... |
| 404 |
'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'editingteacher']),
|
399 |
'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'editingteacher']),
|
| 405 |
],
|
400 |
],
|
| 406 |
['Luna'],
|
401 |
['Luna'],
|
| 407 |
],
|
402 |
],
|
| 408 |
[
|
403 |
[
|
| - |
|
404 |
'group:name',
|
| - |
|
405 |
[
|
| - |
|
406 |
'group:name_operator' => text::IS_EQUAL_TO,
|
| - |
|
407 |
'group:name_value' => 'My group',
|
| - |
|
408 |
],
|
| - |
|
409 |
['Lionel'],
|
| - |
|
410 |
],
|
| - |
|
411 |
[
|
| - |
|
412 |
'cohort:name',
|
| - |
|
413 |
[
|
| - |
|
414 |
'cohort:name_operator' => text::IS_EQUAL_TO,
|
| - |
|
415 |
'cohort:name_value' => 'My cohort',
|
| - |
|
416 |
],
|
| - |
|
417 |
['Kira'],
|
| - |
|
418 |
],
|
| - |
|
419 |
[
|
| 409 |
'completion:completed',
|
420 |
'completion:completed',
|
| 410 |
[
|
421 |
[
|
| 411 |
'completion:completed_operator' => boolean_select::CHECKED,
|
422 |
'completion:completed_operator' => boolean_select::CHECKED,
|
| 412 |
],
|
423 |
],
|
| 413 |
['Lionel'],
|
424 |
['Lionel'],
|
| Línea 479... |
Línea 490... |
| 479 |
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student',
|
490 |
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student',
|
| 480 |
'manual', $timestart, $timeend, ENROL_USER_ACTIVE);
|
491 |
'manual', $timestart, $timeend, ENROL_USER_ACTIVE);
|
| 481 |
$this->getDataGenerator()->enrol_user($user3->id, $course->id, 'editingteacher',
|
492 |
$this->getDataGenerator()->enrol_user($user3->id, $course->id, 'editingteacher',
|
| 482 |
'manual', time(), time(), ENROL_USER_SUSPENDED);
|
493 |
'manual', time(), time(), ENROL_USER_SUSPENDED);
|
| Línea -... |
Línea 494... |
| - |
|
494 |
|
| - |
|
495 |
// Add user1 to a group.
|
| - |
|
496 |
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id, 'name' => 'My group']);
|
| - |
|
497 |
$this->getDataGenerator()->create_group_member(['groupid' => $group->id, 'userid' => $user1->id]);
|
| - |
|
498 |
|
| - |
|
499 |
// Add some cohort data.
|
| - |
|
500 |
$cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
|
| - |
|
501 |
cohort_add_member($cohort->id, $user2->id);
|
| 483 |
|
502 |
|
| 484 |
// Mark course as completed for the user.
|
503 |
// Mark course as completed for the user.
|
| 485 |
$ccompletion = new completion_completion(array('course' => $course->id, 'userid' => $user1->id));
|
504 |
$ccompletion = new completion_completion(array('course' => $course->id, 'userid' => $user1->id));
|
| 486 |
$ccompletion->mark_enrolled($timestart);
|
505 |
$ccompletion->mark_enrolled($timestart);
|
| 487 |
$ccompletion->mark_inprogress($timestart);
|
506 |
$ccompletion->mark_inprogress($timestart);
|