Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 70... Línea 70...
70
    /**
70
    /**
71
     * @covers ::lti_split_parameters()
71
     * @covers ::lti_split_parameters()
72
     *
72
     *
73
     * Test the split parameters function
73
     * Test the split parameters function
74
     */
74
     */
75
    public function test_split_parameters() {
75
    public function test_split_parameters(): void {
76
        $this->assertEquals(lti_split_parameters(''), array());
76
        $this->assertEquals(lti_split_parameters(''), array());
77
        $this->assertEquals(lti_split_parameters('a=1'), array('a' => '1'));
77
        $this->assertEquals(lti_split_parameters('a=1'), array('a' => '1'));
78
        $this->assertEquals(lti_split_parameters("a=1\nb=2"), array('a' => '1', 'b' => '2'));
78
        $this->assertEquals(lti_split_parameters("a=1\nb=2"), array('a' => '1', 'b' => '2'));
79
        $this->assertEquals(lti_split_parameters("a=1\n\rb=2"), array('a' => '1', 'b' => '2'));
79
        $this->assertEquals(lti_split_parameters("a=1\n\rb=2"), array('a' => '1', 'b' => '2'));
80
        $this->assertEquals(lti_split_parameters("a=1\r\nb=2"), array('a' => '1', 'b' => '2'));
80
        $this->assertEquals(lti_split_parameters("a=1\r\nb=2"), array('a' => '1', 'b' => '2'));
81
    }
81
    }
Línea 82... Línea 82...
82
 
82
 
83
    public function test_split_custom_parameters() {
83
    public function test_split_custom_parameters(): void {
Línea 84... Línea 84...
84
        $this->resetAfterTest();
84
        $this->resetAfterTest();
85
 
85
 
86
        $tool = new \stdClass();
86
        $tool = new \stdClass();
Línea 192... Línea 192...
192
        $ltiinstance = (object)array('servicesalt' => '4e5fcc06de1d58.44963230');
192
        $ltiinstance = (object)array('servicesalt' => '4e5fcc06de1d58.44963230');
Línea 193... Línea 193...
193
 
193
 
194
        lti_verify_sourcedid($ltiinstance, $parsed);
194
        lti_verify_sourcedid($ltiinstance, $parsed);
Línea 195... Línea 195...
195
    }
195
    }
196
 
196
 
197
    public function test_lti_ensure_url_is_https() {
197
    public function test_lti_ensure_url_is_https(): void {
198
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('http://moodle.org'));
198
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('http://moodle.org'));
199
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('moodle.org'));
199
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('moodle.org'));
Línea 200... Línea 200...
200
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('https://moodle.org'));
200
        $this->assertEquals('https://moodle.org', lti_ensure_url_is_https('https://moodle.org'));
201
    }
201
    }
202
 
202
 
203
    /**
203
    /**
204
     * Test lti_get_url_thumbprint against various URLs
204
     * Test lti_get_url_thumbprint against various URLs
205
     */
205
     */
206
    public function test_lti_get_url_thumbprint() {
206
    public function test_lti_get_url_thumbprint(): void {
207
        // Note: trailing and double slash are expected right now.  Must evaluate if it must be removed at some point.
207
        // Note: trailing and double slash are expected right now.  Must evaluate if it must be removed at some point.
208
        $this->assertEquals('moodle.org/', lti_get_url_thumbprint('http://MOODLE.ORG'));
208
        $this->assertEquals('moodle.org/', lti_get_url_thumbprint('http://MOODLE.ORG'));
Línea 217... Línea 217...
217
    }
217
    }
Línea 218... Línea 218...
218
 
218
 
219
    /*
219
    /*
220
     * Verify that lti_build_request does handle resource_link_id as expected
220
     * Verify that lti_build_request does handle resource_link_id as expected
221
     */
221
     */
222
    public function test_lti_buid_request_resource_link_id() {
222
    public function test_lti_buid_request_resource_link_id(): void {
Línea 223... Línea 223...
223
        $this->resetAfterTest();
223
        $this->resetAfterTest();
224
 
224
 
225
        self::setUser($this->getDataGenerator()->create_user());
225
        self::setUser($this->getDataGenerator()->create_user());
Línea 256... Línea 256...
256
 
256
 
257
    /**
257
    /**
258
     * Test lti_build_request's resource_link_description and ensure
258
     * Test lti_build_request's resource_link_description and ensure
259
     * that the newlines in the description are correct.
259
     * that the newlines in the description are correct.
260
     */
260
     */
261
    public function test_lti_build_request_description() {
261
    public function test_lti_build_request_description(): void {
Línea 262... Línea 262...
262
        $this->resetAfterTest();
262
        $this->resetAfterTest();
263
 
263
 
264
        self::setUser($this->getDataGenerator()->create_user());
264
        self::setUser($this->getDataGenerator()->create_user());
Línea 294... Línea 294...
294
    }
294
    }
Línea 295... Línea 295...
295
 
295
 
296
    /**
296
    /**
297
     * Tests lti_prepare_type_for_save's handling of the "Force SSL" configuration.
297
     * Tests lti_prepare_type_for_save's handling of the "Force SSL" configuration.
298
     */
298
     */
299
    public function test_lti_prepare_type_for_save_forcessl() {
299
    public function test_lti_prepare_type_for_save_forcessl(): void {
300
        $type = new \stdClass();
300
        $type = new \stdClass();
Línea 301... Línea 301...
301
        $config = new \stdClass();
301
        $config = new \stdClass();
302
 
302
 
Línea 322... Línea 322...
322
    }
322
    }
Línea 323... Línea 323...
323
 
323
 
324
    /**
324
    /**
325
     * Tests lti_load_type_from_cartridge and lti_load_type_if_cartridge
325
     * Tests lti_load_type_from_cartridge and lti_load_type_if_cartridge
326
     */
326
     */
327
    public function test_lti_load_type_from_cartridge() {
327
    public function test_lti_load_type_from_cartridge(): void {
328
        $type = new \stdClass();
328
        $type = new \stdClass();
Línea 329... Línea 329...
329
        $type->lti_toolurl = $this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml');
329
        $type->lti_toolurl = $this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml');
Línea 338... Línea 338...
338
    }
338
    }
Línea 339... Línea 339...
339
 
339
 
340
    /**
340
    /**
341
     * Tests lti_load_tool_from_cartridge and lti_load_tool_if_cartridge
341
     * Tests lti_load_tool_from_cartridge and lti_load_tool_if_cartridge
342
     */
342
     */
343
    public function test_lti_load_tool_from_cartridge() {
343
    public function test_lti_load_tool_from_cartridge(): void {
344
        $lti = new \stdClass();
344
        $lti = new \stdClass();
Línea 345... Línea 345...
345
        $lti->toolurl = $this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml');
345
        $lti->toolurl = $this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml');
Línea 355... Línea 355...
355
    }
355
    }
Línea 356... Línea 356...
356
 
356
 
357
    /**
357
    /**
358
     * Tests for lti_build_content_item_selection_request().
358
     * Tests for lti_build_content_item_selection_request().
359
     */
359
     */
360
    public function test_lti_build_content_item_selection_request() {
360
    public function test_lti_build_content_item_selection_request(): void {
Línea 361... Línea 361...
361
        $this->resetAfterTest();
361
        $this->resetAfterTest();
362
 
362
 
363
        $this->setAdminUser();
363
        $this->setAdminUser();
Línea 444... Línea 444...
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
446
    /**
446
    /**
447
     * Test for lti_build_content_item_selection_request() with nonexistent tool type ID parameter.
447
     * Test for lti_build_content_item_selection_request() with nonexistent tool type ID parameter.
448
     */
448
     */
449
    public function test_lti_build_content_item_selection_request_invalid_tooltype() {
449
    public function test_lti_build_content_item_selection_request_invalid_tooltype(): void {
Línea 450... Línea 450...
450
        $this->resetAfterTest();
450
        $this->resetAfterTest();
451
 
451
 
452
        $this->setAdminUser();
452
        $this->setAdminUser();
Línea 459... Línea 459...
459
    }
459
    }
Línea 460... Línea 460...
460
 
460
 
461
    /**
461
    /**
462
     * Test for lti_build_content_item_selection_request() with invalid media types parameter.
462
     * Test for lti_build_content_item_selection_request() with invalid media types parameter.
463
     */
463
     */
464
    public function test_lti_build_content_item_selection_request_invalid_mediatypes() {
464
    public function test_lti_build_content_item_selection_request_invalid_mediatypes(): void {
Línea 465... Línea 465...
465
        $this->resetAfterTest();
465
        $this->resetAfterTest();
Línea 466... Línea 466...
466
 
466
 
Línea 486... Línea 486...
486
    }
486
    }
Línea 487... Línea 487...
487
 
487
 
488
    /**
488
    /**
489
     * Test for lti_build_content_item_selection_request() with invalid presentation targets parameter.
489
     * Test for lti_build_content_item_selection_request() with invalid presentation targets parameter.
490
     */
490
     */
491
    public function test_lti_build_content_item_selection_request_invalid_presentationtargets() {
491
    public function test_lti_build_content_item_selection_request_invalid_presentationtargets(): void {
Línea 492... Línea 492...
492
        $this->resetAfterTest();
492
        $this->resetAfterTest();
Línea 493... Línea 493...
493
 
493
 
Línea 616... Línea 616...
616
     * @dataProvider lti_get_best_tool_by_url_provider
616
     * @dataProvider lti_get_best_tool_by_url_provider
617
     * @param string $url The URL to test.
617
     * @param string $url The URL to test.
618
     * @param object $expected The expected tool matching the URL.
618
     * @param object $expected The expected tool matching the URL.
619
     * @param array $tools The pool of tools to match the URL with.
619
     * @param array $tools The pool of tools to match the URL with.
620
     */
620
     */
621
    public function test_lti_get_best_tool_by_url($url, $expected, $tools) {
621
    public function test_lti_get_best_tool_by_url($url, $expected, $tools): void {
622
        $actual = lti_get_best_tool_by_url($url, $tools, null);
622
        $actual = lti_get_best_tool_by_url($url, $tools, null);
623
        $this->assertSame($expected, $actual);
623
        $this->assertSame($expected, $actual);
624
    }
624
    }
Línea 625... Línea 625...
625
 
625
 
626
    /**
626
    /**
627
     * @covers ::lti_get_tools_by_domain()
627
     * @covers ::lti_get_tools_by_domain()
628
     *
628
     *
629
     * Test lti_get_tools_by_domain.
629
     * Test lti_get_tools_by_domain.
630
     */
630
     */
631
    public function test_lti_get_tools_by_domain() {
631
    public function test_lti_get_tools_by_domain(): void {
Línea 632... Línea 632...
632
        $this->resetAfterTest();
632
        $this->resetAfterTest();
633
 
633
 
Línea 663... Línea 663...
663
    /**
663
    /**
664
     * @covers ::lti_get_tools_by_domain()
664
     * @covers ::lti_get_tools_by_domain()
665
     *
665
     *
666
     * Test test_lti_get_tools_by_domain_restrict_types_category.
666
     * Test test_lti_get_tools_by_domain_restrict_types_category.
667
     */
667
     */
668
    public function test_lti_get_tools_by_domain_restrict_types_category() {
668
    public function test_lti_get_tools_by_domain_restrict_types_category(): void {
669
        $this->resetAfterTest();
669
        $this->resetAfterTest();
Línea 670... Línea 670...
670
 
670
 
671
        $coursecat1 = $this->getDataGenerator()->create_category();
671
        $coursecat1 = $this->getDataGenerator()->create_category();
Línea 729... Línea 729...
729
    }
729
    }
Línea 730... Línea 730...
730
 
730
 
731
    /**
731
    /**
732
     * Test lti_get_jwt_message_type_mapping().
732
     * Test lti_get_jwt_message_type_mapping().
733
     */
733
     */
734
    public function test_lti_get_jwt_message_type_mapping() {
734
    public function test_lti_get_jwt_message_type_mapping(): void {
735
        $mapping = [
735
        $mapping = [
736
            'basic-lti-launch-request' => 'LtiResourceLinkRequest',
736
            'basic-lti-launch-request' => 'LtiResourceLinkRequest',
737
            'ContentItemSelectionRequest' => 'LtiDeepLinkingRequest',
737
            'ContentItemSelectionRequest' => 'LtiDeepLinkingRequest',
738
            'LtiDeepLinkingResponse' => 'ContentItemSelection',
738
            'LtiDeepLinkingResponse' => 'ContentItemSelection',
Línea 743... Línea 743...
743
    }
743
    }
Línea 744... Línea 744...
744
 
744
 
745
    /**
745
    /**
746
     * Test lti_get_jwt_claim_mapping()
746
     * Test lti_get_jwt_claim_mapping()
747
     */
747
     */
748
    public function test_lti_get_jwt_claim_mapping() {
748
    public function test_lti_get_jwt_claim_mapping(): void {
749
        $mapping = [
749
        $mapping = [
750
            'accept_copy_advice' => [
750
            'accept_copy_advice' => [
751
                'suffix' => 'dl',
751
                'suffix' => 'dl',
752
                'group' => 'deep_linking_settings',
752
                'group' => 'deep_linking_settings',
Línea 1136... Línea 1136...
1136
    }
1136
    }
Línea 1137... Línea 1137...
1137
 
1137
 
1138
    /**
1138
    /**
1139
     * Test lti_build_standard_message().
1139
     * Test lti_build_standard_message().
1140
     */
1140
     */
1141
    public function test_lti_build_standard_message_institution_name_set() {
1141
    public function test_lti_build_standard_message_institution_name_set(): void {
Línea 1142... Línea 1142...
1142
        global $CFG;
1142
        global $CFG;
Línea 1143... Línea 1143...
1143
 
1143
 
Línea 1164... Línea 1164...
1164
    }
1164
    }
Línea 1165... Línea 1165...
1165
 
1165
 
1166
    /**
1166
    /**
1167
     * Test lti_build_standard_message().
1167
     * Test lti_build_standard_message().
1168
     */
1168
     */
1169
    public function test_lti_build_standard_message_institution_name_not_set() {
1169
    public function test_lti_build_standard_message_institution_name_not_set(): void {
Línea 1170... Línea 1170...
1170
        $this->resetAfterTest();
1170
        $this->resetAfterTest();
1171
 
1171
 
1172
        $course   = $this->getDataGenerator()->create_course();
1172
        $course   = $this->getDataGenerator()->create_course();
Línea 1188... Línea 1188...
1188
    }
1188
    }
Línea 1189... Línea 1189...
1189
 
1189
 
1190
    /**
1190
    /**
1191
     * Test lti_verify_jwt_signature().
1191
     * Test lti_verify_jwt_signature().
1192
     */
1192
     */
1193
    public function test_lti_verify_jwt_signature() {
1193
    public function test_lti_verify_jwt_signature(): void {
Línea 1194... Línea 1194...
1194
        $this->resetAfterTest();
1194
        $this->resetAfterTest();
Línea 1195... Línea 1195...
1195
 
1195
 
Línea 1225... Línea 1225...
1225
    }
1225
    }
Línea 1226... Línea 1226...
1226
 
1226
 
1227
    /**
1227
    /**
1228
     * Test lti_verify_jwt_signature_jwk().
1228
     * Test lti_verify_jwt_signature_jwk().
1229
     */
1229
     */
1230
    public function test_lti_verify_jwt_signature_jwk() {
1230
    public function test_lti_verify_jwt_signature_jwk(): void {
Línea 1231... Línea 1231...
1231
        $this->resetAfterTest();
1231
        $this->resetAfterTest();
Línea 1232... Línea 1232...
1232
 
1232
 
Línea 1265... Línea 1265...
1265
    }
1265
    }
Línea 1266... Línea 1266...
1266
 
1266
 
1267
    /**
1267
    /**
1268
     * Test lti_verify_jwt_signature().
1268
     * Test lti_verify_jwt_signature().
1269
     */
1269
     */
1270
    public function test_lti_verify_jwt_signature_with_lti2() {
1270
    public function test_lti_verify_jwt_signature_with_lti2(): void {
Línea 1271... Línea 1271...
1271
        $this->resetAfterTest();
1271
        $this->resetAfterTest();
Línea 1272... Línea 1272...
1272
 
1272
 
Línea 1293... Línea 1293...
1293
    }
1293
    }
Línea 1294... Línea 1294...
1294
 
1294
 
1295
    /**
1295
    /**
1296
     * Test lti_verify_jwt_signature().
1296
     * Test lti_verify_jwt_signature().
1297
     */
1297
     */
1298
    public function test_lti_verify_jwt_signature_no_consumer_key() {
1298
    public function test_lti_verify_jwt_signature_no_consumer_key(): void {
Línea 1299... Línea 1299...
1299
        $this->resetAfterTest();
1299
        $this->resetAfterTest();
Línea 1300... Línea 1300...
1300
 
1300
 
Línea 1316... Línea 1316...
1316
    }
1316
    }
Línea 1317... Línea 1317...
1317
 
1317
 
1318
    /**
1318
    /**
1319
     * Test lti_verify_jwt_signature().
1319
     * Test lti_verify_jwt_signature().
1320
     */
1320
     */
1321
    public function test_lti_verify_jwt_signature_no_public_key() {
1321
    public function test_lti_verify_jwt_signature_no_public_key(): void {
1322
        $this->resetAfterTest();
1322
        $this->resetAfterTest();
Línea 1323... Línea 1323...
1323
        $this->setAdminUser();
1323
        $this->setAdminUser();
1324
 
1324
 
Línea 1339... Línea 1339...
1339
    }
1339
    }
Línea 1340... Línea 1340...
1340
 
1340
 
1341
    /**
1341
    /**
1342
     * Test lti_convert_content_items().
1342
     * Test lti_convert_content_items().
1343
     */
1343
     */
1344
    public function test_lti_convert_content_items() {
1344
    public function test_lti_convert_content_items(): void {
1345
        $contentitems = [];
1345
        $contentitems = [];
1346
        $contentitems[] = [
1346
        $contentitems[] = [
1347
            'type' => 'ltiResourceLink',
1347
            'type' => 'ltiResourceLink',
1348
            'url' => 'http://example.com/messages/launch',
1348
            'url' => 'http://example.com/messages/launch',
Línea 1424... Línea 1424...
1424
    }
1424
    }
Línea 1425... Línea 1425...
1425
 
1425
 
1426
    /**
1426
    /**
1427
     * Test adding a single gradable item through content item.
1427
     * Test adding a single gradable item through content item.
1428
     */
1428
     */
1429
    public function test_lti_tool_configuration_from_content_item_single_gradable() {
1429
    public function test_lti_tool_configuration_from_content_item_single_gradable(): void {
1430
        $this->resetAfterTest();
1430
        $this->resetAfterTest();
Línea 1431... Línea 1431...
1431
        $this->setAdminUser();
1431
        $this->setAdminUser();
1432
 
1432
 
Línea 1471... Línea 1471...
1471
    /**
1471
    /**
1472
     * @covers ::lti_tool_configuration_from_content_item()
1472
     * @covers ::lti_tool_configuration_from_content_item()
1473
     *
1473
     *
1474
     * Test adding a single gradable item through content item with an empty subreview url.
1474
     * Test adding a single gradable item through content item with an empty subreview url.
1475
     */
1475
     */
1476
    public function test_lti_tool_configuration_from_content_item_single_gradable_subreview_default_emptyurl() {
1476
    public function test_lti_tool_configuration_from_content_item_single_gradable_subreview_default_emptyurl(): void {
1477
        $this->resetAfterTest();
1477
        $this->resetAfterTest();
1478
        $this->setAdminUser();
1478
        $this->setAdminUser();
Línea 1479... Línea 1479...
1479
 
1479
 
1480
        $type = new \stdClass();
1480
        $type = new \stdClass();
Línea 1515... Línea 1515...
1515
    /**
1515
    /**
1516
     * @covers ::lti_tool_configuration_from_content_item()
1516
     * @covers ::lti_tool_configuration_from_content_item()
1517
     *
1517
     *
1518
     * Test adding a single gradable item through content item.
1518
     * Test adding a single gradable item through content item.
1519
     */
1519
     */
1520
    public function test_lti_tool_configuration_from_content_item_single_gradable_subreview_default() {
1520
    public function test_lti_tool_configuration_from_content_item_single_gradable_subreview_default(): void {
1521
        $this->resetAfterTest();
1521
        $this->resetAfterTest();
1522
        $this->setAdminUser();
1522
        $this->setAdminUser();
Línea 1523... Línea 1523...
1523
 
1523
 
1524
        $type = new \stdClass();
1524
        $type = new \stdClass();
Línea 1560... Línea 1560...
1560
    }
1560
    }
Línea 1561... Línea 1561...
1561
 
1561
 
1562
    /**
1562
    /**
1563
     * Test adding multiple gradable items through content item.
1563
     * Test adding multiple gradable items through content item.
1564
     */
1564
     */
1565
    public function test_lti_tool_configuration_from_content_item_multiple() {
1565
    public function test_lti_tool_configuration_from_content_item_multiple(): void {
1566
        $this->resetAfterTest();
1566
        $this->resetAfterTest();
Línea 1567... Línea 1567...
1567
        $this->setAdminUser();
1567
        $this->setAdminUser();
1568
 
1568
 
Línea 1624... Línea 1624...
1624
    }
1624
    }
Línea 1625... Línea 1625...
1625
 
1625
 
1626
    /**
1626
    /**
1627
     * Test adding a single non gradable item through content item.
1627
     * Test adding a single non gradable item through content item.
1628
     */
1628
     */
1629
    public function test_lti_tool_configuration_from_content_item_single() {
1629
    public function test_lti_tool_configuration_from_content_item_single(): void {
1630
        $this->resetAfterTest();
1630
        $this->resetAfterTest();
Línea 1631... Línea 1631...
1631
        $this->setAdminUser();
1631
        $this->setAdminUser();
1632
 
1632
 
Línea 1666... Línea 1666...
1666
    }
1666
    }
Línea 1667... Línea 1667...
1667
 
1667
 
1668
    /**
1668
    /**
1669
     * Test lti_sign_jwt().
1669
     * Test lti_sign_jwt().
1670
     */
1670
     */
1671
    public function test_lti_sign_jwt() {
1671
    public function test_lti_sign_jwt(): void {
Línea 1672... Línea 1672...
1672
        $this->resetAfterTest();
1672
        $this->resetAfterTest();
Línea 1673... Línea 1673...
1673
 
1673
 
Línea 1712... Línea 1712...
1712
    }
1712
    }
Línea 1713... Línea 1713...
1713
 
1713
 
1714
    /**
1714
    /**
1715
     * Test lti_convert_from_jwt()
1715
     * Test lti_convert_from_jwt()
1716
     */
1716
     */
1717
    public function test_lti_convert_from_jwt() {
1717
    public function test_lti_convert_from_jwt(): void {
Línea 1718... Línea 1718...
1718
        $this->resetAfterTest();
1718
        $this->resetAfterTest();
Línea 1719... Línea 1719...
1719
 
1719
 
Línea 1752... Línea 1752...
1752
    }
1752
    }
Línea 1753... Línea 1753...
1753
 
1753
 
1754
    /**
1754
    /**
1755
     * Test lti_get_permitted_service_scopes().
1755
     * Test lti_get_permitted_service_scopes().
1756
     */
1756
     */
1757
    public function test_lti_get_permitted_service_scopes() {
1757
    public function test_lti_get_permitted_service_scopes(): void {
Línea 1758... Línea 1758...
1758
        $this->resetAfterTest();
1758
        $this->resetAfterTest();
Línea 1759... Línea 1759...
1759
 
1759
 
Línea 1783... Línea 1783...
1783
    }
1783
    }
Línea 1784... Línea 1784...
1784
 
1784
 
1785
    /**
1785
    /**
1786
     * Test get_tool_type_config().
1786
     * Test get_tool_type_config().
1787
     */
1787
     */
1788
    public function test_get_tool_type_config() {
1788
    public function test_get_tool_type_config(): void {
Línea 1789... Línea 1789...
1789
        $this->resetAfterTest();
1789
        $this->resetAfterTest();
Línea 1790... Línea 1790...
1790
 
1790
 
Línea 1815... Línea 1815...
1815
    }
1815
    }
Línea 1816... Línea 1816...
1816
 
1816
 
1817
    /**
1817
    /**
1818
     * Test lti_new_access_token().
1818
     * Test lti_new_access_token().
1819
     */
1819
     */
1820
    public function test_lti_new_access_token() {
1820
    public function test_lti_new_access_token(): void {
Línea 1821... Línea 1821...
1821
        global $DB;
1821
        global $DB;
Línea 1822... Línea 1822...
1822
 
1822
 
Línea 1852... Línea 1852...
1852
    }
1852
    }
Línea 1853... Línea 1853...
1853
 
1853
 
1854
    /**
1854
    /**
1855
     * Test lti_build_login_request().
1855
     * Test lti_build_login_request().
1856
     */
1856
     */
1857
    public function test_lti_build_login_request() {
1857
    public function test_lti_build_login_request(): void {
Línea 1858... Línea 1858...
1858
        global $USER, $CFG;
1858
        global $USER, $CFG;
Línea 1859... Línea 1859...
1859
 
1859
 
Línea 1886... Línea 1886...
1886
    /**
1886
    /**
1887
     * @covers ::lti_get_launch_data()
1887
     * @covers ::lti_get_launch_data()
1888
     *
1888
     *
1889
     * Test for_user is passed as parameter when specified.
1889
     * Test for_user is passed as parameter when specified.
1890
     */
1890
     */
1891
    public function test_lti_get_launch_data_with_for_user() {
1891
    public function test_lti_get_launch_data_with_for_user(): void {
1892
        global $DB;
1892
        global $DB;
1893
        $this->resetAfterTest();
1893
        $this->resetAfterTest();
1894
        $this->setAdminUser();
1894
        $this->setAdminUser();
1895
        $config = new \stdClass();
1895
        $config = new \stdClass();
1896
        $config->lti_organizationid = '';
1896
        $config->lti_organizationid = '';
Línea 1903... Línea 1903...
1903
    }
1903
    }
Línea 1904... Línea 1904...
1904
 
1904
 
1905
    /**
1905
    /**
1906
     * Test default orgid is host if not specified in config (tool installed in earlier version of Moodle).
1906
     * Test default orgid is host if not specified in config (tool installed in earlier version of Moodle).
1907
     */
1907
     */
1908
    public function test_lti_get_launch_data_default_organizationid_unset_usehost() {
1908
    public function test_lti_get_launch_data_default_organizationid_unset_usehost(): void {
1909
        global $DB;
1909
        global $DB;
1910
        $this->resetAfterTest();
1910
        $this->resetAfterTest();
1911
        $this->setAdminUser();
1911
        $this->setAdminUser();
1912
        $config = new \stdClass();
1912
        $config = new \stdClass();
Línea 1919... Línea 1919...
1919
    }
1919
    }
Línea 1920... Línea 1920...
1920
 
1920
 
1921
    /**
1921
    /**
1922
     * Test default org id is set to host when config is usehost.
1922
     * Test default org id is set to host when config is usehost.
1923
     */
1923
     */
1924
    public function test_lti_get_launch_data_default_organizationid_set_usehost() {
1924
    public function test_lti_get_launch_data_default_organizationid_set_usehost(): void {
1925
        global $DB;
1925
        global $DB;
1926
        $this->resetAfterTest();
1926
        $this->resetAfterTest();
1927
        $this->setAdminUser();
1927
        $this->setAdminUser();
1928
        $config = new \stdClass();
1928
        $config = new \stdClass();
Línea 1936... Línea 1936...
1936
    }
1936
    }
Línea 1937... Línea 1937...
1937
 
1937
 
1938
    /**
1938
    /**
1939
     * Test default org id is set to site id when config is usesiteid.
1939
     * Test default org id is set to site id when config is usesiteid.
1940
     */
1940
     */
1941
    public function test_lti_get_launch_data_default_organizationid_set_usesiteid() {
1941
    public function test_lti_get_launch_data_default_organizationid_set_usesiteid(): void {
1942
        global $DB;
1942
        global $DB;
1943
        $this->resetAfterTest();
1943
        $this->resetAfterTest();
1944
        $this->setAdminUser();
1944
        $this->setAdminUser();
1945
        $config = new \stdClass();
1945
        $config = new \stdClass();
Línea 1953... Línea 1953...
1953
    }
1953
    }
Línea 1954... Línea 1954...
1954
 
1954
 
1955
    /**
1955
    /**
1956
     * Test orgid can be overridden in which case default is ignored.
1956
     * Test orgid can be overridden in which case default is ignored.
1957
     */
1957
     */
1958
    public function test_lti_get_launch_data_default_organizationid_orgid_override() {
1958
    public function test_lti_get_launch_data_default_organizationid_orgid_override(): void {
1959
        global $DB;
1959
        global $DB;
1960
        $this->resetAfterTest();
1960
        $this->resetAfterTest();
1961
        $this->setAdminUser();
1961
        $this->setAdminUser();
1962
        $config = new \stdClass();
1962
        $config = new \stdClass();
Línea 1967... Línea 1967...
1967
        $link = $this->create_instance($type, $course);
1967
        $link = $this->create_instance($type, $course);
1968
        $launchdata = lti_get_launch_data($link);
1968
        $launchdata = lti_get_launch_data($link);
1969
        $this->assertEquals($launchdata[1]['tool_consumer_instance_guid'], 'overridden!');
1969
        $this->assertEquals($launchdata[1]['tool_consumer_instance_guid'], 'overridden!');
1970
    }
1970
    }
Línea 1971... Línea 1971...
1971
 
1971
 
1972
    public function test_get_course_history() {
1972
    public function test_get_course_history(): void {
1973
        global $DB;
1973
        global $DB;
1974
        $this->resetAfterTest();
1974
        $this->resetAfterTest();
1975
        $this->setAdminUser();
1975
        $this->setAdminUser();
1976
        $parentparentcourse = $this->getDataGenerator()->create_course();
1976
        $parentparentcourse = $this->getDataGenerator()->create_course();
Línea 1997... Línea 1997...
1997
     * @param bool $islti2 whether the method is called with LTI 2.0 role names or not.
1997
     * @param bool $islti2 whether the method is called with LTI 2.0 role names or not.
1998
     * @param string $rolename the name of the role (student, teacher, admin)
1998
     * @param string $rolename the name of the role (student, teacher, admin)
1999
     * @param null|string $switchedto the role to switch to, or false if not using the 'switch to' functionality.
1999
     * @param null|string $switchedto the role to switch to, or false if not using the 'switch to' functionality.
2000
     * @param string $expected the expected role name.
2000
     * @param string $expected the expected role name.
2001
     */
2001
     */
2002
    public function test_lti_get_ims_role(bool $islti2, string $rolename, ?string $switchedto, string $expected) {
2002
    public function test_lti_get_ims_role(bool $islti2, string $rolename, ?string $switchedto, string $expected): void {
2003
        global $DB;
2003
        global $DB;
2004
        $this->resetAfterTest();
2004
        $this->resetAfterTest();
Línea 2005... Línea 2005...
2005
 
2005
 
2006
        $course = $this->getDataGenerator()->create_course();
2006
        $course = $this->getDataGenerator()->create_course();
Línea 2086... Línea 2086...
2086
    }
2086
    }
Línea 2087... Línea 2087...
2087
 
2087
 
2088
    /**
2088
    /**
2089
     * Test lti_get_lti_types_and_proxies with no limit or offset.
2089
     * Test lti_get_lti_types_and_proxies with no limit or offset.
2090
     */
2090
     */
2091
    public function test_lti_get_lti_types_and_proxies_with_no_limit() {
2091
    public function test_lti_get_lti_types_and_proxies_with_no_limit(): void {
2092
        $this->resetAfterTest();
2092
        $this->resetAfterTest();
2093
        $this->setAdminUser();
2093
        $this->setAdminUser();
2094
        $this->generate_tool_types_and_proxies(10);
2094
        $this->generate_tool_types_and_proxies(10);
Línea 2099... Línea 2099...
2099
    }
2099
    }
Línea 2100... Línea 2100...
2100
 
2100
 
2101
    /**
2101
    /**
2102
     * Test lti_get_lti_types_and_proxies with limits.
2102
     * Test lti_get_lti_types_and_proxies with limits.
2103
     */
2103
     */
2104
    public function test_lti_get_lti_types_and_proxies_with_limit() {
2104
    public function test_lti_get_lti_types_and_proxies_with_limit(): void {
2105
        $this->resetAfterTest();
2105
        $this->resetAfterTest();
2106
        $this->setAdminUser();
2106
        $this->setAdminUser();
Línea 2107... Línea 2107...
2107
        $this->generate_tool_types_and_proxies(10);
2107
        $this->generate_tool_types_and_proxies(10);
Línea 2126... Línea 2126...
2126
    }
2126
    }
Línea 2127... Línea 2127...
2127
 
2127
 
2128
    /**
2128
    /**
2129
     * Test lti_get_lti_types_and_proxies with limits and only fetching orphaned proxies.
2129
     * Test lti_get_lti_types_and_proxies with limits and only fetching orphaned proxies.
2130
     */
2130
     */
2131
    public function test_lti_get_lti_types_and_proxies_with_limit_and_orphaned_proxies() {
2131
    public function test_lti_get_lti_types_and_proxies_with_limit_and_orphaned_proxies(): void {
2132
        $this->resetAfterTest();
2132
        $this->resetAfterTest();
2133
        $this->setAdminUser();
2133
        $this->setAdminUser();
Línea 2134... Línea 2134...
2134
        $this->generate_tool_types_and_proxies(10, 5);
2134
        $this->generate_tool_types_and_proxies(10, 5);
Línea 2153... Línea 2153...
2153
    }
2153
    }
Línea 2154... Línea 2154...
2154
 
2154
 
2155
    /**
2155
    /**
2156
     * Test lti_get_lti_types_and_proxies_count.
2156
     * Test lti_get_lti_types_and_proxies_count.
2157
     */
2157
     */
2158
    public function test_lti_get_lti_types_and_proxies_count_with_no_filters() {
2158
    public function test_lti_get_lti_types_and_proxies_count_with_no_filters(): void {
2159
        $this->resetAfterTest();
2159
        $this->resetAfterTest();
2160
        $this->setAdminUser();
2160
        $this->setAdminUser();
Línea 2161... Línea 2161...
2161
        $this->generate_tool_types_and_proxies(10, 5);
2161
        $this->generate_tool_types_and_proxies(10, 5);
Línea 2165... Línea 2165...
2165
    }
2165
    }
Línea 2166... Línea 2166...
2166
 
2166
 
2167
    /**
2167
    /**
2168
     * Test lti_get_lti_types_and_proxies_count only counting orphaned proxies.
2168
     * Test lti_get_lti_types_and_proxies_count only counting orphaned proxies.
2169
     */
2169
     */
2170
    public function test_lti_get_lti_types_and_proxies_count_with_only_orphaned_proxies() {
2170
    public function test_lti_get_lti_types_and_proxies_count_with_only_orphaned_proxies(): void {
2171
        $this->resetAfterTest();
2171
        $this->resetAfterTest();
2172
        $this->setAdminUser();
2172
        $this->setAdminUser();
Línea 2173... Línea 2173...
2173
        $this->generate_tool_types_and_proxies(10, 5);
2173
        $this->generate_tool_types_and_proxies(10, 5);
Línea 2177... Línea 2177...
2177
    }
2177
    }
Línea 2178... Línea 2178...
2178
 
2178
 
2179
    /**
2179
    /**
2180
     * Test lti_get_lti_types_and_proxies_count only matching tool type with toolproxyid.
2180
     * Test lti_get_lti_types_and_proxies_count only matching tool type with toolproxyid.
2181
     */
2181
     */
2182
    public function test_lti_get_lti_types_and_proxies_count_type_with_proxyid() {
2182
    public function test_lti_get_lti_types_and_proxies_count_type_with_proxyid(): void {
2183
        $this->resetAfterTest();
2183
        $this->resetAfterTest();
2184
        $this->setAdminUser();
2184
        $this->setAdminUser();
Línea 2185... Línea 2185...
2185
        ['proxies' => $proxies, 'types' => $types] = $this->generate_tool_types_and_proxies(10, 5);
2185
        ['proxies' => $proxies, 'types' => $types] = $this->generate_tool_types_and_proxies(10, 5);
Línea 2191... Línea 2191...
2191
    /**
2191
    /**
2192
     * Verify that empty curl responses lead to the proper moodle_exception, not to XML ValueError.
2192
     * Verify that empty curl responses lead to the proper moodle_exception, not to XML ValueError.
2193
     *
2193
     *
2194
     * @covers ::lti_load_cartridge()
2194
     * @covers ::lti_load_cartridge()
2195
     */
2195
     */
2196
    public function test_empty_reponse_lti_load_cartridge() {
2196
    public function test_empty_reponse_lti_load_cartridge(): void {
2197
        // Mock the curl response to empty string, this is hardly
2197
        // Mock the curl response to empty string, this is hardly
2198
        // reproducible in real life (only Windows + GHA).
2198
        // reproducible in real life (only Windows + GHA).
2199
        \curl::mock_response('');
2199
        \curl::mock_response('');
Línea 2200... Línea 2200...
2200
 
2200