MDL-69319 mod_lti: move test data generation out of common setup
[moodle.git] / mod / lti / tests / externallib_test.php
CommitLineData
d5ded9e7
JL
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * External tool module external functions tests
19 *
20 * @package mod_lti
21 * @category external
22 * @copyright 2015 Juan Leyva <juan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @since Moodle 3.0
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30
31require_once($CFG->dirroot . '/webservice/tests/helpers.php');
32require_once($CFG->dirroot . '/mod/lti/lib.php');
33
34/**
35 * External tool module external functions tests
36 *
37 * @package mod_lti
38 * @category external
39 * @copyright 2015 Juan Leyva <juan@moodle.com>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 * @since Moodle 3.0
42 */
43class mod_lti_external_testcase extends externallib_advanced_testcase {
44
45 /**
46 * Set up for every test
47 */
48 public function setUp() {
d5ded9e7 49 $this->resetAfterTest();
7c7c5286
JD
50 }
51
52 /**
53 * Sets up some basic test data including course, users, roles, and an lti instance, for use in some tests.
54 * @return array
55 */
56 protected function setup_test_data() {
57 global $DB;
d5ded9e7
JL
58 $this->setAdminUser();
59
60 // Setup test data.
7c7c5286
JD
61 $course = $this->getDataGenerator()->create_course();
62 $lti = $this->getDataGenerator()->create_module(
63 'lti',
64 ['course' => $course->id, 'toolurl' => 'http://localhost/not/real/tool.php']
65 );
66 $context = context_module::instance($lti->cmid);
67 $cm = get_coursemodule_from_instance('lti', $lti->id);
d5ded9e7
JL
68
69 // Create users.
7c7c5286
JD
70 $student = self::getDataGenerator()->create_user();
71 $teacher = self::getDataGenerator()->create_user();
d5ded9e7
JL
72
73 // Users enrolments.
7c7c5286
JD
74 $studentrole = $DB->get_record('role', array('shortname' => 'student'));
75 $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
76 $this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id, 'manual');
77 $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id, 'manual');
78
79 return [
80 'course' => $course,
81 'lti' => $lti,
82 'context' => $context,
83 'cm' => $cm,
84 'student' => $student,
85 'teacher' => $teacher,
86 'studentrole' => $studentrole,
87 'teacherrole' => $teacherrole
88 ];
d5ded9e7
JL
89 }
90
91 /**
92 * Test view_lti
93 */
94 public function test_get_tool_launch_data() {
7204d77b
JO
95 global $USER, $SITE;
96
7c7c5286
JD
97 [
98 'course' => $course,
99 'lti' => $lti
100 ] = $this->setup_test_data();
101
102 $result = mod_lti_external::get_tool_launch_data($lti->id);
d5ded9e7
JL
103 $result = external_api::clean_returnvalue(mod_lti_external::get_tool_launch_data_returns(), $result);
104
105 // Basic test, the function returns what it's expected.
7c7c5286 106 self::assertEquals($lti->toolurl, $result['endpoint']);
7204d77b 107 self::assertCount(36, $result['parameters']);
d5ded9e7
JL
108
109 // Check some parameters.
110 $parameters = array();
111 foreach ($result['parameters'] as $param) {
112 $parameters[$param['name']] = $param['value'];
113 }
7c7c5286
JD
114 self::assertEquals($lti->resourcekey, $parameters['oauth_consumer_key']);
115 self::assertEquals($course->fullname, $parameters['context_title']);
116 self::assertEquals($course->shortname, $parameters['context_label']);
d5ded9e7
JL
117 self::assertEquals($USER->id, $parameters['user_id']);
118 self::assertEquals($USER->firstname, $parameters['lis_person_name_given']);
119 self::assertEquals($USER->lastname, $parameters['lis_person_name_family']);
120 self::assertEquals(fullname($USER), $parameters['lis_person_name_full']);
121 self::assertEquals($USER->username, $parameters['ext_user_username']);
2a5bb939
JO
122 self::assertEquals("phpunit", $parameters['tool_consumer_instance_name']);
123 self::assertEquals("PHPUnit test site", $parameters['tool_consumer_instance_description']);
d5ded9e7
JL
124
125 }
126
dfcdec12
JL
127 /*
128 * Test get ltis by courses
129 */
130 public function test_mod_lti_get_ltis_by_courses() {
131 global $DB;
132
7c7c5286
JD
133 [
134 'course' => $course,
135 'lti' => $lti,
136 'student' => $student,
137 'teacher' => $teacher,
138 'studentrole' => $studentrole,
139 ] = $this->setup_test_data();
140
dfcdec12
JL
141 // Create additional course.
142 $course2 = self::getDataGenerator()->create_course();
143
144 // Second lti.
145 $record = new stdClass();
146 $record->course = $course2->id;
147 $lti2 = self::getDataGenerator()->create_module('lti', $record);
148
149 // Execute real Moodle enrolment as we'll call unenrol() method on the instance later.
150 $enrol = enrol_get_plugin('manual');
151 $enrolinstances = enrol_get_instances($course2->id, true);
152 foreach ($enrolinstances as $courseenrolinstance) {
153 if ($courseenrolinstance->enrol == "manual") {
154 $instance2 = $courseenrolinstance;
155 break;
156 }
157 }
7c7c5286 158 $enrol->enrol_user($instance2, $student->id, $studentrole->id);
dfcdec12 159
7c7c5286 160 self::setUser($student);
dfcdec12
JL
161
162 $returndescription = mod_lti_external::get_ltis_by_courses_returns();
163
164 // Create what we expect to be returned when querying the two courses.
165 // First for the student user.
7ef49bd3 166 $expectedfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles', 'launchcontainer',
dfcdec12
JL
167 'showtitlelaunch', 'showdescriptionlaunch', 'icon', 'secureicon');
168
169 // Add expected coursemodule and data.
7c7c5286 170 $lti1 = $lti;
dfcdec12
JL
171 $lti1->coursemodule = $lti1->cmid;
172 $lti1->introformat = 1;
173 $lti1->section = 0;
174 $lti1->visible = true;
175 $lti1->groupmode = 0;
176 $lti1->groupingid = 0;
7ef49bd3 177 $lti1->introfiles = [];
dfcdec12
JL
178
179 $lti2->coursemodule = $lti2->cmid;
180 $lti2->introformat = 1;
181 $lti2->section = 0;
182 $lti2->visible = true;
183 $lti2->groupmode = 0;
184 $lti2->groupingid = 0;
7ef49bd3 185 $lti2->introfiles = [];
dfcdec12
JL
186
187 foreach ($expectedfields as $field) {
188 $expected1[$field] = $lti1->{$field};
189 $expected2[$field] = $lti2->{$field};
190 }
191
192 $expectedltis = array($expected2, $expected1);
193
194 // Call the external function passing course ids.
7c7c5286 195 $result = mod_lti_external::get_ltis_by_courses(array($course2->id, $course->id));
dfcdec12
JL
196 $result = external_api::clean_returnvalue($returndescription, $result);
197
198 $this->assertEquals($expectedltis, $result['ltis']);
199 $this->assertCount(0, $result['warnings']);
200
201 // Call the external function without passing course id.
202 $result = mod_lti_external::get_ltis_by_courses();
203 $result = external_api::clean_returnvalue($returndescription, $result);
204 $this->assertEquals($expectedltis, $result['ltis']);
205 $this->assertCount(0, $result['warnings']);
206
207 // Unenrol user from second course and alter expected ltis.
7c7c5286 208 $enrol->unenrol_user($instance2, $student->id);
dfcdec12
JL
209 array_shift($expectedltis);
210
211 // Call the external function without passing course id.
212 $result = mod_lti_external::get_ltis_by_courses();
213 $result = external_api::clean_returnvalue($returndescription, $result);
214 $this->assertEquals($expectedltis, $result['ltis']);
215
216 // Call for the second course we unenrolled the user from, expected warning.
217 $result = mod_lti_external::get_ltis_by_courses(array($course2->id));
261400d4 218 $result = external_api::clean_returnvalue($returndescription, $result);
dfcdec12
JL
219 $this->assertCount(1, $result['warnings']);
220 $this->assertEquals('1', $result['warnings'][0]['warningcode']);
221 $this->assertEquals($course2->id, $result['warnings'][0]['itemid']);
222
223 // Now, try as a teacher for getting all the additional fields.
7c7c5286 224 self::setUser($teacher);
dfcdec12
JL
225
226 $additionalfields = array('timecreated', 'timemodified', 'typeid', 'toolurl', 'securetoolurl',
227 'instructorchoicesendname', 'instructorchoicesendemailaddr', 'instructorchoiceallowroster',
228 'instructorchoiceallowsetting', 'instructorcustomparameters', 'instructorchoiceacceptgrades', 'grade',
229 'resourcekey', 'password', 'debuglaunch', 'servicesalt', 'visible', 'groupmode', 'groupingid');
230
231 foreach ($additionalfields as $field) {
232 $expectedltis[0][$field] = $lti1->{$field};
233 }
234
235 $result = mod_lti_external::get_ltis_by_courses();
236 $result = external_api::clean_returnvalue($returndescription, $result);
237 $this->assertEquals($expectedltis, $result['ltis']);
238
239 // Admin also should get all the information.
240 self::setAdminUser();
241
7c7c5286 242 $result = mod_lti_external::get_ltis_by_courses(array($course->id));
dfcdec12
JL
243 $result = external_api::clean_returnvalue($returndescription, $result);
244 $this->assertEquals($expectedltis, $result['ltis']);
245
246 // Now, prohibit capabilities.
7c7c5286
JD
247 $this->setUser($student);
248 $contextcourse1 = context_course::instance($course->id);
dfcdec12 249 // Prohibit capability = mod:lti:view on Course1 for students.
7c7c5286 250 assign_capability('mod/lti:view', CAP_PROHIBIT, $studentrole->id, $contextcourse1->id);
0bf6c0be 251 // Empty all the caches that may be affected by this change.
dfcdec12 252 accesslib_clear_all_caches_for_unit_testing();
0bf6c0be 253 course_modinfo::clear_instance_cache();
dfcdec12 254
7c7c5286 255 $ltis = mod_lti_external::get_ltis_by_courses(array($course->id));
dfcdec12 256 $ltis = external_api::clean_returnvalue(mod_lti_external::get_ltis_by_courses_returns(), $ltis);
0bf6c0be 257 $this->assertCount(0, $ltis['ltis']);
dfcdec12
JL
258 }
259
4bed1682
JL
260 /**
261 * Test view_lti
262 */
263 public function test_view_lti() {
264 global $DB;
265
7c7c5286
JD
266 [
267 'lti' => $lti,
268 'context' => $context,
269 'cm' => $cm,
270 'student' => $student,
271 'studentrole' => $studentrole,
272 ] = $this->setup_test_data();
273
4bed1682
JL
274 // Test invalid instance id.
275 try {
276 mod_lti_external::view_lti(0);
277 $this->fail('Exception expected due to invalid mod_lti instance id.');
278 } catch (moodle_exception $e) {
279 $this->assertEquals('invalidrecord', $e->errorcode);
280 }
281
282 // Test not-enrolled user.
283 $usernotenrolled = self::getDataGenerator()->create_user();
284 $this->setUser($usernotenrolled);
285 try {
7c7c5286 286 mod_lti_external::view_lti($lti->id);
4bed1682
JL
287 $this->fail('Exception expected due to not enrolled user.');
288 } catch (moodle_exception $e) {
289 $this->assertEquals('requireloginerror', $e->errorcode);
290 }
291
292 // Test user with full capabilities.
7c7c5286 293 $this->setUser($student);
4bed1682
JL
294
295 // Trigger and capture the event.
296 $sink = $this->redirectEvents();
297
7c7c5286 298 $result = mod_lti_external::view_lti($lti->id);
4bed1682
JL
299 $result = external_api::clean_returnvalue(mod_lti_external::view_lti_returns(), $result);
300
301 $events = $sink->get_events();
302 $this->assertCount(1, $events);
303 $event = array_shift($events);
304
305 // Checking that the event contains the expected values.
306 $this->assertInstanceOf('\mod_lti\event\course_module_viewed', $event);
7c7c5286
JD
307 $this->assertEquals($context, $event->get_context());
308 $moodlelti = new \moodle_url('/mod/lti/view.php', array('id' => $cm->id));
4bed1682
JL
309 $this->assertEquals($moodlelti, $event->get_url());
310 $this->assertEventContextNotUsed($event);
311 $this->assertNotEmpty($event->get_name());
312
313 // Test user with no capabilities.
314 // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
7c7c5286 315 assign_capability('mod/lti:view', CAP_PROHIBIT, $studentrole->id, $context->id);
0bf6c0be 316 // Empty all the caches that may be affected by this change.
4bed1682 317 accesslib_clear_all_caches_for_unit_testing();
0bf6c0be 318 course_modinfo::clear_instance_cache();
4bed1682
JL
319
320 try {
7c7c5286 321 mod_lti_external::view_lti($lti->id);
4bed1682
JL
322 $this->fail('Exception expected due to missing capability.');
323 } catch (moodle_exception $e) {
0bf6c0be 324 $this->assertEquals('requireloginerror', $e->errorcode);
4bed1682
JL
325 }
326
327 }
328
af9d3a92
JO
329 /*
330 * Test create tool proxy
331 */
332 public function test_mod_lti_create_tool_proxy() {
7c7c5286 333 $this->setAdminUser();
eb55f72d
JP
334 $capabilities = ['AA', 'BB'];
335 $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), $capabilities, []);
261400d4
JD
336 $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
337
af9d3a92
JO
338 $this->assertEquals('Test proxy', $proxy->name);
339 $this->assertEquals($this->getExternalTestFileUrl('/test.html'), $proxy->regurl);
340 $this->assertEquals(LTI_TOOL_PROXY_STATE_PENDING, $proxy->state);
eb55f72d 341 $this->assertEquals(implode("\n", $capabilities), $proxy->capabilityoffered);
af9d3a92
JO
342 }
343
344 /*
345 * Test create tool proxy with duplicate url
346 */
347 public function test_mod_lti_create_tool_proxy_duplicateurl() {
7c7c5286 348 $this->setAdminUser();
52f3e060 349 $this->expectException('moodle_exception');
af9d3a92
JO
350 $proxy = mod_lti_external::create_tool_proxy('Test proxy 1', $this->getExternalTestFileUrl('/test.html'), array(), array());
351 $proxy = mod_lti_external::create_tool_proxy('Test proxy 2', $this->getExternalTestFileUrl('/test.html'), array(), array());
352 }
353
354 /*
355 * Test create tool proxy without sufficient capability
356 */
357 public function test_mod_lti_create_tool_proxy_without_capability() {
7c7c5286
JD
358 $course = $this->getDataGenerator()->create_course();
359 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
360 $this->setUser($teacher);
52f3e060 361 $this->expectException('required_capability_exception');
af9d3a92
JO
362 $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
363 }
364
365 /*
366 * Test delete tool proxy
367 */
368 public function test_mod_lti_delete_tool_proxy() {
7c7c5286 369 $this->setAdminUser();
af9d3a92 370 $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
261400d4 371 $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
af9d3a92
JO
372 $this->assertNotEmpty(lti_get_tool_proxy($proxy->id));
373
374 $proxy = mod_lti_external::delete_tool_proxy($proxy->id);
261400d4
JD
375 $proxy = (object) external_api::clean_returnvalue(mod_lti_external::delete_tool_proxy_returns(), $proxy);
376
af9d3a92
JO
377 $this->assertEquals('Test proxy', $proxy->name);
378 $this->assertEquals($this->getExternalTestFileUrl('/test.html'), $proxy->regurl);
379 $this->assertEquals(LTI_TOOL_PROXY_STATE_PENDING, $proxy->state);
380 $this->assertEmpty(lti_get_tool_proxy($proxy->id));
381 }
382
383 /*
384 * Test get tool proxy registration request
385 */
386 public function test_mod_lti_get_tool_proxy_registration_request() {
7c7c5286 387 $this->setAdminUser();
af9d3a92 388 $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
261400d4
JD
389 $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
390
af9d3a92 391 $request = mod_lti_external::get_tool_proxy_registration_request($proxy->id);
261400d4
JD
392 $request = external_api::clean_returnvalue(mod_lti_external::get_tool_proxy_registration_request_returns(),
393 $request);
394
af9d3a92
JO
395 $this->assertEquals('ToolProxyRegistrationRequest', $request['lti_message_type']);
396 $this->assertEquals('LTI-2p0', $request['lti_version']);
397 }
398
399 /*
400 * Test get tool types
401 */
402 public function test_mod_lti_get_tool_types() {
403 // Create a tool proxy.
7c7c5286 404 $this->setAdminUser();
af9d3a92 405 $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
261400d4 406 $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
af9d3a92
JO
407
408 // Create a tool type, associated with that proxy.
409 $type = new stdClass();
410 $data = new stdClass();
411 $type->state = LTI_TOOL_STATE_CONFIGURED;
412 $type->name = "Test tool";
413 $type->description = "Example description";
414 $type->toolproxyid = $proxy->id;
415 $type->baseurl = $this->getExternalTestFileUrl('/test.html');
416 $typeid = lti_add_type($type, $data);
417
418 $types = mod_lti_external::get_tool_types($proxy->id);
261400d4
JD
419 $types = external_api::clean_returnvalue(mod_lti_external::get_tool_types_returns(), $types);
420
af9d3a92
JO
421 $this->assertEquals(1, count($types));
422 $type = $types[0];
423 $this->assertEquals('Test tool', $type['name']);
424 $this->assertEquals('Example description', $type['description']);
425 }
426
427 /*
428 * Test create tool type
429 */
430 public function test_mod_lti_create_tool_type() {
7c7c5286 431 $this->setAdminUser();
af9d3a92 432 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
261400d4
JD
433 $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
434
af9d3a92
JO
435 $this->assertEquals('Example tool', $type['name']);
436 $this->assertEquals('Example tool description', $type['description']);
a6529e04 437 $this->assertEquals('https://download.moodle.org/unittest/test.jpg', $type['urls']['icon']);
af9d3a92
JO
438 $typeentry = lti_get_type($type['id']);
439 $this->assertEquals('http://www.example.com/lti/provider.php', $typeentry->baseurl);
440 $config = lti_get_type_config($type['id']);
441 $this->assertTrue(isset($config['sendname']));
442 $this->assertTrue(isset($config['sendemailaddr']));
443 $this->assertTrue(isset($config['acceptgrades']));
444 $this->assertTrue(isset($config['forcessl']));
445 }
446
447 /*
448 * Test create tool type failure from non existant file
449 */
450 public function test_mod_lti_create_tool_type_nonexistant_file() {
52f3e060 451 $this->expectException('moodle_exception');
af9d3a92
JO
452 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/doesntexist.xml'), '', '');
453 }
454
455 /*
456 * Test create tool type failure from xml that is not a cartridge
457 */
458 public function test_mod_lti_create_tool_type_bad_file() {
52f3e060 459 $this->expectException('moodle_exception');
af9d3a92
JO
460 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/rsstest.xml'), '', '');
461 }
462
463 /*
464 * Test creating of tool types without sufficient capability
465 */
466 public function test_mod_lti_create_tool_type_without_capability() {
7c7c5286
JD
467 $course = $this->getDataGenerator()->create_course();
468 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
469 $this->setUser($teacher);
52f3e060 470 $this->expectException('required_capability_exception');
af9d3a92
JO
471 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
472 }
473
474 /*
475 * Test update tool type
476 */
477 public function test_mod_lti_update_tool_type() {
7c7c5286 478 $this->setAdminUser();
af9d3a92 479 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
261400d4
JD
480 $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
481
af9d3a92 482 $type = mod_lti_external::update_tool_type($type['id'], 'New name', 'New description', LTI_TOOL_STATE_PENDING);
261400d4
JD
483 $type = external_api::clean_returnvalue(mod_lti_external::update_tool_type_returns(), $type);
484
af9d3a92
JO
485 $this->assertEquals('New name', $type['name']);
486 $this->assertEquals('New description', $type['description']);
487 $this->assertEquals('Pending', $type['state']['text']);
488 }
489
490 /*
491 * Test delete tool type
492 */
493 public function test_mod_lti_delete_tool_type() {
7c7c5286 494 $this->setAdminUser();
af9d3a92 495 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
261400d4 496 $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
af9d3a92 497 $this->assertNotEmpty(lti_get_type($type['id']));
261400d4 498
af9d3a92 499 $type = mod_lti_external::delete_tool_type($type['id']);
261400d4 500 $type = external_api::clean_returnvalue(mod_lti_external::delete_tool_type_returns(), $type);
af9d3a92
JO
501 $this->assertEmpty(lti_get_type($type['id']));
502 }
503
504 /*
505 * Test delete tool type without sufficient capability
506 */
507 public function test_mod_lti_delete_tool_type_without_capability() {
7c7c5286 508 $this->setAdminUser();
af9d3a92 509 $type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
261400d4 510 $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
af9d3a92 511 $this->assertNotEmpty(lti_get_type($type['id']));
52f3e060 512 $this->expectException('required_capability_exception');
7c7c5286
JD
513 $course = $this->getDataGenerator()->create_course();
514 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
515 $this->setUser($teacher);
af9d3a92
JO
516 $type = mod_lti_external::delete_tool_type($type['id']);
517 }
518
519 /*
520 * Test is cartridge
521 */
522 public function test_mod_lti_is_cartridge() {
7c7c5286 523 $this->setAdminUser();
af9d3a92 524 $result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'));
261400d4 525 $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
af9d3a92 526 $this->assertTrue($result['iscartridge']);
261400d4 527
af9d3a92 528 $result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/test.html'));
261400d4 529 $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
af9d3a92
JO
530 $this->assertFalse($result['iscartridge']);
531 }
d5ded9e7 532}