Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 34... Línea 34...
34
 *
34
 *
35
 * @package   core_user
35
 * @package   core_user
36
 * @category  test
36
 * @category  test
37
 * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
37
 * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
39
 *
-
 
40
 * @covers \core_user\table\participants_search
39
 */
41
 */
40
final class participants_search_test extends advanced_testcase {
42
final class participants_search_test extends advanced_testcase {
Línea 41... Línea 43...
41
 
43
 
42
    /**
44
    /**
Línea 167... Línea 169...
167
        // Run the search.
169
        // Run the search.
168
        $search = new participants_search($course, $coursecontext, $filterset);
170
        $search = new participants_search($course, $coursecontext, $filterset);
169
        $rs = $search->get_participants();
171
        $rs = $search->get_participants();
170
        $this->assertInstanceOf(moodle_recordset::class, $rs);
172
        $this->assertInstanceOf(moodle_recordset::class, $rs);
171
        $records = $this->convert_recordset_to_array($rs);
173
        $records = $this->convert_recordset_to_array($rs);
-
 
174
        $resetrecords = reset($records);
-
 
175
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 172... Línea 176...
172
 
176
 
173
        $this->assertCount($count, $records);
177
        $this->assertCount($count, $records);
Línea 174... Línea 178...
174
        $this->assertEquals($count, $search->get_total_participants_count());
178
        $this->assertEquals($count, $totalparticipants);
175
 
179
 
176
        foreach ($expectedusers as $expecteduser) {
180
        foreach ($expectedusers as $expecteduser) {
177
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
181
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 185... Línea 189...
185
     */
189
     */
186
    public static function role_provider(): array {
190
    public static function role_provider(): array {
187
        $tests = [
191
        $tests = [
188
            // Users who only have one role each.
192
            // Users who only have one role each.
189
            'Users in each role' => (object) [
193
            'Users in each role' => (object) [
190
                'users' => [
194
                'usersdata' => [
191
                    'a' => [
195
                    'a' => [
192
                        'courseroles' => [
196
                        'courseroles' => [
193
                            'student',
197
                            'student',
194
                        ],
198
                        ],
195
                    ],
199
                    ],
Línea 242... Línea 246...
242
                    ],
246
                    ],
243
                ],
247
                ],
244
                'expect' => [
248
                'expect' => [
245
                    // Tests for jointype: ANY.
249
                    // Tests for jointype: ANY.
246
                    'ANY: No role filter' => (object) [
250
                    'ANY: No role filter' => (object) [
247
                        'roles' => [],
251
                        'testroles' => [],
248
                        'jointype' => filter::JOINTYPE_ANY,
252
                        'jointype' => filter::JOINTYPE_ANY,
249
                        'count' => 8,
253
                        'count' => 8,
250
                        'expectedusers' => [
254
                        'expectedusers' => [
251
                            'a',
255
                            'a',
252
                            'b',
256
                            'b',
Línea 257... Línea 261...
257
                            'g',
261
                            'g',
258
                            'h',
262
                            'h',
259
                        ],
263
                        ],
260
                    ],
264
                    ],
261
                    'ANY: Filter on student' => (object) [
265
                    'ANY: Filter on student' => (object) [
262
                        'roles' => ['student'],
266
                        'testroles' => ['student'],
263
                        'jointype' => filter::JOINTYPE_ANY,
267
                        'jointype' => filter::JOINTYPE_ANY,
264
                        'count' => 2,
268
                        'count' => 2,
265
                        'expectedusers' => [
269
                        'expectedusers' => [
266
                            'a',
270
                            'a',
267
                            'b',
271
                            'b',
268
                        ],
272
                        ],
269
                    ],
273
                    ],
270
                    'ANY: Filter on student, teacher' => (object) [
274
                    'ANY: Filter on student, teacher' => (object) [
271
                        'roles' => ['student', 'teacher'],
275
                        'testroles' => ['student', 'teacher'],
272
                        'jointype' => filter::JOINTYPE_ANY,
276
                        'jointype' => filter::JOINTYPE_ANY,
273
                        'count' => 4,
277
                        'count' => 4,
274
                        'expectedusers' => [
278
                        'expectedusers' => [
275
                            'a',
279
                            'a',
276
                            'b',
280
                            'b',
277
                            'e',
281
                            'e',
278
                            'f',
282
                            'f',
279
                        ],
283
                        ],
280
                    ],
284
                    ],
281
                    'ANY: Filter on student, manager (category level role)' => (object) [
285
                    'ANY: Filter on student, manager (category level role)' => (object) [
282
                        'roles' => ['student', 'manager'],
286
                        'testroles' => ['student', 'manager'],
283
                        'jointype' => filter::JOINTYPE_ANY,
287
                        'jointype' => filter::JOINTYPE_ANY,
284
                        'count' => 3,
288
                        'count' => 3,
285
                        'expectedusers' => [
289
                        'expectedusers' => [
286
                            'a',
290
                            'a',
287
                            'b',
291
                            'b',
288
                            'h',
292
                            'h',
289
                        ],
293
                        ],
290
                    ],
294
                    ],
291
                    'ANY: Filter on student, coursecreator (not assigned)' => (object) [
295
                    'ANY: Filter on student, coursecreator (not assigned)' => (object) [
292
                        'roles' => ['student', 'coursecreator'],
296
                        'testroles' => ['student', 'coursecreator'],
293
                        'jointype' => filter::JOINTYPE_ANY,
297
                        'jointype' => filter::JOINTYPE_ANY,
294
                        'count' => 2,
298
                        'count' => 2,
295
                        'expectedusers' => [
299
                        'expectedusers' => [
296
                            'a',
300
                            'a',
297
                            'b',
301
                            'b',
298
                        ],
302
                        ],
299
                    ],
303
                    ],
Línea 300... Línea 304...
300
 
304
 
301
                    // Tests for jointype: ALL.
305
                    // Tests for jointype: ALL.
302
                    'ALL: No role filter' => (object) [
306
                    'ALL: No role filter' => (object) [
303
                        'roles' => [],
307
                        'testroles' => [],
304
                        'jointype' => filter::JOINTYPE_ALL,
308
                        'jointype' => filter::JOINTYPE_ALL,
305
                        'count' => 8,
309
                        'count' => 8,
306
                        'expectedusers' => [
310
                        'expectedusers' => [
307
                            'a',
311
                            'a',
Línea 313... Línea 317...
313
                            'g',
317
                            'g',
314
                            'h',
318
                            'h',
315
                        ],
319
                        ],
316
                    ],
320
                    ],
317
                    'ALL: Filter on student' => (object) [
321
                    'ALL: Filter on student' => (object) [
318
                        'roles' => ['student'],
322
                        'testroles' => ['student'],
319
                        'jointype' => filter::JOINTYPE_ALL,
323
                        'jointype' => filter::JOINTYPE_ALL,
320
                        'count' => 2,
324
                        'count' => 2,
321
                        'expectedusers' => [
325
                        'expectedusers' => [
322
                            'a',
326
                            'a',
323
                            'b',
327
                            'b',
324
                        ],
328
                        ],
325
                    ],
329
                    ],
326
                    'ALL: Filter on student, teacher' => (object) [
330
                    'ALL: Filter on student, teacher' => (object) [
327
                        'roles' => ['student', 'teacher'],
331
                        'testroles' => ['student', 'teacher'],
328
                        'jointype' => filter::JOINTYPE_ALL,
332
                        'jointype' => filter::JOINTYPE_ALL,
329
                        'count' => 0,
333
                        'count' => 0,
330
                        'expectedusers' => [],
334
                        'expectedusers' => [],
331
                    ],
335
                    ],
332
                    'ALL: Filter on student, manager (category level role))' => (object) [
336
                    'ALL: Filter on student, manager (category level role))' => (object) [
333
                        'roles' => ['student', 'manager'],
337
                        'testroles' => ['student', 'manager'],
334
                        'jointype' => filter::JOINTYPE_ALL,
338
                        'jointype' => filter::JOINTYPE_ALL,
335
                        'count' => 0,
339
                        'count' => 0,
336
                        'expectedusers' => [],
340
                        'expectedusers' => [],
337
                    ],
341
                    ],
338
                    'ALL: Filter on student, coursecreator (not assigned))' => (object) [
342
                    'ALL: Filter on student, coursecreator (not assigned))' => (object) [
339
                        'roles' => ['student', 'coursecreator'],
343
                        'testroles' => ['student', 'coursecreator'],
340
                        'jointype' => filter::JOINTYPE_ALL,
344
                        'jointype' => filter::JOINTYPE_ALL,
341
                        'count' => 0,
345
                        'count' => 0,
342
                        'expectedusers' => [],
346
                        'expectedusers' => [],
343
                    ],
347
                    ],
Línea 344... Línea 348...
344
 
348
 
345
                    // Tests for jointype: NONE.
349
                    // Tests for jointype: NONE.
346
                    'NONE: No role filter' => (object) [
350
                    'NONE: No role filter' => (object) [
347
                        'roles' => [],
351
                        'testroles' => [],
348
                        'jointype' => filter::JOINTYPE_NONE,
352
                        'jointype' => filter::JOINTYPE_NONE,
349
                        'count' => 8,
353
                        'count' => 8,
350
                        'expectedusers' => [
354
                        'expectedusers' => [
351
                            'a',
355
                            'a',
Línea 357... Línea 361...
357
                            'g',
361
                            'g',
358
                            'h',
362
                            'h',
359
                        ],
363
                        ],
360
                    ],
364
                    ],
361
                    'NONE: Filter on student' => (object) [
365
                    'NONE: Filter on student' => (object) [
362
                        'roles' => ['student'],
366
                        'testroles' => ['student'],
363
                        'jointype' => filter::JOINTYPE_NONE,
367
                        'jointype' => filter::JOINTYPE_NONE,
364
                        'count' => 6,
368
                        'count' => 6,
365
                        'expectedusers' => [
369
                        'expectedusers' => [
366
                            'c',
370
                            'c',
367
                            'd',
371
                            'd',
Línea 370... Línea 374...
370
                            'g',
374
                            'g',
371
                            'h',
375
                            'h',
372
                        ],
376
                        ],
373
                    ],
377
                    ],
374
                    'NONE: Filter on student, teacher' => (object) [
378
                    'NONE: Filter on student, teacher' => (object) [
375
                        'roles' => ['student', 'teacher'],
379
                        'testroles' => ['student', 'teacher'],
376
                        'jointype' => filter::JOINTYPE_NONE,
380
                        'jointype' => filter::JOINTYPE_NONE,
377
                        'count' => 4,
381
                        'count' => 4,
378
                        'expectedusers' => [
382
                        'expectedusers' => [
379
                            'c',
383
                            'c',
380
                            'd',
384
                            'd',
381
                            'g',
385
                            'g',
382
                            'h',
386
                            'h',
383
                        ],
387
                        ],
384
                    ],
388
                    ],
385
                    'NONE: Filter on student, manager (category level role))' => (object) [
389
                    'NONE: Filter on student, manager (category level role))' => (object) [
386
                        'roles' => ['student', 'manager'],
390
                        'testroles' => ['student', 'manager'],
387
                        'jointype' => filter::JOINTYPE_NONE,
391
                        'jointype' => filter::JOINTYPE_NONE,
388
                        'count' => 5,
392
                        'count' => 5,
389
                        'expectedusers' => [
393
                        'expectedusers' => [
390
                            'c',
394
                            'c',
391
                            'd',
395
                            'd',
Línea 393... Línea 397...
393
                            'f',
397
                            'f',
394
                            'g',
398
                            'g',
395
                        ],
399
                        ],
396
                    ],
400
                    ],
397
                    'NONE: Filter on student, coursecreator (not assigned))' => (object) [
401
                    'NONE: Filter on student, coursecreator (not assigned))' => (object) [
398
                        'roles' => ['student', 'coursecreator'],
402
                        'testroles' => ['student', 'coursecreator'],
399
                        'jointype' => filter::JOINTYPE_NONE,
403
                        'jointype' => filter::JOINTYPE_NONE,
400
                        'count' => 6,
404
                        'count' => 6,
401
                        'expectedusers' => [
405
                        'expectedusers' => [
402
                            'c',
406
                            'c',
403
                            'd',
407
                            'd',
Línea 408... Línea 412...
408
                        ],
412
                        ],
409
                    ],
413
                    ],
410
                ],
414
                ],
411
            ],
415
            ],
412
            'Users with multiple roles' => (object) [
416
            'Users with multiple roles' => (object) [
413
                'users' => [
417
                'usersdata' => [
414
                    'a' => [
418
                    'a' => [
415
                        'courseroles' => [
419
                        'courseroles' => [
416
                            'student',
420
                            'student',
417
                        ],
421
                        ],
418
                    ],
422
                    ],
Línea 468... Línea 472...
468
                    ],
472
                    ],
469
                ],
473
                ],
470
                'expect' => [
474
                'expect' => [
471
                    // Tests for jointype: ANY.
475
                    // Tests for jointype: ANY.
472
                    'ANY: No role filter' => (object) [
476
                    'ANY: No role filter' => (object) [
473
                        'roles' => [],
477
                        'testroles' => [],
474
                        'jointype' => filter::JOINTYPE_ANY,
478
                        'jointype' => filter::JOINTYPE_ANY,
475
                        'count' => 8,
479
                        'count' => 8,
476
                        'expectedusers' => [
480
                        'expectedusers' => [
477
                            'a',
481
                            'a',
478
                            'b',
482
                            'b',
Línea 483... Línea 487...
483
                            'g',
487
                            'g',
484
                            'h',
488
                            'h',
485
                        ],
489
                        ],
486
                    ],
490
                    ],
487
                    'ANY: Filter on student' => (object) [
491
                    'ANY: Filter on student' => (object) [
488
                        'roles' => ['student'],
492
                        'testroles' => ['student'],
489
                        'jointype' => filter::JOINTYPE_ANY,
493
                        'jointype' => filter::JOINTYPE_ANY,
490
                        'count' => 2,
494
                        'count' => 2,
491
                        'expectedusers' => [
495
                        'expectedusers' => [
492
                            'a',
496
                            'a',
493
                            'b',
497
                            'b',
494
                        ],
498
                        ],
495
                    ],
499
                    ],
496
                    'ANY: Filter on teacher' => (object) [
500
                    'ANY: Filter on teacher' => (object) [
497
                        'roles' => ['teacher'],
501
                        'testroles' => ['teacher'],
498
                        'jointype' => filter::JOINTYPE_ANY,
502
                        'jointype' => filter::JOINTYPE_ANY,
499
                        'count' => 3,
503
                        'count' => 3,
500
                        'expectedusers' => [
504
                        'expectedusers' => [
501
                            'b',
505
                            'b',
502
                            'e',
506
                            'e',
503
                            'f',
507
                            'f',
504
                        ],
508
                        ],
505
                    ],
509
                    ],
506
                    'ANY: Filter on editingteacher' => (object) [
510
                    'ANY: Filter on editingteacher' => (object) [
507
                        'roles' => ['editingteacher'],
511
                        'testroles' => ['editingteacher'],
508
                        'jointype' => filter::JOINTYPE_ANY,
512
                        'jointype' => filter::JOINTYPE_ANY,
509
                        'count' => 3,
513
                        'count' => 3,
510
                        'expectedusers' => [
514
                        'expectedusers' => [
511
                            'c',
515
                            'c',
512
                            'd',
516
                            'd',
513
                            'e',
517
                            'e',
514
                        ],
518
                        ],
515
                    ],
519
                    ],
516
                    'ANY: Filter on student, teacher' => (object) [
520
                    'ANY: Filter on student, teacher' => (object) [
517
                        'roles' => ['student', 'teacher'],
521
                        'testroles' => ['student', 'teacher'],
518
                        'jointype' => filter::JOINTYPE_ANY,
522
                        'jointype' => filter::JOINTYPE_ANY,
519
                        'count' => 4,
523
                        'count' => 4,
520
                        'expectedusers' => [
524
                        'expectedusers' => [
521
                            'a',
525
                            'a',
522
                            'b',
526
                            'b',
523
                            'e',
527
                            'e',
524
                            'f',
528
                            'f',
525
                        ],
529
                        ],
526
                    ],
530
                    ],
527
                    'ANY: Filter on teacher, editingteacher' => (object) [
531
                    'ANY: Filter on teacher, editingteacher' => (object) [
528
                        'roles' => ['teacher', 'editingteacher'],
532
                        'testroles' => ['teacher', 'editingteacher'],
529
                        'jointype' => filter::JOINTYPE_ANY,
533
                        'jointype' => filter::JOINTYPE_ANY,
530
                        'count' => 5,
534
                        'count' => 5,
531
                        'expectedusers' => [
535
                        'expectedusers' => [
532
                            'b',
536
                            'b',
533
                            'c',
537
                            'c',
Línea 535... Línea 539...
535
                            'e',
539
                            'e',
536
                            'f',
540
                            'f',
537
                        ],
541
                        ],
538
                    ],
542
                    ],
539
                    'ANY: Filter on student, manager (category level role)' => (object) [
543
                    'ANY: Filter on student, manager (category level role)' => (object) [
540
                        'roles' => ['student', 'manager'],
544
                        'testroles' => ['student', 'manager'],
541
                        'jointype' => filter::JOINTYPE_ANY,
545
                        'jointype' => filter::JOINTYPE_ANY,
542
                        'count' => 3,
546
                        'count' => 3,
543
                        'expectedusers' => [
547
                        'expectedusers' => [
544
                            'a',
548
                            'a',
545
                            'b',
549
                            'b',
546
                            'h',
550
                            'h',
547
                        ],
551
                        ],
548
                    ],
552
                    ],
549
                    'ANY: Filter on student, coursecreator (not assigned)' => (object) [
553
                    'ANY: Filter on student, coursecreator (not assigned)' => (object) [
550
                        'roles' => ['student', 'coursecreator'],
554
                        'testroles' => ['student', 'coursecreator'],
551
                        'jointype' => filter::JOINTYPE_ANY,
555
                        'jointype' => filter::JOINTYPE_ANY,
552
                        'count' => 2,
556
                        'count' => 2,
553
                        'expectedusers' => [
557
                        'expectedusers' => [
554
                            'a',
558
                            'a',
555
                            'b',
559
                            'b',
556
                        ],
560
                        ],
557
                    ],
561
                    ],
Línea 558... Línea 562...
558
 
562
 
559
                    // Tests for jointype: ALL.
563
                    // Tests for jointype: ALL.
560
                    'ALL: No role filter' => (object) [
564
                    'ALL: No role filter' => (object) [
561
                        'roles' => [],
565
                        'testroles' => [],
562
                        'jointype' => filter::JOINTYPE_ALL,
566
                        'jointype' => filter::JOINTYPE_ALL,
563
                        'count' => 8,
567
                        'count' => 8,
564
                        'expectedusers' => [
568
                        'expectedusers' => [
565
                            'a',
569
                            'a',
Línea 571... Línea 575...
571
                            'g',
575
                            'g',
572
                            'h',
576
                            'h',
573
                        ],
577
                        ],
574
                    ],
578
                    ],
575
                    'ALL: Filter on student' => (object) [
579
                    'ALL: Filter on student' => (object) [
576
                        'roles' => ['student'],
580
                        'testroles' => ['student'],
577
                        'jointype' => filter::JOINTYPE_ALL,
581
                        'jointype' => filter::JOINTYPE_ALL,
578
                        'count' => 2,
582
                        'count' => 2,
579
                        'expectedusers' => [
583
                        'expectedusers' => [
580
                            'a',
584
                            'a',
581
                            'b',
585
                            'b',
582
                        ],
586
                        ],
583
                    ],
587
                    ],
584
                    'ALL: Filter on teacher' => (object) [
588
                    'ALL: Filter on teacher' => (object) [
585
                        'roles' => ['teacher'],
589
                        'testroles' => ['teacher'],
586
                        'jointype' => filter::JOINTYPE_ALL,
590
                        'jointype' => filter::JOINTYPE_ALL,
587
                        'count' => 3,
591
                        'count' => 3,
588
                        'expectedusers' => [
592
                        'expectedusers' => [
589
                            'b',
593
                            'b',
590
                            'e',
594
                            'e',
591
                            'f',
595
                            'f',
592
                        ],
596
                        ],
593
                    ],
597
                    ],
594
                    'ALL: Filter on editingteacher' => (object) [
598
                    'ALL: Filter on editingteacher' => (object) [
595
                        'roles' => ['editingteacher'],
599
                        'testroles' => ['editingteacher'],
596
                        'jointype' => filter::JOINTYPE_ALL,
600
                        'jointype' => filter::JOINTYPE_ALL,
597
                        'count' => 3,
601
                        'count' => 3,
598
                        'expectedusers' => [
602
                        'expectedusers' => [
599
                            'c',
603
                            'c',
600
                            'd',
604
                            'd',
601
                            'e',
605
                            'e',
602
                        ],
606
                        ],
603
                    ],
607
                    ],
604
                    'ALL: Filter on student, teacher' => (object) [
608
                    'ALL: Filter on student, teacher' => (object) [
605
                        'roles' => ['student', 'teacher'],
609
                        'testroles' => ['student', 'teacher'],
606
                        'jointype' => filter::JOINTYPE_ALL,
610
                        'jointype' => filter::JOINTYPE_ALL,
607
                        'count' => 1,
611
                        'count' => 1,
608
                        'expectedusers' => [
612
                        'expectedusers' => [
609
                            'b',
613
                            'b',
610
                        ],
614
                        ],
611
                    ],
615
                    ],
612
                    'ALL: Filter on teacher, editingteacher' => (object) [
616
                    'ALL: Filter on teacher, editingteacher' => (object) [
613
                        'roles' => ['teacher', 'editingteacher'],
617
                        'testroles' => ['teacher', 'editingteacher'],
614
                        'jointype' => filter::JOINTYPE_ALL,
618
                        'jointype' => filter::JOINTYPE_ALL,
615
                        'count' => 1,
619
                        'count' => 1,
616
                        'expectedusers' => [
620
                        'expectedusers' => [
617
                            'e',
621
                            'e',
618
                        ],
622
                        ],
619
                    ],
623
                    ],
620
                    'ALL: Filter on student, manager (category level role)' => (object) [
624
                    'ALL: Filter on student, manager (category level role)' => (object) [
621
                        'roles' => ['student', 'manager'],
625
                        'testroles' => ['student', 'manager'],
622
                        'jointype' => filter::JOINTYPE_ALL,
626
                        'jointype' => filter::JOINTYPE_ALL,
623
                        'count' => 0,
627
                        'count' => 0,
624
                        'expectedusers' => [],
628
                        'expectedusers' => [],
625
                    ],
629
                    ],
626
                    'ALL: Filter on student, coursecreator (not assigned)' => (object) [
630
                    'ALL: Filter on student, coursecreator (not assigned)' => (object) [
627
                        'roles' => ['student', 'coursecreator'],
631
                        'testroles' => ['student', 'coursecreator'],
628
                        'jointype' => filter::JOINTYPE_ALL,
632
                        'jointype' => filter::JOINTYPE_ALL,
629
                        'count' => 0,
633
                        'count' => 0,
630
                        'expectedusers' => [],
634
                        'expectedusers' => [],
631
                    ],
635
                    ],
Línea 632... Línea 636...
632
 
636
 
633
                    // Tests for jointype: NONE.
637
                    // Tests for jointype: NONE.
634
                    'NONE: No role filter' => (object) [
638
                    'NONE: No role filter' => (object) [
635
                        'roles' => [],
639
                        'testroles' => [],
636
                        'jointype' => filter::JOINTYPE_NONE,
640
                        'jointype' => filter::JOINTYPE_NONE,
637
                        'count' => 8,
641
                        'count' => 8,
638
                        'expectedusers' => [
642
                        'expectedusers' => [
639
                            'a',
643
                            'a',
Línea 645... Línea 649...
645
                            'g',
649
                            'g',
646
                            'h',
650
                            'h',
647
                        ],
651
                        ],
648
                    ],
652
                    ],
649
                    'NONE: Filter on student' => (object) [
653
                    'NONE: Filter on student' => (object) [
650
                        'roles' => ['student'],
654
                        'testroles' => ['student'],
651
                        'jointype' => filter::JOINTYPE_NONE,
655
                        'jointype' => filter::JOINTYPE_NONE,
652
                        'count' => 6,
656
                        'count' => 6,
653
                        'expectedusers' => [
657
                        'expectedusers' => [
654
                            'c',
658
                            'c',
655
                            'd',
659
                            'd',
Línea 658... Línea 662...
658
                            'g',
662
                            'g',
659
                            'h',
663
                            'h',
660
                        ],
664
                        ],
661
                    ],
665
                    ],
662
                    'NONE: Filter on teacher' => (object) [
666
                    'NONE: Filter on teacher' => (object) [
663
                        'roles' => ['teacher'],
667
                        'testroles' => ['teacher'],
664
                        'jointype' => filter::JOINTYPE_NONE,
668
                        'jointype' => filter::JOINTYPE_NONE,
665
                        'count' => 5,
669
                        'count' => 5,
666
                        'expectedusers' => [
670
                        'expectedusers' => [
667
                            'a',
671
                            'a',
668
                            'c',
672
                            'c',
Línea 670... Línea 674...
670
                            'g',
674
                            'g',
671
                            'h',
675
                            'h',
672
                        ],
676
                        ],
673
                    ],
677
                    ],
674
                    'NONE: Filter on editingteacher' => (object) [
678
                    'NONE: Filter on editingteacher' => (object) [
675
                        'roles' => ['editingteacher'],
679
                        'testroles' => ['editingteacher'],
676
                        'jointype' => filter::JOINTYPE_NONE,
680
                        'jointype' => filter::JOINTYPE_NONE,
677
                        'count' => 5,
681
                        'count' => 5,
678
                        'expectedusers' => [
682
                        'expectedusers' => [
679
                            'a',
683
                            'a',
680
                            'b',
684
                            'b',
Línea 682... Línea 686...
682
                            'g',
686
                            'g',
683
                            'h',
687
                            'h',
684
                        ],
688
                        ],
685
                    ],
689
                    ],
686
                    'NONE: Filter on student, teacher' => (object) [
690
                    'NONE: Filter on student, teacher' => (object) [
687
                        'roles' => ['student', 'teacher'],
691
                        'testroles' => ['student', 'teacher'],
688
                        'jointype' => filter::JOINTYPE_NONE,
692
                        'jointype' => filter::JOINTYPE_NONE,
689
                        'count' => 4,
693
                        'count' => 4,
690
                        'expectedusers' => [
694
                        'expectedusers' => [
691
                            'c',
695
                            'c',
692
                            'd',
696
                            'd',
693
                            'g',
697
                            'g',
694
                            'h',
698
                            'h',
695
                        ],
699
                        ],
696
                    ],
700
                    ],
697
                    'NONE: Filter on teacher, editingteacher' => (object) [
701
                    'NONE: Filter on teacher, editingteacher' => (object) [
698
                        'roles' => ['teacher', 'editingteacher'],
702
                        'testroles' => ['teacher', 'editingteacher'],
699
                        'jointype' => filter::JOINTYPE_NONE,
703
                        'jointype' => filter::JOINTYPE_NONE,
700
                        'count' => 3,
704
                        'count' => 3,
701
                        'expectedusers' => [
705
                        'expectedusers' => [
702
                            'a',
706
                            'a',
703
                            'g',
707
                            'g',
704
                            'h',
708
                            'h',
705
                        ],
709
                        ],
706
                    ],
710
                    ],
707
                    'NONE: Filter on student, manager (category level role)' => (object) [
711
                    'NONE: Filter on student, manager (category level role)' => (object) [
708
                        'roles' => ['student', 'manager'],
712
                        'testroles' => ['student', 'manager'],
709
                        'jointype' => filter::JOINTYPE_NONE,
713
                        'jointype' => filter::JOINTYPE_NONE,
710
                        'count' => 5,
714
                        'count' => 5,
711
                        'expectedusers' => [
715
                        'expectedusers' => [
712
                            'c',
716
                            'c',
713
                            'd',
717
                            'd',
Línea 715... Línea 719...
715
                            'f',
719
                            'f',
716
                            'g',
720
                            'g',
717
                        ],
721
                        ],
718
                    ],
722
                    ],
719
                    'NONE: Filter on student, coursecreator (not assigned)' => (object) [
723
                    'NONE: Filter on student, coursecreator (not assigned)' => (object) [
720
                        'roles' => ['student', 'coursecreator'],
724
                        'testroles' => ['student', 'coursecreator'],
721
                        'jointype' => filter::JOINTYPE_NONE,
725
                        'jointype' => filter::JOINTYPE_NONE,
722
                        'count' => 6,
726
                        'count' => 6,
723
                        'expectedusers' => [
727
                        'expectedusers' => [
724
                            'c',
728
                            'c',
725
                            'd',
729
                            'd',
Línea 735... Línea 739...
735
 
739
 
736
        $finaltests = [];
740
        $finaltests = [];
737
        foreach ($tests as $testname => $testdata) {
741
        foreach ($tests as $testname => $testdata) {
738
            foreach ($testdata->expect as $expectname => $expectdata) {
742
            foreach ($testdata->expect as $expectname => $expectdata) {
739
                $finaltests["{$testname} => {$expectname}"] = [
743
                $finaltests["{$testname} => {$expectname}"] = [
740
                    'users' => $testdata->users,
744
                    'usersdata' => $testdata->usersdata,
741
                    'roles' => $expectdata->roles,
745
                    'testroles' => $expectdata->testroles,
742
                    'jointype' => $expectdata->jointype,
746
                    'jointype' => $expectdata->jointype,
743
                    'count' => $expectdata->count,
747
                    'count' => $expectdata->count,
744
                    'expectedusers' => $expectdata->expectedusers,
748
                    'expectedusers' => $expectdata->expectedusers,
745
                ];
749
                ];
Línea 777... Línea 781...
777
        $filterset->add_filter(new integer_filter('courseid', null, [(int) $course->id]));
781
        $filterset->add_filter(new integer_filter('courseid', null, [(int) $course->id]));
778
        $filterset->add_filter(new string_filter('country', $jointype, $countries));
782
        $filterset->add_filter(new string_filter('country', $jointype, $countries));
Línea 779... Línea 783...
779
 
783
 
780
        // Run the search, assert count matches the number of expected users.
784
        // Run the search, assert count matches the number of expected users.
781
        $search = new participants_search($course, context_course::instance($course->id), $filterset);
-
 
782
        $this->assertEquals(count($expectedusers), $search->get_total_participants_count());
-
 
783
 
785
        $search = new participants_search($course, context_course::instance($course->id), $filterset);
-
 
786
        $rs = $search->get_participants();
-
 
787
        $totalparticipants = $rs->current()->fullcount ?? 0;
-
 
788
        $this->assertEquals(count($expectedusers), $totalparticipants);
784
        $rs = $search->get_participants();
789
 
Línea 785... Línea 790...
785
        $this->assertInstanceOf(moodle_recordset::class, $rs);
790
        $this->assertInstanceOf(moodle_recordset::class, $rs);
786
 
791
 
787
        // Assert that each expected user is within the participant records.
792
        // Assert that each expected user is within the participant records.
Línea 794... Línea 799...
794
    /**
799
    /**
795
     * Data provider for {@see test_country_filter}
800
     * Data provider for {@see test_country_filter}
796
     *
801
     *
797
     * @return array
802
     * @return array
798
     */
803
     */
799
    public function country_provider(): array {
804
    public static function country_provider(): array {
800
        $tests = [
805
        $tests = [
801
            'users' => [
806
            'usersdata' => [
802
                'user1' => 'DE',
807
                'user1' => 'DE',
803
                'user2' => 'ES',
808
                'user2' => 'ES',
804
                'user3' => 'ES',
809
                'user3' => 'ES',
805
                'user4' => 'GB',
810
                'user4' => 'GB',
806
            ],
811
            ],
Línea 903... Línea 908...
903
        ];
908
        ];
Línea 904... Línea 909...
904
 
909
 
905
        $finaltests = [];
910
        $finaltests = [];
906
        foreach ($tests['expects'] as $testname => $test) {
911
        foreach ($tests['expects'] as $testname => $test) {
907
            $finaltests[$testname] = [
912
            $finaltests[$testname] = [
908
                'users' => $tests['users'],
913
                'usersdata' => $tests['usersdata'],
909
                'countries' => $test->countries,
914
                'countries' => $test->countries,
910
                'jointype' => $test->jointype,
915
                'jointype' => $test->jointype,
911
                'expectedusers' => $test->expectedusers,
916
                'expectedusers' => $test->expectedusers,
912
            ];
917
            ];
Línea 975... Línea 980...
975
        // Run the search.
980
        // Run the search.
976
        $search = new participants_search($course, $coursecontext, $filterset);
981
        $search = new participants_search($course, $coursecontext, $filterset);
977
        $rs = $search->get_participants();
982
        $rs = $search->get_participants();
978
        $this->assertInstanceOf(moodle_recordset::class, $rs);
983
        $this->assertInstanceOf(moodle_recordset::class, $rs);
979
        $records = $this->convert_recordset_to_array($rs);
984
        $records = $this->convert_recordset_to_array($rs);
-
 
985
        $resetrecords = reset($records);
-
 
986
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 980... Línea 987...
980
 
987
 
981
        $this->assertCount($count, $records);
988
        $this->assertCount($count, $records);
Línea 982... Línea 989...
982
        $this->assertEquals($count, $search->get_total_participants_count());
989
        $this->assertEquals($count, $totalparticipants);
983
 
990
 
984
        foreach ($expectedusers as $expecteduser) {
991
        foreach ($expectedusers as $expecteduser) {
985
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
992
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 989... Línea 996...
989
    /**
996
    /**
990
     * Data provider for keywords tests.
997
     * Data provider for keywords tests.
991
     *
998
     *
992
     * @return array
999
     * @return array
993
     */
1000
     */
994
    public function keywords_provider(): array {
1001
    public static function keywords_provider(): array {
995
        $tests = [
1002
        $tests = [
996
            // Users where the keyword matches basic user fields such as names and email.
1003
            // Users where the keyword matches basic user fields such as names and email.
997
            'Users with basic names' => (object) [
1004
            'Users with basic names' => (object) [
998
                'users' => [
1005
                'usersdata' => [
999
                    'adam.ant' => [
1006
                    'adam.ant' => [
1000
                        'firstname' => 'Adam',
1007
                        'firstname' => 'Adam',
1001
                        'lastname' => 'Ant',
1008
                        'lastname' => 'Ant',
1002
                    ],
1009
                    ],
1003
                    'barbara.bennett' => [
1010
                    'barbara.bennett' => [
Línea 1449... Línea 1456...
1449
 
1456
 
1450
        $finaltests = [];
1457
        $finaltests = [];
1451
        foreach ($tests as $testname => $testdata) {
1458
        foreach ($tests as $testname => $testdata) {
1452
            foreach ($testdata->expect as $expectname => $expectdata) {
1459
            foreach ($testdata->expect as $expectname => $expectdata) {
1453
                $finaltests["{$testname} => {$expectname}"] = [
1460
                $finaltests["{$testname} => {$expectname}"] = [
1454
                    'users' => $testdata->users,
1461
                    'usersdata' => $testdata->usersdata,
1455
                    'keywords' => $expectdata->keywords,
1462
                    'keywords' => $expectdata->keywords,
1456
                    'jointype' => $expectdata->jointype,
1463
                    'jointype' => $expectdata->jointype,
1457
                    'count' => $expectdata->count,
1464
                    'count' => $expectdata->count,
1458
                    'expectedusers' => $expectdata->expectedusers,
1465
                    'expectedusers' => $expectdata->expectedusers,
Línea 1490... Línea 1497...
1490
        }
1497
        }
Línea 1491... Línea 1498...
1491
 
1498
 
1492
        foreach ($usersdata as $username => $userdata) {
1499
        foreach ($usersdata as $username => $userdata) {
Línea 1493... Línea 1500...
1493
            $user = $this->getDataGenerator()->create_user(['username' => $username]);
1500
            $user = $this->getDataGenerator()->create_user(['username' => $username]);
1494
 
1501
 
1495
            if (array_key_exists('status', $userdata)) {
1502
            if (array_key_exists('statuses', $userdata)) {
1496
                foreach ($userdata['status'] as $enrolmethod => $status) {
1503
                foreach ($userdata['statuses'] as $enrolmethod => $status) {
1497
                    $this->getDataGenerator()->enrol_user($user->id, $course->id, 'student', $enrolmethod, 0, 0, $status);
1504
                    $this->getDataGenerator()->enrol_user($user->id, $course->id, 'student', $enrolmethod, 0, 0, $status);
Línea 1498... Línea 1505...
1498
                }
1505
                }
Línea 1521... Línea 1528...
1521
        // Run the search.
1528
        // Run the search.
1522
        $search = new participants_search($course, $coursecontext, $filterset);
1529
        $search = new participants_search($course, $coursecontext, $filterset);
1523
        $rs = $search->get_participants();
1530
        $rs = $search->get_participants();
1524
        $this->assertInstanceOf(moodle_recordset::class, $rs);
1531
        $this->assertInstanceOf(moodle_recordset::class, $rs);
1525
        $records = $this->convert_recordset_to_array($rs);
1532
        $records = $this->convert_recordset_to_array($rs);
-
 
1533
        $resetrecords = reset($records);
-
 
1534
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 1526... Línea 1535...
1526
 
1535
 
1527
        $this->assertCount($count, $records);
1536
        $this->assertCount($count, $records);
Línea 1528... Línea 1537...
1528
        $this->assertEquals($count, $search->get_total_participants_count());
1537
        $this->assertEquals($count, $totalparticipants);
1529
 
1538
 
1530
        foreach ($expectedusers as $expecteduser) {
1539
        foreach ($expectedusers as $expecteduser) {
1531
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
1540
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 1535... Línea 1544...
1535
    /**
1544
    /**
1536
     * Data provider for status filter tests.
1545
     * Data provider for status filter tests.
1537
     *
1546
     *
1538
     * @return array
1547
     * @return array
1539
     */
1548
     */
1540
    public function status_provider(): array {
1549
    public static function status_provider(): array {
1541
        $tests = [
1550
        $tests = [
1542
            // Users with different statuses and enrolment methods (so multiple statuses are possible for the same user).
1551
            // Users with different statuses and enrolment methods (so multiple statuses are possible for the same user).
1543
            'Users with different enrolment statuses' => (object) [
1552
            'Users with different enrolment statuses' => (object) [
1544
                'users' => [
1553
                'usersdata' => [
1545
                    'a' => [
1554
                    'a' => [
1546
                        'status' => [
1555
                        'statuses' => [
1547
                            'manual' => ENROL_USER_ACTIVE,
1556
                            'manual' => ENROL_USER_ACTIVE,
1548
                        ]
1557
                        ]
1549
                    ],
1558
                    ],
1550
                    'b' => [
1559
                    'b' => [
1551
                        'status' => [
1560
                        'statuses' => [
1552
                            'self' => ENROL_USER_ACTIVE,
1561
                            'self' => ENROL_USER_ACTIVE,
1553
                        ]
1562
                        ]
1554
                    ],
1563
                    ],
1555
                    'c' => [
1564
                    'c' => [
1556
                        'status' => [
1565
                        'statuses' => [
1557
                            'manual' => ENROL_USER_SUSPENDED,
1566
                            'manual' => ENROL_USER_SUSPENDED,
1558
                        ]
1567
                        ]
1559
                    ],
1568
                    ],
1560
                    'd' => [
1569
                    'd' => [
1561
                        'status' => [
1570
                        'statuses' => [
1562
                            'self' => ENROL_USER_SUSPENDED,
1571
                            'self' => ENROL_USER_SUSPENDED,
1563
                        ]
1572
                        ]
1564
                    ],
1573
                    ],
1565
                    'e' => [
1574
                    'e' => [
1566
                        'status' => [
1575
                        'statuses' => [
1567
                            'manual' => ENROL_USER_ACTIVE,
1576
                            'manual' => ENROL_USER_ACTIVE,
1568
                            'self' => ENROL_USER_SUSPENDED,
1577
                            'self' => ENROL_USER_SUSPENDED,
1569
                        ]
1578
                        ]
1570
                    ],
1579
                    ],
1571
                ],
1580
                ],
1572
                'expect' => [
1581
                'expect' => [
1573
                    // Tests for jointype: ANY.
1582
                    // Tests for jointype: ANY.
1574
                    'ANY: No filter' => (object) [
1583
                    'ANY: No filter' => (object) [
1575
                        'status' => [],
1584
                        'statuses' => [],
1576
                        'jointype' => filter::JOINTYPE_ANY,
1585
                        'jointype' => filter::JOINTYPE_ANY,
1577
                        'count' => 5,
1586
                        'count' => 5,
1578
                        'expectedusers' => [
1587
                        'expectedusers' => [
1579
                            'a',
1588
                            'a',
1580
                            'b',
1589
                            'b',
Línea 1582... Línea 1591...
1582
                            'd',
1591
                            'd',
1583
                            'e',
1592
                            'e',
1584
                        ],
1593
                        ],
1585
                    ],
1594
                    ],
1586
                    'ANY: Filter on active only' => (object) [
1595
                    'ANY: Filter on active only' => (object) [
1587
                        'status' => [ENROL_USER_ACTIVE],
1596
                        'statuses' => [ENROL_USER_ACTIVE],
1588
                        'jointype' => filter::JOINTYPE_ANY,
1597
                        'jointype' => filter::JOINTYPE_ANY,
1589
                        'count' => 3,
1598
                        'count' => 3,
1590
                        'expectedusers' => [
1599
                        'expectedusers' => [
1591
                            'a',
1600
                            'a',
1592
                            'b',
1601
                            'b',
1593
                            'e',
1602
                            'e',
1594
                        ],
1603
                        ],
1595
                    ],
1604
                    ],
1596
                    'ANY: Filter on suspended only' => (object) [
1605
                    'ANY: Filter on suspended only' => (object) [
1597
                        'status' => [ENROL_USER_SUSPENDED],
1606
                        'statuses' => [ENROL_USER_SUSPENDED],
1598
                        'jointype' => filter::JOINTYPE_ANY,
1607
                        'jointype' => filter::JOINTYPE_ANY,
1599
                        'count' => 3,
1608
                        'count' => 3,
1600
                        'expectedusers' => [
1609
                        'expectedusers' => [
1601
                            'c',
1610
                            'c',
1602
                            'd',
1611
                            'd',
1603
                            'e',
1612
                            'e',
1604
                        ],
1613
                        ],
1605
                    ],
1614
                    ],
1606
                    'ANY: Filter on multiple statuses' => (object) [
1615
                    'ANY: Filter on multiple statuses' => (object) [
1607
                        'status' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1616
                        'statuses' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1608
                        'jointype' => filter::JOINTYPE_ANY,
1617
                        'jointype' => filter::JOINTYPE_ANY,
1609
                        'count' => 5,
1618
                        'count' => 5,
1610
                        'expectedusers' => [
1619
                        'expectedusers' => [
1611
                            'a',
1620
                            'a',
1612
                            'b',
1621
                            'b',
Línea 1616... Línea 1625...
1616
                        ],
1625
                        ],
1617
                    ],
1626
                    ],
Línea 1618... Línea 1627...
1618
 
1627
 
1619
                    // Tests for jointype: ALL.
1628
                    // Tests for jointype: ALL.
1620
                    'ALL: No filter' => (object) [
1629
                    'ALL: No filter' => (object) [
1621
                       'status' => [],
1630
                       'statuses' => [],
1622
                        'jointype' => filter::JOINTYPE_ALL,
1631
                        'jointype' => filter::JOINTYPE_ALL,
1623
                        'count' => 5,
1632
                        'count' => 5,
1624
                        'expectedusers' => [
1633
                        'expectedusers' => [
1625
                            'a',
1634
                            'a',
Línea 1628... Línea 1637...
1628
                            'd',
1637
                            'd',
1629
                            'e',
1638
                            'e',
1630
                        ],
1639
                        ],
1631
                    ],
1640
                    ],
1632
                    'ALL: Filter on active only' => (object) [
1641
                    'ALL: Filter on active only' => (object) [
1633
                        'status' => [ENROL_USER_ACTIVE],
1642
                        'statuses' => [ENROL_USER_ACTIVE],
1634
                        'jointype' => filter::JOINTYPE_ALL,
1643
                        'jointype' => filter::JOINTYPE_ALL,
1635
                        'count' => 3,
1644
                        'count' => 3,
1636
                        'expectedusers' => [
1645
                        'expectedusers' => [
1637
                            'a',
1646
                            'a',
1638
                            'b',
1647
                            'b',
1639
                            'e',
1648
                            'e',
1640
                        ],
1649
                        ],
1641
                    ],
1650
                    ],
1642
                    'ALL: Filter on suspended only' => (object) [
1651
                    'ALL: Filter on suspended only' => (object) [
1643
                        'status' => [ENROL_USER_SUSPENDED],
1652
                        'statuses' => [ENROL_USER_SUSPENDED],
1644
                        'jointype' => filter::JOINTYPE_ALL,
1653
                        'jointype' => filter::JOINTYPE_ALL,
1645
                        'count' => 3,
1654
                        'count' => 3,
1646
                        'expectedusers' => [
1655
                        'expectedusers' => [
1647
                            'c',
1656
                            'c',
1648
                            'd',
1657
                            'd',
1649
                            'e',
1658
                            'e',
1650
                        ],
1659
                        ],
1651
                    ],
1660
                    ],
1652
                    'ALL: Filter on multiple statuses' => (object) [
1661
                    'ALL: Filter on multiple statuses' => (object) [
1653
                        'status' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1662
                        'statuses' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1654
                        'jointype' => filter::JOINTYPE_ALL,
1663
                        'jointype' => filter::JOINTYPE_ALL,
1655
                        'count' => 1,
1664
                        'count' => 1,
1656
                        'expectedusers' => [
1665
                        'expectedusers' => [
1657
                            'e',
1666
                            'e',
1658
                        ],
1667
                        ],
1659
                    ],
1668
                    ],
Línea 1660... Línea 1669...
1660
 
1669
 
1661
                    // Tests for jointype: NONE.
1670
                    // Tests for jointype: NONE.
1662
                    'NONE: No filter' => (object) [
1671
                    'NONE: No filter' => (object) [
1663
                       'status' => [],
1672
                       'statuses' => [],
1664
                        'jointype' => filter::JOINTYPE_NONE,
1673
                        'jointype' => filter::JOINTYPE_NONE,
1665
                        'count' => 5,
1674
                        'count' => 5,
1666
                        'expectedusers' => [
1675
                        'expectedusers' => [
1667
                            'a',
1676
                            'a',
Línea 1670... Línea 1679...
1670
                            'd',
1679
                            'd',
1671
                            'e',
1680
                            'e',
1672
                        ],
1681
                        ],
1673
                    ],
1682
                    ],
1674
                    'NONE: Filter on active only' => (object) [
1683
                    'NONE: Filter on active only' => (object) [
1675
                        'status' => [ENROL_USER_ACTIVE],
1684
                        'statuses' => [ENROL_USER_ACTIVE],
1676
                        'jointype' => filter::JOINTYPE_NONE,
1685
                        'jointype' => filter::JOINTYPE_NONE,
1677
                        'count' => 3,
1686
                        'count' => 3,
1678
                        'expectedusers' => [
1687
                        'expectedusers' => [
1679
                            'c',
1688
                            'c',
1680
                            'd',
1689
                            'd',
1681
                            'e',
1690
                            'e',
1682
                        ],
1691
                        ],
1683
                    ],
1692
                    ],
1684
                    'NONE: Filter on suspended only' => (object) [
1693
                    'NONE: Filter on suspended only' => (object) [
1685
                        'status' => [ENROL_USER_SUSPENDED],
1694
                        'statuses' => [ENROL_USER_SUSPENDED],
1686
                        'jointype' => filter::JOINTYPE_NONE,
1695
                        'jointype' => filter::JOINTYPE_NONE,
1687
                        'count' => 3,
1696
                        'count' => 3,
1688
                        'expectedusers' => [
1697
                        'expectedusers' => [
1689
                            'a',
1698
                            'a',
1690
                            'b',
1699
                            'b',
1691
                            'e',
1700
                            'e',
1692
                        ],
1701
                        ],
1693
                    ],
1702
                    ],
1694
                    'NONE: Filter on multiple statuses' => (object) [
1703
                    'NONE: Filter on multiple statuses' => (object) [
1695
                        'status' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1704
                        'statuses' => [ENROL_USER_ACTIVE, ENROL_USER_SUSPENDED],
1696
                        'jointype' => filter::JOINTYPE_NONE,
1705
                        'jointype' => filter::JOINTYPE_NONE,
1697
                        'count' => 0,
1706
                        'count' => 0,
1698
                        'expectedusers' => [],
1707
                        'expectedusers' => [],
1699
                    ],
1708
                    ],
1700
                ],
1709
                ],
Línea 1703... Línea 1712...
1703
 
1712
 
1704
        $finaltests = [];
1713
        $finaltests = [];
1705
        foreach ($tests as $testname => $testdata) {
1714
        foreach ($tests as $testname => $testdata) {
1706
            foreach ($testdata->expect as $expectname => $expectdata) {
1715
            foreach ($testdata->expect as $expectname => $expectdata) {
1707
                $finaltests["{$testname} => {$expectname}"] = [
1716
                $finaltests["{$testname} => {$expectname}"] = [
1708
                    'users' => $testdata->users,
1717
                    'usersdata' => $testdata->usersdata,
1709
                    'status' => $expectdata->status,
1718
                    'statuses' => $expectdata->statuses,
1710
                    'jointype' => $expectdata->jointype,
1719
                    'jointype' => $expectdata->jointype,
1711
                    'count' => $expectdata->count,
1720
                    'count' => $expectdata->count,
1712
                    'expectedusers' => $expectdata->expectedusers,
1721
                    'expectedusers' => $expectdata->expectedusers,
1713
                ];
1722
                ];
Línea 1776... Línea 1785...
1776
        // Run the search.
1785
        // Run the search.
1777
        $search = new participants_search($course, $coursecontext, $filterset);
1786
        $search = new participants_search($course, $coursecontext, $filterset);
1778
        $rs = $search->get_participants();
1787
        $rs = $search->get_participants();
1779
        $this->assertInstanceOf(moodle_recordset::class, $rs);
1788
        $this->assertInstanceOf(moodle_recordset::class, $rs);
1780
        $records = $this->convert_recordset_to_array($rs);
1789
        $records = $this->convert_recordset_to_array($rs);
-
 
1790
        $resetrecords = reset($records);
-
 
1791
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 1781... Línea 1792...
1781
 
1792
 
1782
        $this->assertCount($count, $records);
1793
        $this->assertCount($count, $records);
Línea 1783... Línea 1794...
1783
        $this->assertEquals($count, $search->get_total_participants_count());
1794
        $this->assertEquals($count, $totalparticipants);
1784
 
1795
 
1785
        foreach ($expectedusers as $expecteduser) {
1796
        foreach ($expectedusers as $expecteduser) {
1786
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
1797
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 1790... Línea 1801...
1790
    /**
1801
    /**
1791
     * Data provider for enrolments filter tests.
1802
     * Data provider for enrolments filter tests.
1792
     *
1803
     *
1793
     * @return array
1804
     * @return array
1794
     */
1805
     */
1795
    public function enrolments_provider(): array {
1806
    public static function enrolments_provider(): array {
1796
        $tests = [
1807
        $tests = [
1797
            // Users with different enrolment methods.
1808
            // Users with different enrolment methods.
1798
            'Users with different enrolment methods' => (object) [
1809
            'Users with different enrolment methods' => (object) [
1799
                'users' => [
1810
                'usersdata' => [
1800
                    'a' => [
1811
                    'a' => [
1801
                        'enrolmethods' => [
1812
                        'enrolmethods' => [
1802
                            'manual',
1813
                            'manual',
1803
                        ]
1814
                        ]
1804
                    ],
1815
                    ],
Línea 1915... Línea 1926...
1915
 
1926
 
1916
        $finaltests = [];
1927
        $finaltests = [];
1917
        foreach ($tests as $testname => $testdata) {
1928
        foreach ($tests as $testname => $testdata) {
1918
            foreach ($testdata->expect as $expectname => $expectdata) {
1929
            foreach ($testdata->expect as $expectname => $expectdata) {
1919
                $finaltests["{$testname} => {$expectname}"] = [
1930
                $finaltests["{$testname} => {$expectname}"] = [
1920
                    'users' => $testdata->users,
1931
                    'usersdata' => $testdata->usersdata,
1921
                    'enrolmethods' => $expectdata->enrolmethods,
1932
                    'enrolmethods' => $expectdata->enrolmethods,
1922
                    'jointype' => $expectdata->jointype,
1933
                    'jointype' => $expectdata->jointype,
1923
                    'count' => $expectdata->count,
1934
                    'count' => $expectdata->count,
1924
                    'expectedusers' => $expectdata->expectedusers,
1935
                    'expectedusers' => $expectdata->expectedusers,
Línea 2000... Línea 2011...
2000
        // Run the search.
2011
        // Run the search.
2001
        $search = new participants_search($course, $coursecontext, $filterset);
2012
        $search = new participants_search($course, $coursecontext, $filterset);
2002
        $rs = $search->get_participants();
2013
        $rs = $search->get_participants();
2003
        $this->assertInstanceOf(moodle_recordset::class, $rs);
2014
        $this->assertInstanceOf(moodle_recordset::class, $rs);
2004
        $records = $this->convert_recordset_to_array($rs);
2015
        $records = $this->convert_recordset_to_array($rs);
-
 
2016
        $resetrecords = reset($records);
-
 
2017
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 2005... Línea 2018...
2005
 
2018
 
2006
        $this->assertCount($count, $records);
2019
        $this->assertCount($count, $records);
Línea 2007... Línea 2020...
2007
        $this->assertEquals($count, $search->get_total_participants_count());
2020
        $this->assertEquals($count, $totalparticipants);
2008
 
2021
 
2009
        foreach ($expectedusers as $expecteduser) {
2022
        foreach ($expectedusers as $expecteduser) {
2010
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
2023
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 2014... Línea 2027...
2014
    /**
2027
    /**
2015
     * Data provider for groups filter tests.
2028
     * Data provider for groups filter tests.
2016
     *
2029
     *
2017
     * @return array
2030
     * @return array
2018
     */
2031
     */
2019
    public function groups_provider(): array {
2032
    public static function groups_provider(): array {
2020
        $tests = [
2033
        $tests = [
2021
            'Users in different groups' => (object) [
2034
            'Users in different groups' => (object) [
2022
                'groupsavailable' => [
2035
                'groupsavailable' => [
2023
                    'groupa',
2036
                    'groupa',
2024
                    'groupb',
2037
                    'groupb',
2025
                    'groupc',
2038
                    'groupc',
2026
                ],
2039
                ],
2027
                'users' => [
2040
                'usersdata' => [
2028
                    'a' => [
2041
                    'a' => [
2029
                        'groups' => ['groupa'],
2042
                        'groups' => ['groupa'],
2030
                    ],
2043
                    ],
2031
                    'b' => [
2044
                    'b' => [
2032
                        'groups' => ['groupb'],
2045
                        'groups' => ['groupb'],
Línea 2232... Línea 2245...
2232
 
2245
 
2233
        $finaltests = [];
2246
        $finaltests = [];
2234
        foreach ($tests as $testname => $testdata) {
2247
        foreach ($tests as $testname => $testdata) {
2235
            foreach ($testdata->expect as $expectname => $expectdata) {
2248
            foreach ($testdata->expect as $expectname => $expectdata) {
2236
                $finaltests["{$testname} => {$expectname}"] = [
2249
                $finaltests["{$testname} => {$expectname}"] = [
2237
                    'users' => $testdata->users,
2250
                    'usersdata' => $testdata->usersdata,
2238
                    'groupsavailable' => $testdata->groupsavailable,
2251
                    'groupsavailable' => $testdata->groupsavailable,
2239
                    'filtergroups' => $expectdata->groups,
2252
                    'filtergroups' => $expectdata->groups,
2240
                    'jointype' => $expectdata->jointype,
2253
                    'jointype' => $expectdata->jointype,
2241
                    'count' => $expectdata->count,
2254
                    'count' => $expectdata->count,
Línea 2338... Línea 2351...
2338
        } else {
2351
        } else {
2339
            // All other cases are tested as normal.
2352
            // All other cases are tested as normal.
2340
            $rs = $search->get_participants();
2353
            $rs = $search->get_participants();
2341
            $this->assertInstanceOf(moodle_recordset::class, $rs);
2354
            $this->assertInstanceOf(moodle_recordset::class, $rs);
2342
            $records = $this->convert_recordset_to_array($rs);
2355
            $records = $this->convert_recordset_to_array($rs);
-
 
2356
            $resetrecords = reset($records);
-
 
2357
            $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 2343... Línea 2358...
2343
 
2358
 
2344
            $this->assertCount($count, $records);
2359
            $this->assertCount($count, $records);
Línea 2345... Línea 2360...
2345
            $this->assertEquals($count, $search->get_total_participants_count());
2360
            $this->assertEquals($count, $totalparticipants);
2346
 
2361
 
2347
            foreach ($expectedusers as $expecteduser) {
2362
            foreach ($expectedusers as $expecteduser) {
2348
                $this->assertArrayHasKey($users[$expecteduser]->id, $records);
2363
                $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 2353... Línea 2368...
2353
    /**
2368
    /**
2354
     * Data provider for groups filter tests.
2369
     * Data provider for groups filter tests.
2355
     *
2370
     *
2356
     * @return array
2371
     * @return array
2357
     */
2372
     */
2358
    public function groups_separate_provider(): array {
2373
    public static function groups_separate_provider(): array {
2359
        $tests = [
2374
        $tests = [
2360
            'Users in different groups with separate groups mode enabled' => (object) [
2375
            'Users in different groups with separate groups mode enabled' => (object) [
2361
                'groupsavailable' => [
2376
                'groupsavailable' => [
2362
                    'groupa',
2377
                    'groupa',
2363
                    'groupb',
2378
                    'groupb',
2364
                    'groupc',
2379
                    'groupc',
2365
                ],
2380
                ],
2366
                'users' => [
2381
                'usersdata' => [
2367
                    'a' => [
2382
                    'a' => [
2368
                        'groups' => ['groupa'],
2383
                        'groups' => ['groupa'],
2369
                    ],
2384
                    ],
2370
                    'b' => [
2385
                    'b' => [
2371
                        'groups' => ['groupb'],
2386
                        'groups' => ['groupb'],
Línea 2631... Línea 2646...
2631
 
2646
 
2632
        $finaltests = [];
2647
        $finaltests = [];
2633
        foreach ($tests as $testname => $testdata) {
2648
        foreach ($tests as $testname => $testdata) {
2634
            foreach ($testdata->expect as $expectname => $expectdata) {
2649
            foreach ($testdata->expect as $expectname => $expectdata) {
2635
                $finaltests["{$testname} => {$expectname}"] = [
2650
                $finaltests["{$testname} => {$expectname}"] = [
2636
                    'users' => $testdata->users,
2651
                    'usersdata' => $testdata->usersdata,
2637
                    'groupsavailable' => $testdata->groupsavailable,
2652
                    'groupsavailable' => $testdata->groupsavailable,
2638
                    'filtergroups' => $expectdata->groups,
2653
                    'filtergroups' => $expectdata->groups,
2639
                    'jointype' => $expectdata->jointype,
2654
                    'jointype' => $expectdata->jointype,
2640
                    'count' => $expectdata->count,
2655
                    'count' => $expectdata->count,
Línea 2699... Línea 2714...
2699
        // Run the search.
2714
        // Run the search.
2700
        $search = new participants_search($course, $coursecontext, $filterset);
2715
        $search = new participants_search($course, $coursecontext, $filterset);
2701
        $rs = $search->get_participants();
2716
        $rs = $search->get_participants();
2702
        $this->assertInstanceOf(moodle_recordset::class, $rs);
2717
        $this->assertInstanceOf(moodle_recordset::class, $rs);
2703
        $records = $this->convert_recordset_to_array($rs);
2718
        $records = $this->convert_recordset_to_array($rs);
-
 
2719
        $resetrecords = reset($records);
-
 
2720
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 2704... Línea 2721...
2704
 
2721
 
2705
        $this->assertCount($count, $records);
2722
        $this->assertCount($count, $records);
Línea 2706... Línea 2723...
2706
        $this->assertEquals($count, $search->get_total_participants_count());
2723
        $this->assertEquals($count, $totalparticipants);
2707
 
2724
 
2708
        foreach ($expectedusers as $expecteduser) {
2725
        foreach ($expectedusers as $expecteduser) {
2709
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
2726
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 2713... Línea 2730...
2713
    /**
2730
    /**
2714
     * Data provider for last access filter tests.
2731
     * Data provider for last access filter tests.
2715
     *
2732
     *
2716
     * @return array
2733
     * @return array
2717
     */
2734
     */
2718
    public function accesssince_provider(): array {
2735
    public static function accesssince_provider(): array {
2719
        $tests = [
2736
        $tests = [
2720
            // Users with different last access times.
2737
            // Users with different last access times.
2721
            'Users in different groups' => (object) [
2738
            'Users in different groups' => (object) [
2722
                'users' => [
2739
                'usersdata' => [
2723
                    'a' => [
2740
                    'a' => [
2724
                        'lastlogin' => '-3 days',
2741
                        'lastlogin' => '-3 days',
2725
                    ],
2742
                    ],
2726
                    'b' => [
2743
                    'b' => [
2727
                        'lastlogin' => '-2 weeks',
2744
                        'lastlogin' => '-2 weeks',
Línea 2929... Línea 2946...
2929
 
2946
 
2930
        $finaltests = [];
2947
        $finaltests = [];
2931
        foreach ($tests as $testname => $testdata) {
2948
        foreach ($tests as $testname => $testdata) {
2932
            foreach ($testdata->expect as $expectname => $expectdata) {
2949
            foreach ($testdata->expect as $expectname => $expectdata) {
2933
                $finaltests["{$testname} => {$expectname}"] = [
2950
                $finaltests["{$testname} => {$expectname}"] = [
2934
                    'users' => $testdata->users,
2951
                    'usersdata' => $testdata->usersdata,
2935
                    'accesssince' => $expectdata->accesssince,
2952
                    'accesssince' => $expectdata->accesssince,
2936
                    'jointype' => $expectdata->jointype,
2953
                    'jointype' => $expectdata->jointype,
2937
                    'count' => $expectdata->count,
2954
                    'count' => $expectdata->count,
2938
                    'expectedusers' => $expectdata->expectedusers,
2955
                    'expectedusers' => $expectdata->expectedusers,
Línea 3104... Línea 3121...
3104
        // Run the search.
3121
        // Run the search.
3105
        $search = new participants_search($course, $coursecontext, $filterset);
3122
        $search = new participants_search($course, $coursecontext, $filterset);
3106
        $rs = $search->get_participants();
3123
        $rs = $search->get_participants();
3107
        $this->assertInstanceOf(moodle_recordset::class, $rs);
3124
        $this->assertInstanceOf(moodle_recordset::class, $rs);
3108
        $records = $this->convert_recordset_to_array($rs);
3125
        $records = $this->convert_recordset_to_array($rs);
-
 
3126
        $resetrecords = reset($records);
-
 
3127
        $totalparticipants = $resetrecords->fullcount ?? 0;
Línea 3109... Línea 3128...
3109
 
3128
 
3110
        $this->assertCount($count, $records);
3129
        $this->assertCount($count, $records);
Línea 3111... Línea 3130...
3111
        $this->assertEquals($count, $search->get_total_participants_count());
3130
        $this->assertEquals($count, $totalparticipants);
3112
 
3131
 
3113
        foreach ($expectedusers as $expecteduser) {
3132
        foreach ($expectedusers as $expecteduser) {
3114
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
3133
            $this->assertArrayHasKey($users[$expecteduser]->id, $records);
Línea 3118... Línea 3137...
3118
    /**
3137
    /**
3119
     * Data provider for filterset join tests.
3138
     * Data provider for filterset join tests.
3120
     *
3139
     *
3121
     * @return array
3140
     * @return array
3122
     */
3141
     */
3123
    public function filterset_joins_provider(): array {
3142
    public static function filterset_joins_provider(): array {
3124
        $tests = [
3143
        $tests = [
3125
            // Users with different configurations.
3144
            // Users with different configurations.
3126
            'Users with different configurations' => (object) [
3145
            'Users with different configurations' => (object) [
3127
                'groupsavailable' => [
3146
                'groupsavailable' => [
3128
                    'groupa',
3147
                    'groupa',
3129
                    'groupb',
3148
                    'groupb',
3130
                    'groupc',
3149
                    'groupc',
3131
                ],
3150
                ],
3132
                'users' => [
3151
                'usersdata' => [
3133
                    'adam.ant' => [
3152
                    'adam.ant' => [
3134
                        'firstname' => 'Adam',
3153
                        'firstname' => 'Adam',
3135
                        'lastname' => 'Ant',
3154
                        'lastname' => 'Ant',
3136
                        'enrolments' => [
3155
                        'enrolments' => [
3137
                            [
3156
                            [
Línea 3477... Línea 3496...
3477
 
3496
 
3478
        $finaltests = [];
3497
        $finaltests = [];
3479
        foreach ($tests as $testname => $testdata) {
3498
        foreach ($tests as $testname => $testdata) {
3480
            foreach ($testdata->expect as $expectname => $expectdata) {
3499
            foreach ($testdata->expect as $expectname => $expectdata) {
3481
                $finaltests["{$testname} => {$expectname}"] = [
3500
                $finaltests["{$testname} => {$expectname}"] = [
3482
                    'users' => $testdata->users,
3501
                    'usersdata' => $testdata->usersdata,
3483
                    'filterdata' => $expectdata->filterdata,
3502
                    'filterdata' => $expectdata->filterdata,
3484
                    'groupsavailable' => $testdata->groupsavailable,
3503
                    'groupsavailable' => $testdata->groupsavailable,
3485
                    'jointype' => $expectdata->jointype,
3504
                    'jointype' => $expectdata->jointype,
3486
                    'count' => $expectdata->count,
3505
                    'count' => $expectdata->count,
Línea 3489... Línea 3508...
3489
            }
3508
            }
3490
        }
3509
        }
Línea 3491... Línea 3510...
3491
 
3510
 
3492
        return $finaltests;
3511
        return $finaltests;
-
 
3512
    }
-
 
3513
 
-
 
3514
    /**
-
 
3515
     * Tests sorting of participants in a course.
-
 
3516
     *
-
 
3517
     * This test runs a search for participants twice, first with an "ORDER BY" clause and second without.
-
 
3518
     * The test asserts the correct ordering of participants based on the sorting condition.
-
 
3519
     */
-
 
3520
    public function test_sort_participants(): void {
-
 
3521
        $this->resetAfterTest();
-
 
3522
 
-
 
3523
        $course = $this->getDataGenerator()->create_course();
-
 
3524
        $coursecontext = context_course::instance($course->id);
-
 
3525
 
-
 
3526
        // Generate users with their role.
-
 
3527
        $this->getDataGenerator()->create_and_enrol($course, 'teacher');
-
 
3528
        $this->getDataGenerator()->create_and_enrol($course, 'student');
-
 
3529
 
-
 
3530
        // Create the basic filter.
-
 
3531
        $filterset = new participants_filterset();
-
 
3532
        $filterset->add_filter(new integer_filter('courseid', null, [(int) $course->id]));
-
 
3533
 
-
 
3534
        // Run the search with using ORDER BY.
-
 
3535
        $search = new participants_search($course, $coursecontext, $filterset);
-
 
3536
        $rs = $search->get_participants(
-
 
3537
            sort: 'ORDER     BY id', // Adding spaces between "ORDER" and "BY" is intentional.
-
 
3538
        );
-
 
3539
        $records = $this->convert_recordset_to_array($rs);
-
 
3540
        $userids = array_keys($records);
-
 
3541
        $this->assertGreaterThan($userids[0], $userids[1]);
-
 
3542
 
-
 
3543
        // Run the search without using ORDER BY.
-
 
3544
        $rs = $search->get_participants(
-
 
3545
            sort: 'id DESC',
-
 
3546
        );
-
 
3547
        $records = $this->convert_recordset_to_array($rs);
-
 
3548
        $userids = array_keys($records);
-
 
3549
        $this->assertGreaterThan($userids[1], $userids[0]);
-
 
3550
 
-
 
3551
        $rs->close();
3493
    }
3552
    }