Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 86... Línea 86...
86
    }
86
    }
Línea 87... Línea 87...
87
 
87
 
88
    /**
88
    /**
89
     * Test get_tool_proxies.
89
     * Test get_tool_proxies.
90
     */
90
     */
91
    public function test_mod_lti_get_tool_proxies() {
91
    public function test_mod_lti_get_tool_proxies(): void {
92
        // Create two tool proxies. One to associate with tool, and one to leave orphaned.
92
        // Create two tool proxies. One to associate with tool, and one to leave orphaned.
93
        $this->setAdminUser();
93
        $this->setAdminUser();
94
        $proxy = $this->generate_tool_proxy("1");
94
        $proxy = $this->generate_tool_proxy("1");
95
        $orphanedproxy = $this->generate_tool_proxy("2");
95
        $orphanedproxy = $this->generate_tool_proxy("2");
Línea 104... Línea 104...
104
    }
104
    }
Línea 105... Línea 105...
105
 
105
 
106
    /**
106
    /**
107
     * Test get_tool_proxies with orphaned proxies only.
107
     * Test get_tool_proxies with orphaned proxies only.
108
     */
108
     */
109
    public function test_mod_lti_get_orphaned_tool_proxies() {
109
    public function test_mod_lti_get_orphaned_tool_proxies(): void {
110
        // Create two tool proxies. One to associate with tool, and one to leave orphaned.
110
        // Create two tool proxies. One to associate with tool, and one to leave orphaned.
111
        $this->setAdminUser();
111
        $this->setAdminUser();
112
        $proxy = $this->generate_tool_proxy("1");
112
        $proxy = $this->generate_tool_proxy("1");
113
        $orphanedproxy = $this->generate_tool_proxy("2");
113
        $orphanedproxy = $this->generate_tool_proxy("2");
Línea 122... Línea 122...
122
    }
122
    }
Línea 123... Línea 123...
123
 
123
 
124
    /**
124
    /**
125
     * Test get_tool_launch_data.
125
     * Test get_tool_launch_data.
126
     */
126
     */
127
    public function test_get_tool_launch_data() {
127
    public function test_get_tool_launch_data(): void {
Línea 128... Línea 128...
128
        global $USER;
128
        global $USER;
129
 
129
 
130
        [
130
        [
Línea 157... Línea 157...
157
    }
157
    }
Línea 158... Línea 158...
158
 
158
 
159
    /**
159
    /**
160
     * Test get_ltis_by_courses.
160
     * Test get_ltis_by_courses.
161
     */
161
     */
162
    public function test_mod_lti_get_ltis_by_courses() {
162
    public function test_mod_lti_get_ltis_by_courses(): void {
163
        [
163
        [
164
            'course' => $course,
164
            'course' => $course,
165
            'lti' => $lti,
165
            'lti' => $lti,
166
            'student' => $student,
166
            'student' => $student,
Línea 292... Línea 292...
292
    }
292
    }
Línea 293... Línea 293...
293
 
293
 
294
    /**
294
    /**
295
     * Test view_lti with an invalid instance id.
295
     * Test view_lti with an invalid instance id.
296
     */
296
     */
297
    public function test_view_lti_invalid_instanceid() {
297
    public function test_view_lti_invalid_instanceid(): void {
298
        $this->expectException(\moodle_exception::class);
298
        $this->expectException(\moodle_exception::class);
299
        mod_lti_external::view_lti(0);
299
        mod_lti_external::view_lti(0);
Línea 300... Línea 300...
300
    }
300
    }
301
 
301
 
302
    /**
302
    /**
303
     * Test view_lti as a user who is not enrolled in the course.
303
     * Test view_lti as a user who is not enrolled in the course.
304
     */
304
     */
305
    public function test_view_lti_no_enrolment() {
305
    public function test_view_lti_no_enrolment(): void {
306
        [
306
        [
Línea 307... Línea 307...
307
            'lti' => $lti
307
            'lti' => $lti
Línea 316... Línea 316...
316
    }
316
    }
Línea 317... Línea 317...
317
 
317
 
318
    /**
318
    /**
319
     * Test view_lti for a user without the mod/lti:view capability.
319
     * Test view_lti for a user without the mod/lti:view capability.
320
     */
320
     */
321
    public function test_view_lti_no_capability() {
321
    public function test_view_lti_no_capability(): void {
322
        [
322
        [
323
            'lti' => $lti,
323
            'lti' => $lti,
324
            'student' => $student,
324
            'student' => $student,
325
            'studentrole' => $studentrole,
325
            'studentrole' => $studentrole,
Línea 339... Línea 339...
339
    }
339
    }
Línea 340... Línea 340...
340
 
340
 
341
    /**
341
    /**
342
     * Test view_lti for a user with the mod/lti:view capability in the course.
342
     * Test view_lti for a user with the mod/lti:view capability in the course.
343
     */
343
     */
344
    public function test_view_lti() {
344
    public function test_view_lti(): void {
345
        [
345
        [
346
            'lti' => $lti,
346
            'lti' => $lti,
347
            'context' => $context,
347
            'context' => $context,
348
            'cm' => $cm,
348
            'cm' => $cm,
Línea 373... Línea 373...
373
    }
373
    }
Línea 374... Línea 374...
374
 
374
 
375
    /**
375
    /**
376
     * Test create_tool_proxy.
376
     * Test create_tool_proxy.
377
     */
377
     */
378
    public function test_mod_lti_create_tool_proxy() {
378
    public function test_mod_lti_create_tool_proxy(): void {
379
        $this->setAdminUser();
379
        $this->setAdminUser();
380
        $capabilities = ['AA', 'BB'];
380
        $capabilities = ['AA', 'BB'];
381
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), $capabilities, []);
381
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), $capabilities, []);
Línea 388... Línea 388...
388
    }
388
    }
Línea 389... Línea 389...
389
 
389
 
390
    /**
390
    /**
391
     * Test create_tool_proxy with a duplicate url.
391
     * Test create_tool_proxy with a duplicate url.
392
     */
392
     */
393
    public function test_mod_lti_create_tool_proxy_duplicateurl() {
393
    public function test_mod_lti_create_tool_proxy_duplicateurl(): void {
394
        $this->setAdminUser();
394
        $this->setAdminUser();
Línea 395... Línea 395...
395
        mod_lti_external::create_tool_proxy('Test proxy 1', $this->getExternalTestFileUrl('/test.html'), array(), array());
395
        mod_lti_external::create_tool_proxy('Test proxy 1', $this->getExternalTestFileUrl('/test.html'), array(), array());
396
 
396
 
397
        $this->expectException(\moodle_exception::class);
397
        $this->expectException(\moodle_exception::class);
Línea 398... Línea 398...
398
        mod_lti_external::create_tool_proxy('Test proxy 2', $this->getExternalTestFileUrl('/test.html'), array(), array());
398
        mod_lti_external::create_tool_proxy('Test proxy 2', $this->getExternalTestFileUrl('/test.html'), array(), array());
399
    }
399
    }
400
 
400
 
401
    /**
401
    /**
402
     * Test create_tool_proxy for a user without the required capability.
402
     * Test create_tool_proxy for a user without the required capability.
403
     */
403
     */
404
    public function test_mod_lti_create_tool_proxy_without_capability() {
404
    public function test_mod_lti_create_tool_proxy_without_capability(): void {
405
        $course = $this->getDataGenerator()->create_course();
405
        $course = $this->getDataGenerator()->create_course();
406
        $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
406
        $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
407
        $this->setUser($teacher);
407
        $this->setUser($teacher);
Línea 408... Línea 408...
408
        $this->expectException(\required_capability_exception::class);
408
        $this->expectException(\required_capability_exception::class);
409
        mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
409
        mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
410
    }
410
    }
411
 
411
 
412
    /**
412
    /**
413
     * Test delete_tool_proxy.
413
     * Test delete_tool_proxy.
414
     */
414
     */
415
    public function test_mod_lti_delete_tool_proxy() {
415
    public function test_mod_lti_delete_tool_proxy(): void {
Línea 428... Línea 428...
428
    }
428
    }
Línea 429... Línea 429...
429
 
429
 
430
    /**
430
    /**
431
     * Test get_tool_proxy_registration_request.
431
     * Test get_tool_proxy_registration_request.
432
     */
432
     */
433
    public function test_mod_lti_get_tool_proxy_registration_request() {
433
    public function test_mod_lti_get_tool_proxy_registration_request(): void {
434
        $this->setAdminUser();
434
        $this->setAdminUser();
435
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
435
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
Línea 436... Línea 436...
436
        $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
436
        $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
Línea 444... Línea 444...
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
446
    /**
446
    /**
447
     * Test get_tool_types.
447
     * Test get_tool_types.
448
     */
448
     */
449
    public function test_mod_lti_get_tool_types() {
449
    public function test_mod_lti_get_tool_types(): void {
450
        $this->setAdminUser();
450
        $this->setAdminUser();
451
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
451
        $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
Línea 452... Línea 452...
452
        $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
452
        $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
Línea 471... Línea 471...
471
    }
471
    }
Línea 472... Línea 472...
472
 
472
 
473
    /**
473
    /**
474
     * Test create_tool_type.
474
     * Test create_tool_type.
475
     */
475
     */
476
    public function test_mod_lti_create_tool_type() {
476
    public function test_mod_lti_create_tool_type(): void {
477
        $this->setAdminUser();
477
        $this->setAdminUser();
478
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
478
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
Línea 479... Línea 479...
479
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
479
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
Línea 491... Línea 491...
491
    }
491
    }
Línea 492... Línea 492...
492
 
492
 
493
    /**
493
    /**
494
     * Test create_tool_type failure from non existent file.
494
     * Test create_tool_type failure from non existent file.
495
     */
495
     */
496
    public function test_mod_lti_create_tool_type_nonexistant_file() {
496
    public function test_mod_lti_create_tool_type_nonexistant_file(): void {
497
        $this->expectException(\moodle_exception::class);
497
        $this->expectException(\moodle_exception::class);
498
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/doesntexist.xml'), '', '');
498
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/doesntexist.xml'), '', '');
Línea 499... Línea 499...
499
    }
499
    }
500
 
500
 
501
    /**
501
    /**
502
     * Test create_tool_type failure from xml that is not a cartridge.
502
     * Test create_tool_type failure from xml that is not a cartridge.
503
     */
503
     */
504
    public function test_mod_lti_create_tool_type_bad_file() {
504
    public function test_mod_lti_create_tool_type_bad_file(): void {
505
        $this->expectException(\moodle_exception::class);
505
        $this->expectException(\moodle_exception::class);
Línea 506... Línea 506...
506
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/rsstest.xml'), '', '');
506
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/rsstest.xml'), '', '');
507
    }
507
    }
508
 
508
 
509
    /**
509
    /**
510
     * Test create_tool_type as a user without the required capability.
510
     * Test create_tool_type as a user without the required capability.
511
     */
511
     */
512
    public function test_mod_lti_create_tool_type_without_capability() {
512
    public function test_mod_lti_create_tool_type_without_capability(): void {
513
        $course = $this->getDataGenerator()->create_course();
513
        $course = $this->getDataGenerator()->create_course();
514
        $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
514
        $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
515
        $this->setUser($teacher);
515
        $this->setUser($teacher);
Línea 516... Línea 516...
516
        $this->expectException(\required_capability_exception::class);
516
        $this->expectException(\required_capability_exception::class);
517
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
517
        mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
518
    }
518
    }
519
 
519
 
520
    /**
520
    /**
521
     * Test update_tool_type.
521
     * Test update_tool_type.
522
     */
522
     */
Línea 523... Línea 523...
523
    public function test_mod_lti_update_tool_type() {
523
    public function test_mod_lti_update_tool_type(): void {
Línea 534... Línea 534...
534
    }
534
    }
Línea 535... Línea 535...
535
 
535
 
536
    /**
536
    /**
537
     * Test delete_tool_type for a user with the required capability.
537
     * Test delete_tool_type for a user with the required capability.
538
     */
538
     */
539
    public function test_mod_lti_delete_tool_type() {
539
    public function test_mod_lti_delete_tool_type(): void {
540
        $this->setAdminUser();
540
        $this->setAdminUser();
541
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
541
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
542
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
542
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
Línea 548... Línea 548...
548
    }
548
    }
Línea 549... Línea 549...
549
 
549
 
550
    /**
550
    /**
551
     * Test delete_tool_type for a user without the required capability.
551
     * Test delete_tool_type for a user without the required capability.
552
     */
552
     */
553
    public function test_mod_lti_delete_tool_type_without_capability() {
553
    public function test_mod_lti_delete_tool_type_without_capability(): void {
554
        $this->setAdminUser();
554
        $this->setAdminUser();
555
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
555
        $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
556
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
556
        $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
Línea 564... Línea 564...
564
    }
564
    }
Línea 565... Línea 565...
565
 
565
 
566
    /**
566
    /**
567
     * Test is_cartridge.
567
     * Test is_cartridge.
568
     */
568
     */
569
    public function test_mod_lti_is_cartridge() {
569
    public function test_mod_lti_is_cartridge(): void {
570
        $this->setAdminUser();
570
        $this->setAdminUser();
571
        $result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'));
571
        $result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'));
572
        $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
572
        $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);