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
declare(strict_types=1);
18
 
19
namespace core_course\reportbuilder\datasource;
20
 
21
use completion_completion;
22
use completion_criteria_self;
23
use core_reportbuilder_generator;
1441 ariadna 24
use core_reportbuilder\local\filters\{boolean_select, date, duration, select, text};
25
use core_reportbuilder\tests\core_reportbuilder_testcase;
26
use core\user;
1 efrain 27
use grade_item;
28
 
29
/**
30
 * Course participants datasource tests
31
 *
32
 * @package     core_course
33
 * @covers      \core_course\reportbuilder\datasource\participants
34
 * @copyright   2022 David Matamoros <davidmc@moodle.com>
35
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
1441 ariadna 37
final class participants_test extends core_reportbuilder_testcase {
1 efrain 38
 
39
    /**
40
     * Load required test libraries
41
     */
42
    public static function setUpBeforeClass(): void {
43
        global $CFG;
44
 
45
        require_once("{$CFG->libdir}/gradelib.php");
46
        require_once("{$CFG->dirroot}/completion/criteria/completion_criteria_self.php");
1441 ariadna 47
        parent::setUpBeforeClass();
1 efrain 48
    }
49
 
50
    /**
51
     * Test default datasource
52
     */
53
    public function test_datasource_default(): void {
54
        global $DB;
55
 
56
        $this->resetAfterTest();
57
 
58
        // Course one, two manually enrolled users.
59
        $courseone = $this->getDataGenerator()->create_course(['fullname' => 'Zebras']);
60
        $userone = $this->getDataGenerator()->create_and_enrol($courseone, 'student', ['firstname' => 'Zoe']);
61
        $usertwo = $this->getDataGenerator()->create_and_enrol($courseone, 'student', ['firstname' => 'Amy']);
62
 
63
        // Course two, two self enrolled users (one inactive).
64
        $coursetwo = $this->getDataGenerator()->create_course(['fullname' => 'Aardvarks']);
65
 
66
        $enrol = $DB->get_record('enrol', ['courseid' => $coursetwo->id, 'enrol' => 'self']);
67
        enrol_get_plugin($enrol->enrol)->update_status($enrol, ENROL_INSTANCE_ENABLED);
68
 
69
        $this->getDataGenerator()->enrol_user($userone->id, $coursetwo->id, null, 'self');
70
        $this->getDataGenerator()->enrol_user($usertwo->id, $coursetwo->id, null, 'self', 0, 0, ENROL_USER_SUSPENDED);
71
 
72
        /** @var core_reportbuilder_generator $generator */
73
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
74
        $report = $generator->create_report(['name' => 'Participants', 'source' => participants::class, 'default' => 1]);
75
 
76
        $content = $this->get_custom_report_content($report->get('id'));
77
 
78
        // Default columns are course, user, method. Sorted by each.
79
        $courseoneurl = course_get_url($courseone);
80
        $coursetwourl = course_get_url($coursetwo);
81
 
1441 ariadna 82
        $useroneurl = user::get_profile_url($userone);
83
        $usertwourl = user::get_profile_url($usertwo);
1 efrain 84
 
85
        $this->assertEquals([
86
            ["<a href=\"{$coursetwourl}\">{$coursetwo->fullname}</a>",
87
                "<a href=\"{$useroneurl}\">" . fullname($userone) . "</a>", 'Self enrolment (Student)'],
88
            ["<a href=\"{$courseoneurl}\">{$courseone->fullname}</a>",
89
                "<a href=\"{$usertwourl}\">" . fullname($usertwo) . "</a>", 'Manual enrolments'],
90
            ["<a href=\"{$courseoneurl}\">{$courseone->fullname}</a>",
91
                "<a href=\"{$useroneurl}\">" . fullname($userone) . "</a>", 'Manual enrolments'],
92
        ], array_map('array_values', $content));
93
    }
94
 
95
    /**
96
     * Test datasource columns that aren't added by default
97
     */
98
    public function test_datasource_non_default_columns(): void {
99
        global $DB;
100
        $this->resetAfterTest();
101
 
102
        $timestart = time() - DAYSECS;
103
        $timeend = $timestart + 3 * DAYSECS;
104
        $timecompleted = $timestart + 2 * DAYSECS;
105
        $timelastaccess = time() + 4 * DAYSECS;
106
 
107
        $category = $this->getDataGenerator()->create_category(['name' => 'Music']);
108
        $course = $this->getDataGenerator()->create_course([
109
            'category' => $category->id,
110
            'fullname' => 'All about Lionel at the work place',
111
            'enablecompletion' => true,
112
            'startdate' => $timestart,
113
            'enddate' => $timeend,
114
        ]);
115
 
116
        $user1 = self::getDataGenerator()->create_user();
117
        $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student',
118
            'manual', $timestart, $timeend, ENROL_USER_ACTIVE);
119
 
120
        // Add them to a group.
121
        $group = self::getDataGenerator()->create_group(['courseid' => $course->id]);
122
        self::getDataGenerator()->create_group_member(['groupid' => $group->id, 'userid' => $user1->id]);
123
 
124
        // Create self completion, mark as complete for the user.
125
        $criteriaconfig = (object) ['id' => $course->id, 'criteria_self' => true];
126
        (new completion_criteria_self())->update_config($criteriaconfig);
127
 
128
        $ccompletion = new completion_completion(['course' => $course->id, 'userid' => $user1->id]);
129
        $ccompletion->mark_enrolled($timestart);
130
        $ccompletion->mark_complete($timecompleted);
131
 
132
        // Update final grade for the user.
133
        $courseitem = grade_item::fetch_course_item($course->id);
134
        $courseitem->update_final_grade($user1->id, 42.5);
135
 
1441 ariadna 136
        // Add some cohort data.
137
        $cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
138
        cohort_add_member($cohort->id, $user1->id);
139
 
1 efrain 140
        // Set some last access value for the user in the course.
141
        $DB->insert_record('user_lastaccess',
142
            ['userid' => $user1->id, 'courseid' => $course->id, 'timeaccess' => $timelastaccess]);
143
 
144
        /** @var core_reportbuilder_generator $generator */
145
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
146
        $report = $generator->create_report(['name' => 'Participants', 'source' => participants::class, 'default' => false]);
147
 
148
        $generator->create_column(['reportid' => $report->get('id'),
149
            'uniqueidentifier' => 'course:fullname']);
150
        $generator->create_column(['reportid' => $report->get('id'),
151
            'uniqueidentifier' => 'course_category:name']);
152
        $generator->create_column(['reportid' => $report->get('id'),
153
            'uniqueidentifier' => 'user:fullname']);
154
 
155
        // Enrol entity (report ordering by enrolment name).
156
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:name', 'sortenabled' => 1]);
157
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:plugin']);
158
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:enabled']);
159
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:period']);
160
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:startdate']);
161
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:enddate']);
162
 
163
        // Role entity.
164
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:name']);
165
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:shortname']);
166
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'role:description']);
167
 
168
        $generator->create_column(['reportid' => $report->get('id'),
169
            'uniqueidentifier' => 'group:name']);
1441 ariadna 170
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);
1 efrain 171
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'completion:criteria']);
172
        $generator->create_column(['reportid' => $report->get('id'),
173
            'uniqueidentifier' => 'completion:completed']);
174
        $generator->create_column(['reportid' => $report->get('id'),
175
            'uniqueidentifier' => 'access:timeaccess']);
176
        $generator->create_column(['reportid' => $report->get('id'),
177
            'uniqueidentifier' => 'completion:progresspercent']);
178
        $generator->create_column(['reportid' => $report->get('id'),
179
            'uniqueidentifier' => 'completion:timeenrolled']);
180
        $generator->create_column(['reportid' => $report->get('id'),
181
            'uniqueidentifier' => 'completion:timestarted']);
182
        $generator->create_column(['reportid' => $report->get('id'),
183
            'uniqueidentifier' => 'completion:timecompleted']);
184
        $generator->create_column(['reportid' => $report->get('id'),
185
            'uniqueidentifier' => 'completion:reaggregate']);
186
        $generator->create_column(['reportid' => $report->get('id'),
187
            'uniqueidentifier' => 'completion:dayscourse']);
188
        $generator->create_column(['reportid' => $report->get('id'),
189
            'uniqueidentifier' => 'completion:daysuntilcompletion']);
190
        $generator->create_column(['reportid' => $report->get('id'),
191
            'uniqueidentifier' => 'completion:grade']);
192
 
1441 ariadna 193
        // It should get 3 records (manual enrolment, self and guest).
1 efrain 194
        $content = $this->get_custom_report_content($report->get('id'));
195
        $this->assertCount(3, $content);
196
 
197
        // Filter by Manual enrolment method.
1441 ariadna 198
        $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:plugin']);
1 efrain 199
        $content = $this->get_custom_report_content($report->get('id'), 30, [
200
            'enrol:plugin_operator' => select::EQUAL_TO,
201
            'enrol:plugin_value' => 'manual',
202
        ]);
203
 
204
        $this->assertCount(1, $content);
205
 
206
        $this->assertEquals([
207
            'All about Lionel at the work place', // Course name.
208
            'Music', // Course category name.
209
            fullname($user1), // User fullname.
210
            'Manual enrolments', // Enrolment method.
211
            'Manual enrolments', // Enrolment plugin.
212
            'Yes', // Enrolment enabled.
213
            '', // Enrolment period.
214
            '', // Enrolment start date.
215
            '', // Enrolment end date.
216
            'Student', // Role name.
217
            'student', // Role shortname.
218
            'Students generally have fewer privileges within a course.', // Role description.
219
            $group->name, // Group name.
1441 ariadna 220
            $cohort->name, // Cohort name.
1 efrain 221
            "All criteria below are required<ul>\n<li>Self completion: Self completion</li>\n</ul>", // Completion criteria.
222
            'Yes', // Course completed.
223
            userdate($timelastaccess), // Time last access.
224
            '100.0%', // Progress percentage.
225
            userdate($timestart), // Time enrolled.
226
            '', // Time started.
227
            userdate($timecompleted), // Time completed.
228
            '', // Reagreggate.
1441 ariadna 229
            '2 days', // Days taking course.
230
            '2 days', // Days until completion.
1 efrain 231
            '42.50', // Grade.
232
        ], array_values($content[0]));
233
    }
234
 
11 efrain 235
 
1 efrain 236
    /**
11 efrain 237
     * Test creating participants report, with aggregated last access date (minimum and maximum)
238
     */
239
    public function test_course_last_access_aggregation(): void {
240
        $this->resetAfterTest();
241
 
242
        $course = $this->getDataGenerator()->create_course();
243
 
244
        $userone = $this->getDataGenerator()->create_and_enrol($course);
245
        $useronelastaccess = $this->getDataGenerator()->create_user_course_lastaccess($userone, $course, 1622502000);
246
 
247
        $usertwo = $this->getDataGenerator()->create_and_enrol($course);
248
        $usertwolastaccess = $this->getDataGenerator()->create_user_course_lastaccess($usertwo, $course, 1622847600);
249
 
250
        /** @var core_reportbuilder_generator $generator */
251
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
252
 
253
        $report = $generator->create_report(['name' => 'Participants', 'source' => participants::class, 'default' => 0]);
254
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:fullname']);
255
        $column = $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'access:timeaccess']);
256
 
257
        // Course aggregated with "Minimum" last access.
258
        $column->set('aggregation', 'min')->update();
259
        $content = $this->get_custom_report_content($report->get('id'));
260
        $this->assertEquals([
261
            [$course->fullname, userdate($useronelastaccess->timeaccess)],
262
        ], array_map('array_values', $content));
263
 
264
        // Course aggregated with "Maximum" last access.
265
        $column->set('aggregation', 'max')->update();
266
        $content = $this->get_custom_report_content($report->get('id'));
267
        $this->assertEquals([
268
            [$course->fullname, userdate($usertwolastaccess->timeaccess)],
269
        ], array_map('array_values', $content));
270
    }
271
 
272
    /**
273
     * Test creating participants report, with aggregated days taking course column
274
     */
275
    public function test_completion_days_taking_course_aggregation(): void {
276
        $this->resetAfterTest();
277
 
278
        $courseone = $this->getDataGenerator()->create_course(['fullname' => 'Course 1', 'startdate' => 1622502000]);
279
        $coursetwo = $this->getDataGenerator()->create_course(['fullname' => 'Course 2']);
280
 
281
        // User one completed the course in two days.
282
        $userone = $this->getDataGenerator()->create_and_enrol($courseone);
283
        $completion = new completion_completion(['course' => $courseone->id, 'userid' => $userone->id]);
284
        $completion->mark_complete(1622502000 + (2 * DAYSECS));
285
 
286
        // User two completed the course in three days (lazy bum).
287
        $usertwo = $this->getDataGenerator()->create_and_enrol($courseone);
288
        $completion = new completion_completion(['course' => $courseone->id, 'userid' => $usertwo->id]);
289
        $completion->mark_complete(1622502000 + (3 * DAYSECS));
290
 
291
        /** @var core_reportbuilder_generator $generator */
292
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
293
 
294
        $report = $generator->create_report(['name' => 'Participants', 'source' => participants::class, 'default' => 0]);
295
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:fullname', 'sortenabled' => 1]);
296
        $generator->create_column([
297
            'reportid' => $report->get('id'),
298
            'uniqueidentifier' => 'completion:dayscourse',
299
            'aggregation' => 'avg',
300
        ]);
301
 
302
        $content = $this->get_custom_report_content($report->get('id'));
303
        $this->assertEquals([
1441 ariadna 304
            [$courseone->fullname, '2 days 12 hours'],
11 efrain 305
            [$coursetwo->fullname, ''],
306
        ], array_map('array_values', $content));
307
    }
308
 
309
    /**
1 efrain 310
     * Data provider for {@see test_datasource_filters}
311
     *
312
     * @return array
313
     */
1441 ariadna 314
    public static function datasource_filters_provider(): array {
1 efrain 315
        global $DB;
316
 
317
        return [
318
            [
319
                'enrolment:status',
320
                [
321
                    'enrolment:status_operator' => select::EQUAL_TO,
322
                    'enrolment:status_value' => 1,
323
                ],
324
                ['Luna'],
325
            ],
326
            [
327
                'enrolment:timecreated',
328
                [
329
                    'enrolment:timecreated_operator' => date::DATE_CURRENT,
330
                    'enrolment:timecreated_unit' => date::DATE_UNIT_DAY,
331
                ],
332
                ['Kira'],
333
            ],
334
            [
335
                'enrolment:timestarted',
336
                [
337
                    'enrolment:timestarted_operator' => date::DATE_CURRENT,
338
                    'enrolment:timecreated_unit' => date::DATE_UNIT_DAY,
339
                ],
340
                ['Luna'],
341
            ],
342
            [
343
                'enrolment:timeended',
344
                [
345
                    'enrolment:timeended_operator' => date::DATE_CURRENT,
346
                    'enrolment:timeended_unit' => date::DATE_UNIT_DAY,
347
                ],
348
                ['Luna'],
349
            ],
350
            [
351
                'enrol:enabled',
352
                [
353
                    'completion:enabled_operator' => boolean_select::CHECKED,
354
                ],
355
                ['Lionel', 'Kira', 'Luna'],
356
            ],
357
            [
358
                'enrol:period',
359
                [
360
                    'enrol:period_operator' => duration::DURATION_MAXIMUM,
361
                    'enrol:period_unit' => MINSECS,
362
                    'enrol:period_value' => 2,
363
                ],
364
                ['Lionel', 'Kira', 'Luna'],
365
            ],
366
            [
367
                'enrol:startdate',
368
                [
369
                    'enrol:startdate_operator' => date::DATE_EMPTY,
370
                ],
371
                ['Lionel', 'Kira', 'Luna'],
372
            ],
373
            [
374
                'enrol:enddate',
375
                [
376
                    'enrol:enddate_operator' => date::DATE_EMPTY,
377
                ],
378
                ['Lionel', 'Kira', 'Luna'],
379
            ],
380
            [
381
                'enrol:customname',
382
                [
383
                    'enrol:customname_operator' => text::IS_EMPTY,
384
                ],
385
                ['Luna', 'Kira', 'Lionel'],
386
            ],
387
            [
388
                'enrol:customname',
389
                [
390
                    'enrol:customname_operator' => text::IS_EQUAL_TO,
391
                    'enrol:customname_value' => 'All night long'
392
                ],
393
                [],
394
            ],
395
            [
396
                'role:name',
397
                [
398
                    'role:name_operator' => select::EQUAL_TO,
399
                    'role:name_value' => $DB->get_field('role', 'id', ['shortname' => 'editingteacher']),
400
                ],
401
                ['Luna'],
402
            ],
403
            [
1441 ariadna 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
            [
1 efrain 420
                'completion:completed',
421
                [
422
                    'completion:completed_operator' => boolean_select::CHECKED,
423
                ],
424
                ['Lionel'],
425
            ],
426
            [
427
                'completion:timecompleted',
428
                [
429
                    'completion:timecompleted_operator' => date::DATE_NOT_EMPTY,
430
                ],
431
                ['Lionel'],
432
            ],
433
            [
434
                'completion:timeenrolled',
435
                [
436
                    'completion:timeenrolled_operator' => date::DATE_NOT_EMPTY,
437
                ],
438
                ['Lionel'],
439
            ],
440
            [
441
                'completion:timestarted',
442
                [
443
                    'completion:timestarted_operator' => date::DATE_NOT_EMPTY,
444
                ],
445
                ['Lionel'],
446
            ],
447
            [
448
                'completion:reaggregate',
449
                [
450
                    'completion:reaggregate_operator' => date::DATE_NOT_EMPTY,
451
                ],
452
                ['Lionel'],
453
            ],
454
        ];
455
    }
456
 
457
    /**
458
     * Test getting filter SQL
459
     *
460
     * @param string $filter
461
     * @param array $filtervalues
462
     * @param string[] $expected
463
     *
464
     * @dataProvider datasource_filters_provider
465
     */
466
    public function test_datasource_filters(string $filter, array $filtervalues, array $expected): void {
467
        global $DB;
468
        $this->resetAfterTest();
469
 
470
        $timestart = time() - DAYSECS;
471
        $timeend = $timestart + 3 * DAYSECS;
472
        $timecompleted = $timestart + 2 * DAYSECS;
473
        $timelastaccess = time() + 4 * DAYSECS;
474
 
475
        $category = $this->getDataGenerator()->create_category(['name' => 'Music']);
476
        $course = $this->getDataGenerator()->create_course([
477
            'category' => $category->id,
478
            'fullname' => 'All about Lionel at the work place',
479
            'enablecompletion' => true,
480
            'startdate' => $timestart,
481
            'enddate' => $timeend,
482
        ]);
483
 
484
        $user1 = self::getDataGenerator()->create_user(['firstname' => 'Lionel']);
485
        $user2 = self::getDataGenerator()->create_user(['firstname' => 'Kira']);
486
        $user3 = self::getDataGenerator()->create_user(['firstname' => 'Luna']);
487
 
488
        $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student',
489
            'manual', $timestart - 8 * DAYSECS, $timeend, ENROL_USER_ACTIVE);
490
        $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student',
491
            'manual', $timestart, $timeend, ENROL_USER_ACTIVE);
492
        $this->getDataGenerator()->enrol_user($user3->id, $course->id, 'editingteacher',
493
            'manual', time(), time(), ENROL_USER_SUSPENDED);
494
 
1441 ariadna 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);
502
 
1 efrain 503
        // Mark course as completed for the user.
504
        $ccompletion = new completion_completion(array('course' => $course->id, 'userid' => $user1->id));
505
        $ccompletion->mark_enrolled($timestart);
506
        $ccompletion->mark_inprogress($timestart);
507
        $ccompletion->mark_complete($timecompleted);
508
 
509
        // Set some last access value for the user in the course.
510
        $DB->insert_record('user_lastaccess',
511
            ['userid' => $user1->id, 'courseid' => $course->id, 'timeaccess' => $timelastaccess]);
512
 
513
        /** @var core_reportbuilder_generator $generator */
514
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
515
        $report = $generator->create_report(['name' => 'Participants', 'source' => participants::class, 'default' => false]);
516
 
517
        // Add user firstname column to the report.
518
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname']);
519
 
520
        $DB->set_field('user_enrolments', 'timecreated', 0, ['userid' => $user1->id]);
521
        $DB->set_field('user_enrolments', 'timecreated', 0, ['userid' => $user3->id]);
522
 
523
        // Add filters to the report.
524
        $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'enrol:plugin']);
525
        $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => $filter]);
526
 
527
        // Apply filters.
528
        $filtermanual = ['enrol:plugin_operator' => select::EQUAL_TO, 'enrol:plugin_value' => 'manual'];
529
        $content = $this->get_custom_report_content($report->get('id'), 30, $filtermanual + $filtervalues);
530
 
531
        $this->assertEqualsCanonicalizing($expected, array_column($content, 'c0_firstname'));
532
    }
533
 
534
    /**
535
     * Stress test datasource
536
     *
537
     * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php
538
     */
539
    public function test_stress_datasource(): void {
540
        if (!PHPUNIT_LONGTEST) {
541
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
542
        }
543
 
544
        $this->resetAfterTest();
545
 
546
        $course = $this->getDataGenerator()->create_course();
547
        $this->getDataGenerator()->create_and_enrol($course);
548
 
549
        $this->datasource_stress_test_columns(participants::class);
550
        $this->datasource_stress_test_columns_aggregation(participants::class);
551
        $this->datasource_stress_test_conditions(participants::class, 'course:idnumber');
552
    }
553
}