Proyectos de Subversion Moodle

Rev

| 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_user\reportbuilder\datasource;
20
 
21
use core_reportbuilder_testcase;
22
use core_reportbuilder_generator;
23
use core_reportbuilder\local\filters\boolean_select;
24
use core_reportbuilder\local\filters\date;
25
use core_reportbuilder\local\filters\select;
26
use core_reportbuilder\local\filters\tags;
27
use core_reportbuilder\local\filters\text;
28
use core_reportbuilder\local\filters\user as user_filter;
29
 
30
defined('MOODLE_INTERNAL') || die();
31
 
32
global $CFG;
33
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
34
 
35
/**
36
 * Unit tests for users datasource
37
 *
38
 * @package     core_user
39
 * @covers      \core_user\reportbuilder\datasource\users
40
 * @copyright   2022 Paul Holden <paulh@moodle.com>
41
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class users_test extends core_reportbuilder_testcase {
44
 
45
    /**
46
     * Test default datasource
47
     */
48
    public function test_datasource_default(): void {
49
        $this->resetAfterTest();
50
 
51
        $user2 = $this->getDataGenerator()->create_user(['firstname' => 'Charles']);
52
        $user3 = $this->getDataGenerator()->create_user(['firstname' => 'Brian']);
53
 
54
        /** @var core_reportbuilder_generator $generator */
55
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
56
        $report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 1]);
57
 
58
        $content = $this->get_custom_report_content($report->get('id'));
59
        $this->assertCount(3, $content);
60
 
61
        // Default columns are fullname, username, email. Results are sorted by the fullname.
62
        [$adminrow, $userrow1, $userrow2] = array_map('array_values', $content);
63
 
64
        $this->assertEquals(['Admin User', 'admin', 'admin@example.com'], $adminrow);
65
        $this->assertEquals([fullname($user3), $user3->username, $user3->email], $userrow1);
66
        $this->assertEquals([fullname($user2), $user2->username, $user2->email], $userrow2);
67
    }
68
 
69
    /**
70
     * Test datasource columns that aren't added by default
71
     */
72
    public function test_datasource_non_default_columns(): void {
73
        $this->resetAfterTest();
74
 
75
        $user = $this->getDataGenerator()->create_user([
76
            'firstname' => 'Zoe',
77
            'idnumber' => 'U0001',
78
            'city' => 'London',
79
            'country' => 'GB',
80
            'theme' => 'boost',
81
            'interests' => ['Horses'],
82
        ]);
83
 
84
        $cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
85
        cohort_add_member($cohort->id, $user->id);
86
 
87
        /** @var core_reportbuilder_generator $generator */
88
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
89
        $report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
90
 
91
        // User.
92
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullnamewithlink',
93
            'sortenabled' => 1]);
94
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullnamewithpicture']);
95
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullnamewithpicturelink']);
96
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:picture']);
97
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname']);
98
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname']);
99
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:city']);
100
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:country']);
101
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:description']);
102
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstnamephonetic']);
103
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastnamephonetic']);
104
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:middlename']);
105
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:alternatename']);
106
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:idnumber']);
107
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:institution']);
108
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:department']);
109
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:phone1']);
110
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:phone2']);
111
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:address']);
112
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastaccess']);
113
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended']);
114
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:confirmed']);
115
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:auth']);
116
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:moodlenetprofile']);
117
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timecreated']);
118
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timemodified']);
119
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastip']);
120
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:theme']);
121
 
122
        // Tags.
123
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:name']);
124
 
125
        // Cohort.
126
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);
127
 
128
        $content = $this->get_custom_report_content($report->get('id'));
129
        $this->assertCount(2, $content);
130
 
131
        // Admin row.
132
        [
133
            $fullnamewithlink,
134
            $fullnamewithpicture,
135
            $fullnamewithpicturelink,
136
            $picture,
137
            $lastname,
138
            $firstname,
139
        ] = array_values($content[0]);
140
 
141
        $this->assertStringContainsString('Admin User', $fullnamewithlink);
142
        $this->assertStringContainsString('Admin User', $fullnamewithpicture);
143
        $this->assertStringContainsString('Admin User', $fullnamewithpicturelink);
144
        $this->assertNotEmpty($picture);
145
        $this->assertEquals('Admin', $lastname);
146
        $this->assertEquals('User', $firstname);
147
 
148
        // User row.
149
        [
150
            $fullnamewithlink,
151
            $fullnamewithpicture,
152
            $fullnamewithpicturelink,
153
            $picture,
154
            $firstname,
155
            $lastname,
156
            $city,
157
            $country,
158
            $description,
159
            $firstnamephonetic,
160
            $lastnamephonetic,
161
            $middlename,
162
            $alternatename,
163
            $idnumber,
164
            $institution,
165
            $department,
166
            $phone1,
167
            $phone2,
168
            $address,
169
            $lastaccess,
170
            $suspended,
171
            $confirmed,
172
            $auth,
173
            $moodlenetprofile,
174
            $timecreated,
175
            $timemodified,
176
            $lastip,
177
            $theme,
178
            $tag,
179
            $cohortname,
180
        ] = array_values($content[1]);
181
 
182
        $this->assertStringContainsString(fullname($user), $fullnamewithlink);
183
        $this->assertStringContainsString(fullname($user), $fullnamewithpicture);
184
        $this->assertStringContainsString(fullname($user), $fullnamewithpicturelink);
185
        $this->assertNotEmpty($picture);
186
        $this->assertEquals($user->firstname, $firstname);
187
        $this->assertEquals($user->lastname, $lastname);
188
        $this->assertEquals($user->city, $city);
189
        $this->assertEquals('United Kingdom', $country);
190
        $this->assertEquals($user->description, $description);
191
        $this->assertEquals($user->firstnamephonetic, $firstnamephonetic);
192
        $this->assertEquals($user->lastnamephonetic, $lastnamephonetic);
193
        $this->assertEquals($user->middlename, $middlename);
194
        $this->assertEquals($user->alternatename, $alternatename);
195
        $this->assertEquals($user->idnumber, $idnumber);
196
        $this->assertEquals($user->institution, $institution);
197
        $this->assertEquals($user->department, $department);
198
        $this->assertEquals($user->phone1, $phone1);
199
        $this->assertEquals($user->phone2, $phone2);
200
        $this->assertEquals($user->address, $address);
201
        $this->assertEmpty($lastaccess);
202
        $this->assertEquals('No', $suspended);
203
        $this->assertEquals('Yes', $confirmed);
204
        $this->assertEquals('Manual accounts', $auth);
205
        $this->assertEquals($user->moodlenetprofile, $moodlenetprofile);
206
        $this->assertNotEmpty($timecreated);
207
        $this->assertNotEmpty($timemodified);
208
        $this->assertEquals('0.0.0.0', $lastip);
209
        $this->assertEquals('Boost', $theme);
210
        $this->assertEquals('Horses', $tag);
211
        $this->assertEquals($cohort->name, $cohortname);
212
    }
213
 
214
    /**
215
     * Data provider for {@see test_datasource_filters}
216
     *
217
     * @return array[]
218
     */
219
    public function datasource_filters_provider(): array {
220
        return [
221
            // User.
222
            'Filter user' => ['user:userselect', [
223
                'user:userselect_operator' => user_filter::USER_SELECT,
224
                'user:userselect_value' => [-1],
225
            ], false],
226
            'Filter fullname' => ['user:fullname', [
227
                'user:fullname_operator' => text::CONTAINS,
228
                'user:fullname_value' => 'Zoe',
229
            ], true],
230
            'Filter fullname (no match)' => ['user:fullname', [
231
                'user:fullname_operator' => text::CONTAINS,
232
                'user:fullname_value' => 'Alfie',
233
            ], false],
234
            'Filter firstname' => ['user:firstname', [
235
                'user:firstname_operator' => text::IS_EQUAL_TO,
236
                'user:firstname_value' => 'Zoe',
237
            ], true],
238
            'Filter firstname (no match)' => ['user:firstname', [
239
                'user:firstname_operator' => text::IS_EQUAL_TO,
240
                'user:firstname_value' => 'Alfie',
241
            ], false],
242
            'Filter middlename' => ['user:middlename', [
243
                'user:middlename_operator' => text::IS_EQUAL_TO,
244
                'user:middlename_value' => 'Zebediah',
245
            ], true],
246
            'Filter middlename (no match)' => ['user:middlename', [
247
                'user:middlename_operator' => text::IS_EQUAL_TO,
248
                'user:middlename_value' => 'Aardvark',
249
            ], false],
250
            'Filter lastname' => ['user:lastname', [
251
                'user:lastname_operator' => text::IS_EQUAL_TO,
252
                'user:lastname_value' => 'Zebra',
253
            ], true],
254
            'Filter lastname (no match)' => ['user:lastname', [
255
                'user:lastname_operator' => text::IS_EQUAL_TO,
256
                'user:lastname_value' => 'Aardvark',
257
            ], false],
258
            'Filter firstnamephonetic' => ['user:firstnamephonetic', [
259
                'user:firstnamephonetic_operator' => text::IS_EQUAL_TO,
260
                'user:firstnamephonetic_value' => 'Eoz',
261
            ], true],
262
            'Filter firstnamephonetic (no match)' => ['user:firstnamephonetic', [
263
                'user:firstnamephonetic_operator' => text::IS_EQUAL_TO,
264
                'user:firstnamephonetic_value' => 'Alfie',
265
            ], false],
266
            'Filter lastnamephonetic' => ['user:lastnamephonetic', [
267
                'user:lastnamephonetic_operator' => text::IS_EQUAL_TO,
268
                'user:lastnamephonetic_value' => 'Arbez',
269
            ], true],
270
            'Filter lastnamephonetic (no match)' => ['user:lastnamephonetic', [
271
                'user:lastnamephonetic_operator' => text::IS_EQUAL_TO,
272
                'user:lastnamephonetic_value' => 'Aardvark',
273
            ], false],
274
            'Filter alternatename' => ['user:alternatename', [
275
                'user:alternatename_operator' => text::IS_EQUAL_TO,
276
                'user:alternatename_value' => 'Zee',
277
            ], true],
278
            'Filter alternatename (no match)' => ['user:alternatename', [
279
                'user:alternatename_operator' => text::IS_EQUAL_TO,
280
                'user:alternatename_value' => 'Aardvark',
281
            ], false],
282
            'Filter email' => ['user:email', [
283
                'user:email_operator' => text::CONTAINS,
284
                'user:email_value' => 'zoe1',
285
            ], true],
286
            'Filter email (no match)' => ['user:email', [
287
                'user:email_operator' => text::CONTAINS,
288
                'user:email_value' => 'alfie1',
289
            ], false],
290
            'Filter phone1' => ['user:phone1', [
291
                'user:phone1_operator' => text::IS_EQUAL_TO,
292
                'user:phone1_value' => '111',
293
            ], true],
294
            'Filter phone1 (no match)' => ['user:phone1', [
295
                'user:phone1_operator' => text::IS_EQUAL_TO,
296
                'user:phone1_value' => '119',
297
            ], false],
298
            'Filter phone2' => ['user:phone2', [
299
                'user:phone2_operator' => text::IS_EQUAL_TO,
300
                'user:phone2_value' => '222',
301
            ], true],
302
            'Filter phone2 (no match)' => ['user:phone2', [
303
                'user:phone2_operator' => text::IS_EQUAL_TO,
304
                'user:phone2_value' => '229',
305
            ], false],
306
            'Filter address' => ['user:address', [
307
                'user:address_operator' => text::IS_EQUAL_TO,
308
                'user:address_value' => 'Big Farm',
309
            ], true],
310
            'Filter address (no match)' => ['user:address', [
311
                'user:address_operator' => text::IS_EQUAL_TO,
312
                'user:address_value' => 'Small Farm',
313
            ], false],
314
            'Filter city' => ['user:city', [
315
                'user:city_operator' => text::IS_EQUAL_TO,
316
                'user:city_value' => 'Barcelona',
317
            ], true],
318
            'Filter city (no match)' => ['user:city', [
319
                'user:city_operator' => text::IS_EQUAL_TO,
320
                'user:city_value' => 'Perth',
321
            ], false],
322
            'Filter country' => ['user:country', [
323
                'user:country_operator' => select::EQUAL_TO,
324
                'user:country_value' => 'ES',
325
            ], true],
326
            'Filter country (no match)' => ['user:country', [
327
                'user:country_operator' => select::EQUAL_TO,
328
                'user:country_value' => 'AU',
329
            ], false],
330
            'Filter theme' => ['user:theme', [
331
                'user:theme_operator' => select::EQUAL_TO,
332
                'user:theme_value' => 'boost',
333
            ], true],
334
            'Filter theme (no match)' => ['user:theme', [
335
                'user:theme_operator' => select::EQUAL_TO,
336
                'user:theme_value' => 'classic',
337
            ], false],
338
            'Filter description' => ['user:description', [
339
                'user:description_operator' => text::CONTAINS,
340
                'user:description_value' => 'Hello there',
341
            ], true],
342
            'Filter description (no match)' => ['user:description', [
343
                'user:description_operator' => text::CONTAINS,
344
                'user:description_value' => 'Goodbye',
345
            ], false],
346
            'Filter auth' => ['user:auth', [
347
                'user:auth_operator' => select::EQUAL_TO,
348
                'user:auth_value' => 'manual',
349
            ], true],
350
            'Filter auth (no match)' => ['user:auth', [
351
                'user:auth_operator' => select::EQUAL_TO,
352
                'user:auth_value' => 'ldap',
353
            ], false],
354
            'Filter username' => ['user:username', [
355
                'user:username_operator' => text::IS_EQUAL_TO,
356
                'user:username_value' => 'zoe1',
357
            ], true],
358
            'Filter username (no match)' => ['user:username', [
359
                'user:username_operator' => text::IS_EQUAL_TO,
360
                'user:username_value' => 'alfie1',
361
            ], false],
362
            'Filter idnumber' => ['user:idnumber', [
363
                'user:idnumber_operator' => text::IS_EQUAL_TO,
364
                'user:idnumber_value' => 'Z0001',
365
            ], true],
366
            'Filter idnumber (no match)' => ['user:idnumber', [
367
                'user:idnumber_operator' => text::IS_EQUAL_TO,
368
                'user:idnumber_value' => 'A0001',
369
            ], false],
370
            'Filter institution' => ['user:institution', [
371
                'user:institution_operator' => text::IS_EQUAL_TO,
372
                'user:institution_value' => 'Farm',
373
            ], true],
374
            'Filter institution (no match)' => ['user:institution', [
375
                'user:institution_operator' => text::IS_EQUAL_TO,
376
                'user:institution_value' => 'University',
377
            ], false],
378
            'Filter department' => ['user:department', [
379
                'user:department_operator' => text::IS_EQUAL_TO,
380
                'user:department_value' => 'Stable',
381
            ], true],
382
            'Filter department (no match)' => ['user:department', [
383
                'user:department_operator' => text::IS_EQUAL_TO,
384
                'user:department_value' => 'Office',
385
            ], false],
386
            'Filter moodlenetprofile' => ['user:moodlenetprofile', [
387
                'user:moodlenetprofile_operator' => text::IS_EQUAL_TO,
388
                'user:moodlenetprofile_value' => '@zoe1@example.com',
389
            ], true],
390
            'Filter moodlenetprofile (no match)' => ['user:moodlenetprofile', [
391
                'user:moodlenetprofile_operator' => text::IS_EQUAL_TO,
392
                'user:moodlenetprofile_value' => '@alfie1@example.com',
393
            ], false],
394
            'Filter suspended' => ['user:suspended', [
395
                'user:suspended_operator' => boolean_select::NOT_CHECKED,
396
            ], true],
397
            'Filter suspended (no match)' => ['user:suspended', [
398
                'user:suspended_operator' => boolean_select::CHECKED,
399
            ], false],
400
            'Filter confirmed' => ['user:confirmed', [
401
                'user:confirmed_operator' => boolean_select::CHECKED,
402
            ], true],
403
            'Filter confirmed (no match)' => ['user:confirmed', [
404
                'user:confirmed_operator' => boolean_select::NOT_CHECKED,
405
            ], false],
406
            'Filter timecreated' => ['user:timecreated', [
407
                'user:timecreated_operator' => date::DATE_RANGE,
408
                'user:timecreated_from' => 1622502000,
409
            ], true],
410
            'Filter timecreated (no match)' => ['user:timecreated', [
411
                'user:timecreated_operator' => date::DATE_RANGE,
412
                'user:timecreated_from' => 1619823600,
413
                'user:timecreated_to' => 1622502000,
414
            ], false],
415
            'Filter timemodified' => ['user:timemodified', [
416
                'user:timemodified_operator' => date::DATE_RANGE,
417
                'user:timemodified_from' => 1622502000,
418
            ], true],
419
            'Filter timemodified (no match)' => ['user:timemodified', [
420
                'user:timemodified_operator' => date::DATE_RANGE,
421
                'user:timemodified_to' => 1622502000,
422
            ], false],
423
            'Filter lastaccess' => ['user:lastaccess', [
424
                'user:lastaccess_operator' => date::DATE_EMPTY,
425
            ], true],
426
            'Filter lastaccess (no match)' => ['user:lastaccess', [
427
                'user:lastaccess_operator' => date::DATE_RANGE,
428
                'user:lastaccess_from' => 1619823600,
429
                'user:lastaccess_to' => 1622502000,
430
            ], false],
431
            'Filter lastip' => ['user:lastip', [
432
                'user:lastip_operator' => text::IS_EQUAL_TO,
433
                'user:lastip_value' => '0.0.0.0',
434
            ], true],
435
            'Filter lastip (no match)' => ['user:lastip', [
436
                'user:lastip_operator' => text::IS_EQUAL_TO,
437
                'user:lastip_value' => '1.2.3.4',
438
            ], false],
439
 
440
            // Tags.
441
            'Filter tag name' => ['tag:name', [
442
                'tag:name_operator' => tags::EQUAL_TO,
443
                'tag:name_value' => [-1],
444
            ], false],
445
            'Filter tag name not empty' => ['tag:name', [
446
                'tag:name_operator' => tags::NOT_EMPTY,
447
            ], true],
448
 
449
            // Cohort.
450
            'Filter cohort name' => ['cohort:name', [
451
                'cohort:name_operator' => text::IS_EQUAL_TO,
452
                'cohort:name_value' => 'My cohort',
453
            ], true],
454
            'Filter cohort name (no match)' => ['cohort:name', [
455
                'cohort:name_operator' => text::IS_EQUAL_TO,
456
                'cohort:name_value' => 'Not my cohort',
457
            ], false],
458
        ];
459
    }
460
 
461
    /**
462
     * Test datasource filters
463
     *
464
     * @param string $filtername
465
     * @param array $filtervalues
466
     * @param bool $expectmatch
467
     *
468
     * @dataProvider datasource_filters_provider
469
     */
470
    public function test_datasource_filters(string $filtername, array $filtervalues, bool $expectmatch): void {
471
        $this->resetAfterTest();
472
 
473
        $user = $this->getDataGenerator()->create_user([
474
            'username' => 'zoe1',
475
            'email' => 'zoe1@example.com',
476
            'firstname' => 'Zoe',
477
            'middlename' => 'Zebediah',
478
            'lastname' => 'Zebra',
479
            'firstnamephonetic' => 'Eoz',
480
            'lastnamephonetic' => 'Arbez',
481
            'alternatename' => 'Zee',
482
            'idnumber' => 'Z0001',
483
            'institution' => 'Farm',
484
            'department' => 'Stable',
485
            'phone1' => '111',
486
            'phone2' => '222',
487
            'address' => 'Big Farm',
488
            'city' => 'Barcelona',
489
            'country' => 'ES',
490
            'theme' => 'boost',
491
            'description' => 'Hello there',
492
            'moodlenetprofile' => '@zoe1@example.com',
493
            'interests' => ['Horses'],
494
            'lastip' => '0.0.0.0',
495
        ]);
496
 
497
        $cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
498
        cohort_add_member($cohort->id, $user->id);
499
 
500
        /** @var core_reportbuilder_generator $generator */
501
        $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
502
 
503
        // Create report containing single column, and given filter.
504
        $report = $generator->create_report(['name' => 'Tasks', 'source' => users::class, 'default' => 0]);
505
        $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:username']);
506
 
507
        // Add filter, set it's values.
508
        $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => $filtername]);
509
        $content = $this->get_custom_report_content($report->get('id'), 0, $filtervalues);
510
 
511
        if ($expectmatch) {
512
            $this->assertNotEmpty($content);
513
 
514
            // Merge report usernames into easily traversable array.
515
            $usernames = array_merge(...array_map('array_values', $content));
516
            $this->assertContains($user->username, $usernames);
517
        } else {
518
            $this->assertEmpty($content);
519
        }
520
    }
521
 
522
    /**
523
     * Stress test datasource
524
     *
525
     * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php
526
     */
527
    public function test_stress_datasource(): void {
528
        if (!PHPUNIT_LONGTEST) {
529
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
530
        }
531
 
532
        $this->resetAfterTest();
533
 
534
        $user = $this->getDataGenerator()->create_user();
535
 
536
        $this->datasource_stress_test_columns(users::class);
537
        $this->datasource_stress_test_columns_aggregation(users::class);
538
        $this->datasource_stress_test_conditions(users::class, 'user:username');
539
    }
540
}