Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 31... Línea 31...
31
 * @package enrol_lti
31
 * @package enrol_lti
32
 * @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
32
 * @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 * @coversDefaultClass \enrol_lti\local\ltiadvantage\task\sync_members
34
 * @coversDefaultClass \enrol_lti\local\ltiadvantage\task\sync_members
35
 */
35
 */
36
class sync_members_test extends \lti_advantage_testcase {
36
final class sync_members_test extends \lti_advantage_testcase {
Línea 37... Línea 37...
37
 
37
 
38
    /**
38
    /**
39
     * Verify the user's profile picture has been set, which is useful to verify picture syncs.
39
     * Verify the user's profile picture has been set, which is useful to verify picture syncs.
40
     *
40
     *
Línea 71... Línea 71...
71
     * @param bool $picture whether to mock a user's picture field in the return data.
71
     * @param bool $picture whether to mock a user's picture field in the return data.
72
     * @param array $roles an array of IMS roles to include with each member which, if empty, defaults to just the learner role.
72
     * @param array $roles an array of IMS roles to include with each member which, if empty, defaults to just the learner role.
73
     * @return array the array of users.
73
     * @return array the array of users.
74
     * @throws \Exception if the legacyuserids array doesn't contain the correct number of ids.
74
     * @throws \Exception if the legacyuserids array doesn't contain the correct number of ids.
75
     */
75
     */
76
    protected function get_mock_members_with_ids(array $userids, ?array $legacyuserids = null, $names = true,
76
    protected static function get_mock_members_with_ids(
-
 
77
        array $userids,
-
 
78
        ?array $legacyuserids = null,
-
 
79
        $names = true,
-
 
80
        $emails = true,
77
            $emails = true, bool $linklevel = true, bool $picture = false, array $roles = []): array {
81
        bool $linklevel = true,
-
 
82
        bool $picture = false,
-
 
83
        array $roles = [],
-
 
84
    ): array {
Línea 78... Línea 85...
78
 
85
 
79
        if (!is_null($legacyuserids) && count($legacyuserids) != count($userids)) {
86
        if (!is_null($legacyuserids) && count($legacyuserids) != count($userids)) {
80
            throw new \Exception('legacyuserids must contain the same number of ids as $userids.');
87
            throw new \Exception('legacyuserids must contain the same number of ids as $userids.');
Línea 86... Línea 93...
86
 
93
 
87
        $users = [];
94
        $users = [];
88
        foreach ($userids as $userid) {
95
        foreach ($userids as $userid) {
89
            $user = ['user_id' => (string) $userid, 'roles' => $roles];
96
            $user = ['user_id' => (string) $userid, 'roles' => $roles];
90
            if ($picture) {
97
            if ($picture) {
91
                $user['picture'] = $this->getExternalTestFileUrl('/test.jpg', false);
98
                $user['picture'] = static::getExternalTestFileUrl('/test.jpg', false);
92
            }
99
            }
93
            if ($names) {
100
            if ($names) {
94
                $user['given_name'] = 'Firstname' . $userid;
101
                $user['given_name'] = 'Firstname' . $userid;
95
                $user['family_name'] = 'Surname' . $userid;
102
                $user['family_name'] = 'Surname' . $userid;
Línea 135... Línea 142...
135
                        if ($reslink->get_resourcelinkid() === $rl[0]->get_resourcelinkid()) {
142
                        if ($reslink->get_resourcelinkid() === $rl[0]->get_resourcelinkid()) {
136
                            return $rl[1];
143
                            return $rl[1];
137
                        }
144
                        }
138
                    }
145
                    }
139
                } else {
146
                } else {
140
                    return $this->get_mock_members_with_ids(range(1, 2));
147
                    return self::get_mock_members_with_ids(range(1, 2));
141
                }
148
                }
142
            }));
149
            }));
143
        return $mocktask;
150
        return $mocktask;
144
    }
151
    }
Línea 159... Línea 166...
159
                throw new \Exception();
166
                throw new \Exception();
160
            }));
167
            }));
161
        $mocktask->expects($this->any())
168
        $mocktask->expects($this->any())
162
            ->method('get_context_level_members')
169
            ->method('get_context_level_members')
163
            ->will($this->returnCallback(function() {
170
            ->will($this->returnCallback(function() {
164
                return $this->get_mock_members_with_ids(range(1, 3), null, true, true, false);
171
                return self::get_mock_members_with_ids(range(1, 3), null, true, true, false);
165
            }));;
172
            }));;
166
        return $mocktask;
173
        return $mocktask;
167
    }
174
    }
Línea 168... Línea 175...
168
 
175
 
Línea 227... Línea 234...
227
    public function test_resource_link_level_sync(): void {
234
    public function test_resource_link_level_sync(): void {
228
        $this->resetAfterTest();
235
        $this->resetAfterTest();
229
        [$course, $resource] = $this->create_test_environment();
236
        [$course, $resource] = $this->create_test_environment();
Línea 230... Línea 237...
230
 
237
 
231
        // Launch the tool for a user.
238
        // Launch the tool for a user.
232
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0]);
239
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0]);
233
        $instructoruser = $this->lti_advantage_user_authenticates('1');
240
        $instructoruser = $this->lti_advantage_user_authenticates('1');
234
        $launchservice = $this->get_tool_launch_service();
241
        $launchservice = $this->get_tool_launch_service();
Línea 235... Línea 242...
235
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
242
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 259... Línea 266...
259
        [$course, $resource] = $this->create_test_environment();
266
        [$course, $resource] = $this->create_test_environment();
Línea 260... Línea 267...
260
 
267
 
261
        // Launch twice - once from each resource link in the platform.
268
        // Launch twice - once from each resource link in the platform.
262
        $launchservice = $this->get_tool_launch_service();
269
        $launchservice = $this->get_tool_launch_service();
263
        $instructoruser = $this->lti_advantage_user_authenticates('1');
270
        $instructoruser = $this->lti_advantage_user_authenticates('1');
264
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0], '123');
271
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0], '123');
265
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
272
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
266
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0], '456');
273
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0], '456');
Línea 267... Línea 274...
267
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
274
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
268
 
275
 
269
        // Now, grab the resource links.
276
        // Now, grab the resource links.
270
        $rlrepo = new resource_link_repository();
277
        $rlrepo = new resource_link_repository();
271
        $reslinks = $rlrepo->find_by_resource($resource->id);
278
        $reslinks = $rlrepo->find_by_resource($resource->id);
272
        $mockmembers = $this->get_mock_members_with_ids(range(1, 10));
279
        $mockmembers = self::get_mock_members_with_ids(range(1, 10));
273
        $mockusers1 = array_slice($mockmembers, 0, 6);
280
        $mockusers1 = array_slice($mockmembers, 0, 6);
274
        $mockusers2 = array_slice($mockmembers, 6);
281
        $mockusers2 = array_slice($mockmembers, 6);
275
        $resourcelinks = [
282
        $resourcelinks = [
Línea 303... Línea 310...
303
    public function test_user_profile_image_sync(): void {
310
    public function test_user_profile_image_sync(): void {
304
        $this->resetAfterTest();
311
        $this->resetAfterTest();
305
        [$course, $resource] = $this->create_test_environment();
312
        [$course, $resource] = $this->create_test_environment();
Línea 306... Línea 313...
306
 
313
 
307
        // Launch the tool for a user.
314
        // Launch the tool for a user.
308
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0]);
315
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0]);
309
        $launchservice = $this->get_tool_launch_service();
316
        $launchservice = $this->get_tool_launch_service();
310
        $instructoruser = $this->lti_advantage_user_authenticates('1');
317
        $instructoruser = $this->lti_advantage_user_authenticates('1');
Línea 311... Línea 318...
311
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
318
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
312
 
319
 
313
        // Sync members.
320
        // Sync members.
314
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(['1'], null, true, true, true, true));
321
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(['1'], null, true, true, true, true));
315
        ob_start();
322
        ob_start();
Línea 316... Línea 323...
316
        $task->execute();
323
        $task->execute();
Línea 334... Línea 341...
334
    public function test_context_level_sync(): void {
341
    public function test_context_level_sync(): void {
335
        $this->resetAfterTest();
342
        $this->resetAfterTest();
336
        [$course, $resource] = $this->create_test_environment();
343
        [$course, $resource] = $this->create_test_environment();
Línea 337... Línea 344...
337
 
344
 
338
        // Launch the tool for a user.
345
        // Launch the tool for a user.
339
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0]);
346
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0]);
340
        $launchservice = $this->get_tool_launch_service();
347
        $launchservice = $this->get_tool_launch_service();
341
        $instructoruser = $this->lti_advantage_user_authenticates('1');
348
        $instructoruser = $this->lti_advantage_user_authenticates('1');
Línea 342... Línea 349...
342
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
349
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 363... Línea 370...
363
        $this->resetAfterTest();
370
        $this->resetAfterTest();
364
        [$course, $resource, $resource2, $resource3, $appreg] = $this->create_test_environment();
371
        [$course, $resource, $resource2, $resource3, $appreg] = $this->create_test_environment();
365
        $userrepo = new user_repository();
372
        $userrepo = new user_repository();
Línea 366... Línea 373...
366
 
373
 
367
        // Launch the tool for a user.
374
        // Launch the tool for a user.
368
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'])[0]);
375
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids(['1'])[0]);
369
        $launchservice = $this->get_tool_launch_service();
376
        $launchservice = $this->get_tool_launch_service();
370
        $instructoruser = $this->lti_advantage_user_authenticates('1');
377
        $instructoruser = $this->lti_advantage_user_authenticates('1');
Línea 371... Línea 378...
371
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
378
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
372
 
379
 
Línea 373... Línea 380...
373
        // Sync members.
380
        // Sync members.
374
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(1, 5), null, false, false));
381
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(1, 5), null, false, false));
375
 
382
 
Línea 396... Línea 403...
396
            $issuersubhash = sha1($appreg->get_platformid() . '_' . $ltiuser->get_sourceid());
403
            $issuersubhash = sha1($appreg->get_platformid() . '_' . $ltiuser->get_sourceid());
397
            $this->assertEquals("enrol_lti_13_{$issuersubhash}@example.com", $user->email);
404
            $this->assertEquals("enrol_lti_13_{$issuersubhash}@example.com", $user->email);
398
        }
405
        }
Línea 399... Línea 406...
399
 
406
 
400
        // Sync again, this time with user data included.
407
        // Sync again, this time with user data included.
401
        $mockmembers = $this->get_mock_members_with_ids(range(1, 5));
408
        $mockmembers = self::get_mock_members_with_ids(range(1, 5));
Línea 402... Línea 409...
402
        $task = $this->get_mock_task_with_users($mockmembers);
409
        $task = $this->get_mock_task_with_users($mockmembers);
403
 
410
 
404
        ob_start();
411
        ob_start();
Línea 427... Línea 434...
427
    public function test_membership_sync_disabled(): void {
434
    public function test_membership_sync_disabled(): void {
428
        $this->resetAfterTest();
435
        $this->resetAfterTest();
429
        [$course, $resource] = $this->create_test_environment(true, true, false);
436
        [$course, $resource] = $this->create_test_environment(true, true, false);
Línea 430... Línea 437...
430
 
437
 
431
        // Launch the tool for a user.
438
        // Launch the tool for a user.
432
        $mockuser = $this->get_mock_launch_users_with_ids(['1'])[0];
439
        $mockuser = self::get_mock_launch_users_with_ids(['1'])[0];
433
        $mocklaunch = $this->get_mock_launch($resource, $mockuser);
440
        $mocklaunch = $this->get_mock_launch($resource, $mockuser);
434
        $launchservice = $this->get_tool_launch_service();
441
        $launchservice = $this->get_tool_launch_service();
435
        $instructoruser = $this->lti_advantage_user_authenticates('1');
442
        $instructoruser = $this->lti_advantage_user_authenticates('1');
Línea 436... Línea 443...
436
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
443
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
437
 
444
 
438
        // Sync members.
445
        // Sync members.
439
        $task = $this->get_mock_task_with_users($this->get_mock_launch_users_with_ids(range(1, 4)));
446
        $task = $this->get_mock_task_with_users(self::get_mock_launch_users_with_ids(range(1, 4)));
440
        ob_start();
447
        ob_start();
Línea 441... Línea 448...
441
        $task->execute();
448
        $task->execute();
Línea 459... Línea 466...
459
        $this->resetAfterTest();
466
        $this->resetAfterTest();
460
        [$course, $resource] = $this->create_test_environment();
467
        [$course, $resource] = $this->create_test_environment();
461
        $userrepo = new user_repository();
468
        $userrepo = new user_repository();
Línea 462... Línea 469...
462
 
469
 
463
        // Launch the tool for a user.
470
        // Launch the tool for a user.
464
        $mockuser = $this->get_mock_launch_users_with_ids(['1'])[0];
471
        $mockuser = self::get_mock_launch_users_with_ids(['1'])[0];
465
        $mocklaunch = $this->get_mock_launch($resource, $mockuser);
472
        $mocklaunch = $this->get_mock_launch($resource, $mockuser);
466
        $launchservice = $this->get_tool_launch_service();
473
        $launchservice = $this->get_tool_launch_service();
467
        $instructoruser = $this->lti_advantage_user_authenticates('1');
474
        $instructoruser = $this->lti_advantage_user_authenticates('1');
Línea 468... Línea 475...
468
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
475
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
469
 
476
 
Línea 470... Línea 477...
470
        // Sync members.
477
        // Sync members.
471
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(1, 3)));
478
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(1, 3)));
472
 
479
 
Línea 479... Línea 486...
479
        $this->assertCount(3, $ltiusers);
486
        $this->assertCount(3, $ltiusers);
480
        $this->verify_course_enrolments($course, $ltiusers);
487
        $this->verify_course_enrolments($course, $ltiusers);
Línea 481... Línea 488...
481
 
488
 
482
        // Now, simulate a subsequent sync in which 1 existing user maintains access,
489
        // Now, simulate a subsequent sync in which 1 existing user maintains access,
483
        // 2 existing users are unenrolled and 3 new users are enrolled.
490
        // 2 existing users are unenrolled and 3 new users are enrolled.
484
        $task2 = $this->get_mock_task_with_users($this->get_mock_members_with_ids(['1', '4', '5', '6']));
491
        $task2 = $this->get_mock_task_with_users(self::get_mock_members_with_ids(['1', '4', '5', '6']));
485
        ob_start();
492
        ob_start();
486
        $task2->execute();
493
        $task2->execute();
Línea 487... Línea 494...
487
        ob_end_clean();
494
        ob_end_clean();
Línea 507... Línea 514...
507
        $this->resetAfterTest();
514
        $this->resetAfterTest();
508
        [$course, $resource] = $this->create_test_environment(true, true, true, helper::MEMBER_SYNC_UNENROL_MISSING);
515
        [$course, $resource] = $this->create_test_environment(true, true, true, helper::MEMBER_SYNC_UNENROL_MISSING);
509
        $userrepo = new user_repository();
516
        $userrepo = new user_repository();
Línea 510... Línea 517...
510
 
517
 
511
        // Launch the tool for a user.
518
        // Launch the tool for a user.
512
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids([1])[0]);
519
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids([1])[0]);
513
        $launchservice = $this->get_tool_launch_service();
520
        $launchservice = $this->get_tool_launch_service();
514
        $instructoruser = $this->lti_advantage_user_authenticates('1');
521
        $instructoruser = $this->lti_advantage_user_authenticates('1');
515
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
522
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 516... Línea 523...
516
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
523
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
517
 
524
 
Línea 518... Línea 525...
518
        // Sync members using a payload which doesn't include the original launch user (User id = 1).
525
        // Sync members using a payload which doesn't include the original launch user (User id = 1).
519
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(2, 3)));
526
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(2, 3)));
520
 
527
 
Línea 536... Línea 543...
536
        $this->resetAfterTest();
543
        $this->resetAfterTest();
537
        [$course, $resource] = $this->create_test_environment(true, true, true, helper::MEMBER_SYNC_ENROL_NEW);
544
        [$course, $resource] = $this->create_test_environment(true, true, true, helper::MEMBER_SYNC_ENROL_NEW);
538
        $userrepo = new user_repository();
545
        $userrepo = new user_repository();
Línea 539... Línea 546...
539
 
546
 
540
        // Launch the tool for a user.
547
        // Launch the tool for a user.
541
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids([1])[0]);
548
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids([1])[0]);
542
        $launchservice = $this->get_tool_launch_service();
549
        $launchservice = $this->get_tool_launch_service();
543
        $instructoruser = $this->lti_advantage_user_authenticates('1');
550
        $instructoruser = $this->lti_advantage_user_authenticates('1');
544
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
551
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 545... Línea 552...
545
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
552
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
546
 
553
 
Línea 547... Línea 554...
547
        // Sync members using a payload which includes two new members only (i.e. not the original launching user).
554
        // Sync members using a payload which includes two new members only (i.e. not the original launching user).
548
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(2, 3)));
555
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(2, 3)));
549
 
556
 
Línea 566... Línea 573...
566
        $this->resetAfterTest();
573
        $this->resetAfterTest();
567
        [$course, $resource] = $this->create_test_environment(false);
574
        [$course, $resource] = $this->create_test_environment(false);
568
        $userrepo = new user_repository();
575
        $userrepo = new user_repository();
Línea 569... Línea 576...
569
 
576
 
570
        // Launch the tool for a user.
577
        // Launch the tool for a user.
571
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids([1])[0]);
578
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids([1])[0]);
572
        $launchservice = $this->get_tool_launch_service();
579
        $launchservice = $this->get_tool_launch_service();
573
        $instructoruser = $this->lti_advantage_user_authenticates('1');
580
        $instructoruser = $this->lti_advantage_user_authenticates('1');
574
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
581
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 575... Línea 582...
575
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
582
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
576
 
583
 
577
        // If the task were to run, this would trigger 1 unenrolment (the launching user) and 3 enrolments.
584
        // If the task were to run, this would trigger 1 unenrolment (the launching user) and 3 enrolments.
Línea 578... Línea 585...
578
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(2, 2)));
585
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(2, 2)));
579
        $task->execute();
586
        $task->execute();
580
 
587
 
Línea 592... Línea 599...
592
        $this->resetAfterTest();
599
        $this->resetAfterTest();
593
        [$course, $resource] = $this->create_test_environment(true, false);
600
        [$course, $resource] = $this->create_test_environment(true, false);
594
        $userrepo = new user_repository();
601
        $userrepo = new user_repository();
Línea 595... Línea 602...
595
 
602
 
596
        // Launch the tool for a user.
603
        // Launch the tool for a user.
597
        $mocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids([1])[0]);
604
        $mocklaunch = $this->get_mock_launch($resource, self::get_mock_launch_users_with_ids([1])[0]);
598
        $launchservice = $this->get_tool_launch_service();
605
        $launchservice = $this->get_tool_launch_service();
599
        $instructoruser = $this->lti_advantage_user_authenticates('1');
606
        $instructoruser = $this->lti_advantage_user_authenticates('1');
600
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
607
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 601... Línea 608...
601
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
608
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
602
 
609
 
603
        // If the task were to run, this would trigger 1 unenrolment of the launching user and enrolment of 3 users.
610
        // If the task were to run, this would trigger 1 unenrolment of the launching user and enrolment of 3 users.
Línea 604... Línea 611...
604
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(2, 2)));
611
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(2, 2)));
605
        $task->execute();
612
        $task->execute();
606
 
613
 
Línea 628... Línea 635...
628
        // Delete the activity being shared by resource2, leaving resource 2 disabled as a result.
635
        // Delete the activity being shared by resource2, leaving resource 2 disabled as a result.
629
        $modcontext = \context::instance_by_id($resource2->contextid);
636
        $modcontext = \context::instance_by_id($resource2->contextid);
630
        course_delete_module($modcontext->instanceid);
637
        course_delete_module($modcontext->instanceid);
Línea 631... Línea 638...
631
 
638
 
632
        // Only the enabled resource 3 should sync members.
639
        // Only the enabled resource 3 should sync members.
633
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(1, 1)));
640
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(1, 1)));
Línea 634... Línea 641...
634
        $task->execute();
641
        $task->execute();
635
 
642
 
636
        $this->expectOutputRegex(
643
        $this->expectOutputRegex(
Línea 650... Línea 657...
650
        $this->resetAfterTest();
657
        $this->resetAfterTest();
651
        [$course, $resource] = $this->create_test_environment();
658
        [$course, $resource] = $this->create_test_environment();
652
        $userrepo = new user_repository();
659
        $userrepo = new user_repository();
Línea 653... Línea 660...
653
 
660
 
654
        // Launch the tool for a user.
661
        // Launch the tool for a user.
655
        $mockinstructor = $this->get_mock_launch_users_with_ids([1])[0];
662
        $mockinstructor = self::get_mock_launch_users_with_ids([1])[0];
656
        $mocklaunch = $this->get_mock_launch($resource, $mockinstructor, null, null, false);
663
        $mocklaunch = $this->get_mock_launch($resource, $mockinstructor, null, null, false);
657
        $launchservice = $this->get_tool_launch_service();
664
        $launchservice = $this->get_tool_launch_service();
658
        $instructoruser = $this->lti_advantage_user_authenticates('1');
665
        $instructoruser = $this->lti_advantage_user_authenticates('1');
659
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
666
        $launchservice->user_launches_tool($instructoruser, $mocklaunch);
Línea 660... Línea 667...
660
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
667
        $this->assertCount(1, $userrepo->find_by_resource($resource->id));
661
 
668
 
Línea 662... Línea 669...
662
        // The task would sync an additional 2 users if the link had NRPS service support.
669
        // The task would sync an additional 2 users if the link had NRPS service support.
663
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(2, 2)));
670
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(range(2, 2)));
Línea 664... Línea 671...
664
 
671
 
Línea 691... Línea 698...
691
        $authenticateduser->password = '1234abcD*';
698
        $authenticateduser->password = '1234abcD*';
692
        user_update_user($authenticateduser);
699
        user_update_user($authenticateduser);
693
        $authenticateduser = \core_user::get_user($authenticateduser->id);
700
        $authenticateduser = \core_user::get_user($authenticateduser->id);
Línea 694... Línea 701...
694
 
701
 
695
        // Mock the launch for the specified user.
702
        // Mock the launch for the specified user.
696
        $mocklaunchuser = $this->get_mock_launch_users_with_ids([$authenticateduser->id])[0];
703
        $mocklaunchuser = self::get_mock_launch_users_with_ids([$authenticateduser->id])[0];
697
        $mocklaunch = $this->get_mock_launch($resource, $mocklaunchuser);
704
        $mocklaunch = $this->get_mock_launch($resource, $mocklaunchuser);
Línea 698... Línea 705...
698
        $this->get_tool_launch_service()->user_launches_tool($authenticateduser, $mocklaunch);
705
        $this->get_tool_launch_service()->user_launches_tool($authenticateduser, $mocklaunch);
699
 
706
 
Línea 700... Línea 707...
700
        // Prepare the sync task, with a stubbed list of members.
707
        // Prepare the sync task, with a stubbed list of members.
701
        $task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(['123'], null, true, true, true, true));
708
        $task = $this->get_mock_task_with_users(self::get_mock_members_with_ids(['123'], null, true, true, true, true));
702
 
709
 
703
        // Run the member sync.
710
        // Run the member sync.
Línea 786... Línea 793...
786
    /**
793
    /**
787
     * Data provider for member syncs.
794
     * Data provider for member syncs.
788
     *
795
     *
789
     * @return array[] the array of test data.
796
     * @return array[] the array of test data.
790
     */
797
     */
791
    public function member_sync_data_provider(): array {
798
    public static function member_sync_data_provider(): array {
792
        global $CFG;
799
        global $CFG;
793
        require_once($CFG->dirroot . '/auth/lti/auth.php');
800
        require_once($CFG->dirroot . '/auth/lti/auth.php');
794
        return [
801
        return [
795
            'Migrated tool, user ids changed, new and existing users present in sync' => [
802
            'Migrated tool, user ids changed, new and existing users present in sync' => [
796
                'legacy_data' => [
803
                'legacydata' => [
797
                    'users' => [
804
                    'users' => [
798
                        ['user_id' => '1'],
805
                        ['user_id' => '1'],
799
                        ['user_id' => '2'],
806
                        ['user_id' => '2'],
800
                    ],
807
                    ],
801
                    'consumer_key' => 'CONSUMER_1',
808
                    'consumer_key' => 'CONSUMER_1',
802
                    'tools' => [
809
                    'tools' => [
803
                        ['secret' => 'toolsecret1'],
810
                        ['secret' => 'toolsecret1'],
804
                        ['secret' => 'toolsecret2'],
811
                        ['secret' => 'toolsecret2'],
805
                    ]
812
                    ]
806
                ],
813
                ],
807
                'resource_config' => null,
814
                'resourceconfig' => null,
808
                'launch_data' => [
815
                'launchdata' => [
809
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
816
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
810
                    'launch_migration_claim' => [
817
                    'launch_migration_claim' => [
811
                        'consumer_key' => 'CONSUMER_1',
818
                        'consumer_key' => 'CONSUMER_1',
812
                        'signing_secret' => 'toolsecret1',
819
                        'signing_secret' => 'toolsecret1',
813
                        'user_id' => '1',
820
                        'user_id' => '1',
814
                        'context_id' => 'd345b',
821
                        'context_id' => 'd345b',
815
                        'tool_consumer_instance_guid' => '12345-123',
822
                        'tool_consumer_instance_guid' => '12345-123',
816
                        'resource_link_id' => '4b6fa'
823
                        'resource_link_id' => '4b6fa'
817
                    ],
824
                    ],
818
                ],
825
                ],
819
                'sync_members_data' => [
826
                'syncmembers' => [
820
                    $this->get_mock_members_with_ids(['1p3_1'], ['1'])[0],
827
                    self::get_mock_members_with_ids(['1p3_1'], ['1'])[0],
821
                    $this->get_mock_members_with_ids(['1p3_2'], ['2'])[0],
828
                    self::get_mock_members_with_ids(['1p3_2'], ['2'])[0],
822
                    $this->get_mock_members_with_ids(['1p3_3'], ['3'])[0],
829
                    self::get_mock_members_with_ids(['1p3_3'], ['3'])[0],
823
                    $this->get_mock_members_with_ids(['1p3_4'], ['4'])[0],
830
                    self::get_mock_members_with_ids(['1p3_4'], ['4'])[0],
824
                ],
831
                ],
825
                'expected' => [
832
                'expected' => [
826
                    'enrolments' => [
833
                    'enrolments' => [
827
                        '1p3_1' => [
834
                        '1p3_1' => [
828
                            'is_enrolled' => true,
835
                            'is_enrolled' => true,
Línea 842... Línea 849...
842
                        ]
849
                        ]
843
                    ]
850
                    ]
844
                ]
851
                ]
845
            ],
852
            ],
846
            'Migrated tool, no change in user ids, new and existing users present in sync' => [
853
            'Migrated tool, no change in user ids, new and existing users present in sync' => [
847
                'legacy_data' => [
854
                'legacydata' => [
848
                    'users' => [
855
                    'users' => [
849
                        ['user_id' => '1'],
856
                        ['user_id' => '1'],
850
                        ['user_id' => '2'],
857
                        ['user_id' => '2'],
851
                    ],
858
                    ],
852
                    'consumer_key' => 'CONSUMER_1',
859
                    'consumer_key' => 'CONSUMER_1',
853
                    'tools' => [
860
                    'tools' => [
854
                        ['secret' => 'toolsecret1'],
861
                        ['secret' => 'toolsecret1'],
855
                        ['secret' => 'toolsecret2'],
862
                        ['secret' => 'toolsecret2'],
856
                    ]
863
                    ]
857
                ],
864
                ],
858
                'resource_config' => null,
865
                'resourceconfig' => null,
859
                'launch_data' => [
866
                'launchdata' => [
860
                    'user' => $this->get_mock_launch_users_with_ids(['1'])[0],
867
                    'user' => self::get_mock_launch_users_with_ids(['1'])[0],
861
                    'launch_migration_claim' => [
868
                    'launch_migration_claim' => [
862
                        'consumer_key' => 'CONSUMER_1',
869
                        'consumer_key' => 'CONSUMER_1',
863
                        'signing_secret' => 'toolsecret1',
870
                        'signing_secret' => 'toolsecret1',
864
                        'context_id' => 'd345b',
871
                        'context_id' => 'd345b',
865
                        'tool_consumer_instance_guid' => '12345-123',
872
                        'tool_consumer_instance_guid' => '12345-123',
866
                        'resource_link_id' => '4b6fa'
873
                        'resource_link_id' => '4b6fa'
867
                    ],
874
                    ],
868
                ],
875
                ],
869
                'sync_members_data' => [
876
                'syncmembers' => [
870
                    $this->get_mock_members_with_ids(['1'], null)[0],
877
                    self::get_mock_members_with_ids(['1'], null)[0],
871
                    $this->get_mock_members_with_ids(['2'], null)[0],
878
                    self::get_mock_members_with_ids(['2'], null)[0],
872
                    $this->get_mock_members_with_ids(['3'], null)[0],
879
                    self::get_mock_members_with_ids(['3'], null)[0],
873
                    $this->get_mock_members_with_ids(['4'], null)[0],
880
                    self::get_mock_members_with_ids(['4'], null)[0],
874
                ],
881
                ],
875
                'expected' => [
882
                'expected' => [
876
                    'enrolments' => [
883
                    'enrolments' => [
877
                        '1' => [
884
                        '1' => [
878
                            'is_enrolled' => true,
885
                            'is_enrolled' => true,
Línea 892... Línea 899...
892
                        ]
899
                        ]
893
                    ]
900
                    ]
894
                ]
901
                ]
895
            ],
902
            ],
896
            'New tool, no launch migration claim, change in user ids, new and existing users present in sync' => [
903
            'New tool, no launch migration claim, change in user ids, new and existing users present in sync' => [
897
                'legacy_data' => [
904
                'legacydata' => [
898
                    'users' => [
905
                    'users' => [
899
                        ['user_id' => '1'],
906
                        ['user_id' => '1'],
900
                        ['user_id' => '2'],
907
                        ['user_id' => '2'],
901
                    ],
908
                    ],
902
                    'consumer_key' => 'CONSUMER_1',
909
                    'consumer_key' => 'CONSUMER_1',
903
                    'tools' => [
910
                    'tools' => [
904
                        ['secret' => 'toolsecret1'],
911
                        ['secret' => 'toolsecret1'],
905
                        ['secret' => 'toolsecret2'],
912
                        ['secret' => 'toolsecret2'],
906
                    ]
913
                    ]
907
                ],
914
                ],
908
                'resource_config' => null,
915
                'resourceconfig' => null,
909
                'launch_data' => [
916
                'launchdata' => [
910
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
917
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
911
                    'launch_migration_claim' => null,
918
                    'launch_migration_claim' => null,
912
                ],
919
                ],
913
                'sync_members_data' => [
920
                'syncmembers' => [
914
                    $this->get_mock_members_with_ids(['1p3_1'], null)[0],
921
                    self::get_mock_members_with_ids(['1p3_1'], null)[0],
915
                    $this->get_mock_members_with_ids(['1p3_2'], null)[0],
922
                    self::get_mock_members_with_ids(['1p3_2'], null)[0],
916
                    $this->get_mock_members_with_ids(['1p3_3'], null)[0],
923
                    self::get_mock_members_with_ids(['1p3_3'], null)[0],
917
                    $this->get_mock_members_with_ids(['1p3_4'], null)[0],
924
                    self::get_mock_members_with_ids(['1p3_4'], null)[0],
918
                ],
925
                ],
919
                'expected' => [
926
                'expected' => [
920
                    'enrolments' => [
927
                    'enrolments' => [
921
                        '1p3_1' => [
928
                        '1p3_1' => [
922
                            'is_enrolled' => true,
929
                            'is_enrolled' => true,
Línea 936... Línea 943...
936
                        ]
943
                        ]
937
                    ]
944
                    ]
938
                ]
945
                ]
939
            ],
946
            ],
940
            'New tool, no launch migration claim, no change in user ids, new and existing users present in sync' => [
947
            'New tool, no launch migration claim, no change in user ids, new and existing users present in sync' => [
941
                'legacy_data' => [
948
                'legacydata' => [
942
                    'users' => [
949
                    'users' => [
943
                        ['user_id' => '1'],
950
                        ['user_id' => '1'],
944
                        ['user_id' => '2'],
951
                        ['user_id' => '2'],
945
                    ],
952
                    ],
946
                    'consumer_key' => 'CONSUMER_1',
953
                    'consumer_key' => 'CONSUMER_1',
947
                    'tools' => [
954
                    'tools' => [
948
                        ['secret' => 'toolsecret1'],
955
                        ['secret' => 'toolsecret1'],
949
                        ['secret' => 'toolsecret2'],
956
                        ['secret' => 'toolsecret2'],
950
                    ]
957
                    ]
951
                ],
958
                ],
952
                'resource_config' => null,
959
                'resourceconfig' => null,
953
                'launch_data' => [
960
                'launchdata' => [
954
                    'user' => $this->get_mock_launch_users_with_ids(['1'])[0],
961
                    'user' => self::get_mock_launch_users_with_ids(['1'])[0],
955
                    'launch_migration_claim' => null,
962
                    'launch_migration_claim' => null,
956
                ],
963
                ],
957
                'sync_members_data' => [
964
                'syncmembers' => [
958
                    $this->get_mock_members_with_ids(['1'], null)[0],
965
                    self::get_mock_members_with_ids(['1'], null)[0],
959
                    $this->get_mock_members_with_ids(['2'], null)[0],
966
                    self::get_mock_members_with_ids(['2'], null)[0],
960
                    $this->get_mock_members_with_ids(['3'], null)[0],
967
                    self::get_mock_members_with_ids(['3'], null)[0],
961
                    $this->get_mock_members_with_ids(['4'], null)[0],
968
                    self::get_mock_members_with_ids(['4'], null)[0],
962
                ],
969
                ],
963
                'expected' => [
970
                'expected' => [
964
                    'enrolments' => [
971
                    'enrolments' => [
965
                        '1' => [
972
                        '1' => [
966
                            'is_enrolled' => true,
973
                            'is_enrolled' => true,
Línea 980... Línea 987...
980
                        ]
987
                        ]
981
                    ]
988
                    ]
982
                ]
989
                ]
983
            ],
990
            ],
984
            'New tool, migration only via member sync, no launch claim, new and existing users present in sync' => [
991
            'New tool, migration only via member sync, no launch claim, new and existing users present in sync' => [
985
                'legacy_data' => [
992
                'legacydata' => [
986
                    'users' => [
993
                    'users' => [
987
                        ['user_id' => '1'],
994
                        ['user_id' => '1'],
988
                        ['user_id' => '2'],
995
                        ['user_id' => '2'],
989
                    ],
996
                    ],
990
                    'consumer_key' => 'CONSUMER_1',
997
                    'consumer_key' => 'CONSUMER_1',
991
                    'tools' => [
998
                    'tools' => [
992
                        ['secret' => 'toolsecret1'],
999
                        ['secret' => 'toolsecret1'],
993
                        ['secret' => 'toolsecret2'],
1000
                        ['secret' => 'toolsecret2'],
994
                    ]
1001
                    ]
995
                ],
1002
                ],
996
                'resource_config' => null,
1003
                'resourceconfig' => null,
997
                'launch_data' => [
1004
                'launchdata' => [
998
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
1005
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
999
                    'launch_migration_claim' => null,
1006
                    'launch_migration_claim' => null,
1000
                ],
1007
                ],
1001
                'sync_members_data' => [
1008
                'syncmembers' => [
1002
                    $this->get_mock_members_with_ids(['1p3_1'], ['1'])[0],
1009
                    self::get_mock_members_with_ids(['1p3_1'], ['1'])[0],
1003
                    $this->get_mock_members_with_ids(['1p3_2'], ['2'])[0],
1010
                    self::get_mock_members_with_ids(['1p3_2'], ['2'])[0],
1004
                    $this->get_mock_members_with_ids(['1p3_3'], ['3'])[0],
1011
                    self::get_mock_members_with_ids(['1p3_3'], ['3'])[0],
1005
                    $this->get_mock_members_with_ids(['1p3_4'], ['4'])[0],
1012
                    self::get_mock_members_with_ids(['1p3_4'], ['4'])[0],
1006
                ],
1013
                ],
1007
                'expected' => [
1014
                'expected' => [
1008
                    'enrolments' => [
1015
                    'enrolments' => [
1009
                        '1p3_1' => [
1016
                        '1p3_1' => [
1010
                            'is_enrolled' => true,
1017
                            'is_enrolled' => true,
Línea 1024... Línea 1031...
1024
                        ]
1031
                        ]
1025
                    ]
1032
                    ]
1026
                ]
1033
                ]
1027
            ],
1034
            ],
1028
            'Default provisioning modes, mixed bag of users and roles' => [
1035
            'Default provisioning modes, mixed bag of users and roles' => [
1029
                'legacy_data' => null,
1036
                'legacydata' => null,
1030
                'resource_config' => [
1037
                'resourceconfig' => [
1031
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1038
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1032
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING
1039
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING
1033
                ],
1040
                ],
1034
                'launch_data' => [
1041
                'launchdata' => [
1035
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
1042
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
1036
                    'launch_migration_claim' => null,
1043
                    'launch_migration_claim' => null,
1037
                ],
1044
                ],
1038
                'sync_members_data' => [
1045
                'syncmembers' => [
1039
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1046
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1040
                    $this->get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1047
                    self::get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1041
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1048
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1042
                    ])[0],
1049
                    ])[0],
1043
                    // This user is just a learner.
1050
                    // This user is just a learner.
1044
                    $this->get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1051
                    self::get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1045
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1052
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1046
                    ])[0],
1053
                    ])[0],
1047
                    // This user is also a learner.
1054
                    // This user is also a learner.
1048
                    $this->get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1055
                    self::get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1049
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1056
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1050
                    ])[0],
1057
                    ])[0],
1051
                    // This user is both an instructor and a learner.
1058
                    // This user is both an instructor and a learner.
1052
                    $this->get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1059
                    self::get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1053
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1060
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1054
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1061
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1055
                    ])[0],
1062
                    ])[0],
1056
                ],
1063
                ],
1057
                'expected' => [
1064
                'expected' => [
Línea 1074... Línea 1081...
1074
                        ]
1081
                        ]
1075
                    ]
1082
                    ]
1076
                ]
1083
                ]
1077
            ],
1084
            ],
1078
            'All automatic provisioning, mixed bag of users and roles' => [
1085
            'All automatic provisioning, mixed bag of users and roles' => [
1079
                'legacy_data' => null,
1086
                'legacydata' => null,
1080
                'resource_config' => [
1087
                'resourceconfig' => [
1081
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1088
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1082
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY
1089
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY
1083
                ],
1090
                ],
1084
                'launch_data' => [
1091
                'launchdata' => [
1085
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
1092
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
1086
                    'launch_migration_claim' => null,
1093
                    'launch_migration_claim' => null,
1087
                ],
1094
                ],
1088
                'sync_members_data' => [
1095
                'syncmembers' => [
1089
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1096
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1090
                    $this->get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1097
                    self::get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1091
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1098
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1092
                    ])[0],
1099
                    ])[0],
1093
                    // This user is just a learner.
1100
                    // This user is just a learner.
1094
                    $this->get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1101
                    self::get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1095
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1102
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1096
                    ])[0],
1103
                    ])[0],
1097
                    // This user is also a learner.
1104
                    // This user is also a learner.
1098
                    $this->get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1105
                    self::get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1099
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1106
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1100
                    ])[0],
1107
                    ])[0],
1101
                    // This user is both an instructor and a learner.
1108
                    // This user is both an instructor and a learner.
1102
                    $this->get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1109
                    self::get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1103
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1110
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1104
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1111
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1105
                    ])[0],
1112
                    ])[0],
1106
                ],
1113
                ],
1107
                'expected' => [
1114
                'expected' => [
Línea 1124... Línea 1131...
1124
                        ]
1131
                        ]
1125
                    ]
1132
                    ]
1126
                ]
1133
                ]
1127
            ],
1134
            ],
1128
            'All prompt provisioning, mixed bag of users and roles' => [
1135
            'All prompt provisioning, mixed bag of users and roles' => [
1129
                'legacy_data' => null,
1136
                'legacydata' => null,
1130
                'resource_config' => [
1137
                'resourceconfig' => [
1131
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING,
1138
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING,
1132
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING
1139
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_PROMPT_NEW_EXISTING
1133
                ],
1140
                ],
1134
                'launch_data' => [
1141
                'launchdata' => [
1135
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
1142
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
1136
                    'launch_migration_claim' => null,
1143
                    'launch_migration_claim' => null,
1137
                ],
1144
                ],
1138
                'sync_members_data' => [
1145
                'syncmembers' => [
1139
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1146
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1140
                    $this->get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1147
                    self::get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1141
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1148
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1142
                    ])[0],
1149
                    ])[0],
1143
                    // This user is just a learner.
1150
                    // This user is just a learner.
1144
                    $this->get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1151
                    self::get_mock_members_with_ids(['1p3_2'], null, true, true, true, false, [
1145
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1152
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1146
                    ])[0],
1153
                    ])[0],
1147
                    // This user is also a learner.
1154
                    // This user is also a learner.
1148
                    $this->get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1155
                    self::get_mock_members_with_ids(['1p3_3'], null, true, true, true, false, [
1149
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1156
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1150
                    ])[0],
1157
                    ])[0],
1151
                    // This user is both an instructor and a learner.
1158
                    // This user is both an instructor and a learner.
1152
                    $this->get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1159
                    self::get_mock_members_with_ids(['1p3_4'], null, true, true, true, false, [
1153
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1160
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1154
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1161
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1155
                    ])[0],
1162
                    ])[0],
1156
                ],
1163
                ],
1157
                'expected' => [
1164
                'expected' => [
Línea 1174... Línea 1181...
1174
                        ]
1181
                        ]
1175
                    ]
1182
                    ]
1176
                ]
1183
                ]
1177
            ],
1184
            ],
1178
            'All automatic provisioning, with legacy data and migration claim, mixed bag of users and roles' => [
1185
            'All automatic provisioning, with legacy data and migration claim, mixed bag of users and roles' => [
1179
                'legacy_data' => [
1186
                'legacydata' => [
1180
                    'users' => [
1187
                    'users' => [
1181
                        ['user_id' => '2'],
1188
                        ['user_id' => '2'],
1182
                        ['user_id' => '3'],
1189
                        ['user_id' => '3'],
1183
                        ['user_id' => '4'],
1190
                        ['user_id' => '4'],
1184
                        ['user_id' => '5']
1191
                        ['user_id' => '5']
Línea 1187... Línea 1194...
1187
                    'tools' => [
1194
                    'tools' => [
1188
                        ['secret' => 'toolsecret1'],
1195
                        ['secret' => 'toolsecret1'],
1189
                        ['secret' => 'toolsecret2'],
1196
                        ['secret' => 'toolsecret2'],
1190
                    ]
1197
                    ]
1191
                ],
1198
                ],
1192
                'resource_config' => [
1199
                'resourceconfig' => [
1193
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1200
                    'provisioningmodelearner' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY,
1194
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY
1201
                    'provisioningmodeinstructor' => \auth_plugin_lti::PROVISIONING_MODE_AUTO_ONLY
1195
                ],
1202
                ],
1196
                'launch_data' => [
1203
                'launchdata' => [
1197
                    'user' => $this->get_mock_launch_users_with_ids(['1p3_1'])[0],
1204
                    'user' => self::get_mock_launch_users_with_ids(['1p3_1'])[0],
1198
                    'launch_migration_claim' => [
1205
                    'launch_migration_claim' => [
1199
                        'consumer_key' => 'CONSUMER_1',
1206
                        'consumer_key' => 'CONSUMER_1',
1200
                        'signing_secret' => 'toolsecret1',
1207
                        'signing_secret' => 'toolsecret1',
1201
                        'context_id' => 'd345b',
1208
                        'context_id' => 'd345b',
1202
                        'tool_consumer_instance_guid' => '12345-123',
1209
                        'tool_consumer_instance_guid' => '12345-123',
1203
                        'resource_link_id' => '4b6fa'
1210
                        'resource_link_id' => '4b6fa'
1204
                    ],
1211
                    ],
1205
                ],
1212
                ],
1206
                'sync_members_data' => [
1213
                'syncmembers' => [
1207
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1214
                    // This user is just an instructor but is also the user who is already linked, via the launch above.
1208
                    $this->get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1215
                    self::get_mock_members_with_ids(['1p3_1'], null, true, true, true, false, [
1209
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1216
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1210
                    ])[0],
1217
                    ])[0],
1211
                    // This user is just a learner.
1218
                    // This user is just a learner.
1212
                    $this->get_mock_members_with_ids(['1p3_2'], ['2'], true, true, true, false, [
1219
                    self::get_mock_members_with_ids(['1p3_2'], ['2'], true, true, true, false, [
1213
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1220
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1214
                    ])[0],
1221
                    ])[0],
1215
                    // This user is also a learner.
1222
                    // This user is also a learner.
1216
                    $this->get_mock_members_with_ids(['1p3_3'], ['3'], true, true, true, false, [
1223
                    self::get_mock_members_with_ids(['1p3_3'], ['3'], true, true, true, false, [
1217
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1224
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1218
                    ])[0],
1225
                    ])[0],
1219
                    // This user is both an instructor and a learner.
1226
                    // This user is both an instructor and a learner.
1220
                    $this->get_mock_members_with_ids(['1p3_4'], ['4'], true, true, true, false, [
1227
                    self::get_mock_members_with_ids(['1p3_4'], ['4'], true, true, true, false, [
1221
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1228
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1222
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1229
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
1223
                    ])[0],
1230
                    ])[0],
1224
                    // This user is just an instructor who hasn't launched before (unlike the first user here).
1231
                    // This user is just an instructor who hasn't launched before (unlike the first user here).
1225
                    $this->get_mock_members_with_ids(['1p3_5'], ['5'], true, true, true, false, [
1232
                    self::get_mock_members_with_ids(['1p3_5'], ['5'], true, true, true, false, [
1226
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1233
                        'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
1227
                    ])[0],
1234
                    ])[0],
1228
                ],
1235
                ],
1229
                'expected' => [
1236
                'expected' => [
1230
                    'enrolments' => [
1237
                    'enrolments' => [