+
+ {{> mod_lti/loader }}
+
{{#str}} loadinghelp, moodle {{/str}}
+
{{#str}} register_warning, mod_lti {{/str}}
+
+
+
+
+
+
+{{#js}}
+ require(['jquery'], function($) {
+ var loadingContainer = $('.contentitem-loading-container');
+ var iframe = $('#contentitem-page-iframe');
+ var timeout = setTimeout(function () {
+ var failedContainer = $('#tool-loading-failed');
+ failedContainer.removeClass('hidden');
+ }, 20000);
+
+ // Submit form.
+ $('#contentitem-request-form').submit();
+
+ iframe.on('load', function() {
+ loadingContainer.addClass('hidden');
+ iframe.removeClass('hidden');
+
+ // Adjust iframe's width to the fit the container's width.
+ var containerWidth = $('div.contentitem-container').width();
+ $('#contentitem-page-iframe').attr('width', containerWidth);
+
+ var dialogueContentDiv = $('div.contentitem-container').parent();
+ var dialogueContainer = dialogueContentDiv.parent();
+ // Adjust iframe's height to container's height - 55px (dialogue title bar + top/bottom margins).
+ var containerHeight = dialogueContainer.height() - 55;
+ $('#contentitem-page-iframe').attr('height', containerHeight);
+ });
+ });
+{{/js}}
diff --git a/mod/lti/tests/behat/addtool.feature b/mod/lti/tests/behat/addtool.feature
index 8e51ddd95ba..0703fe66b1b 100644
--- a/mod/lti/tests/behat/addtool.feature
+++ b/mod/lti/tests/behat/addtool.feature
@@ -30,9 +30,15 @@ Feature: Add tools
When I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
- And I add a "Teaching Tool 1" to section "1" and I fill the form with:
- | Activity name | Test tool activity 1 |
- | Launch container | Embed |
+ And I add a "Teaching Tool 1" to section "1"
+ # For tool that does not support Content-Item message type, the Select content button must be disabled.
+ And the "Select content" "button" should be disabled
+ And I set the field "Activity name" to "Test tool activity 1"
+ And I click on "Show more..." "link"
+ And I set the field "Launch container" to "Embed"
+ And I press "Save and return to course"
And I open "Test tool activity 1" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Preconfigured tool" matches value "Teaching Tool 1"
+ # When editing settings, the Select content button should be disabled.
+ And the "Select content" "button" should be disabled
diff --git a/mod/lti/tests/behat/contentitem.feature b/mod/lti/tests/behat/contentitem.feature
new file mode 100644
index 00000000000..a0d50fe96ec
--- /dev/null
+++ b/mod/lti/tests/behat/contentitem.feature
@@ -0,0 +1,65 @@
+@mod @mod_lti @mod_lti_contentitem
+Feature: Content-Item support
+ In order to easily add activities and content in a course from an external tool
+ As a teacher
+ I need to utilise a tool that supports the Content-Item Message type
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | Terry1 | Teacher1 | teacher1@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And I log in as "admin"
+ And I navigate to "Manage tools" node in "Site administration > Plugins > Activity modules > External tool"
+ And I follow "configure a tool manually"
+ And I set the field "Tool name" to "Teaching Tool 1"
+ And I set the field "Tool base URL/cartridge URL" to local url "/mod/lti/tests/fixtures/tool_provider.php"
+ And I set the field "Tool configuration usage" to "Show in activity chooser and as a preconfigured tool"
+ And I expand all fieldsets
+ And I set the field "Content-Item Message" to "1"
+ And I press "Save changes"
+ And I log out
+
+ @javascript
+ Scenario: Tool that supports Content-Item Message type should be able to configure a tool via the Select content button
+ When I log in as "teacher1"
+ And I follow "Course 1"
+ And I turn editing mode on
+ And I add a "Teaching Tool 1" to section "1"
+ Then the "Select content" "button" should be enabled
+
+ @javascript
+ Scenario: Adding a preconfigured tool that does not support Content-Item.
+ When I log in as "teacher1"
+ And I follow "Course 1"
+ And I turn editing mode on
+ And I add a "Teaching Tool 1" to section "1"
+ And the "Select content" "button" should be enabled
+ And I set the field "Activity name" to "Test tool activity 1"
+ And I expand all fieldsets
+ And I set the field "Launch container" to "Embed"
+ And I press "Save and return to course"
+ And I open "Test tool activity 1" actions menu
+ And I follow "Edit settings" in the open menu
+ Then the field "Preconfigured tool" matches value "Teaching Tool 1"
+ # When editing settings, the Select content button should be disabled.
+ And the "Select content" "button" should be disabled
+
+ @javascript
+ Scenario: Selecting a preconfigured tool that supports Content-Item
+ When I log in as "teacher1"
+ And I follow "Course 1"
+ And I turn editing mode on
+ And I add a "External tool" to section "1"
+ And the field "Preconfigured tool" matches value "Automatic, based on launch URL"
+ And the "Select content" "button" should be disabled
+ And I set the field "Activity name" to "Test tool activity 1"
+ And I set the field "Preconfigured tool" to "Teaching Tool 1"
+ Then the "Select content" "button" should be enabled
+ And I set the field "Preconfigured tool" to "Automatic, based on launch URL"
+ And the "Select content" "button" should be disabled
diff --git a/mod/lti/tests/behat/contentitemregistration.feature b/mod/lti/tests/behat/contentitemregistration.feature
new file mode 100644
index 00000000000..af3cb38625c
--- /dev/null
+++ b/mod/lti/tests/behat/contentitemregistration.feature
@@ -0,0 +1,32 @@
+@mod @mod_lti @mod_lti_contentitem
+Feature: Content-Item support
+ In order to provide external tools that support the Content-Item Message type for teachers and learners
+ As an admin
+ I need to be able to configure external tool registrations that support the Content-Item Message type.
+
+ Background:
+ Given I log in as "admin"
+ And I navigate to "Manage tools" node in "Site administration > Plugins > Activity modules > External tool"
+
+ Scenario: Verifying ContentItemSelectionRequest selection support in external tool registration
+ When I follow "Manage external tool registrations"
+ And I follow "Configure a new external tool registration"
+ Then I should see "ContentItemSelectionRequest" in the "Capabilities" "select"
+
+ @javascript
+ Scenario: Creating and editing tool configuration that has Content-Item support
+ When I follow "configure a tool manually"
+ And I set the field "Tool name" to "Test tool"
+ And I set the field "Tool base URL/cartridge URL" to local url "/mod/lti/tests/fixtures/tool_provider.php"
+ And I set the field "Tool configuration usage" to "Show in activity chooser and as a preconfigured tool"
+ And I expand all fieldsets
+ And I set the field "Content-Item Message" to "1"
+ And I press "Save changes"
+ And I follow "Edit"
+ And I expand all fieldsets
+ Then the field "Content-Item Message" matches value "1"
+ And I set the field "Content-Item Message" to "0"
+ And I press "Save changes"
+ And I follow "Edit"
+ And I expand all fieldsets
+ And the field "Content-Item Message" matches value "0"
diff --git a/mod/lti/tests/locallib_test.php b/mod/lti/tests/locallib_test.php
index 399b429f713..07592fa804e 100644
--- a/mod/lti/tests/locallib_test.php
+++ b/mod/lti/tests/locallib_test.php
@@ -325,4 +325,161 @@ class mod_lti_locallib_testcase extends advanced_testcase {
$this->assertEquals('http://download.moodle.org/unittest/test.jpg', $lti->icon);
$this->assertEquals('https://download.moodle.org/unittest/test.jpg', $lti->secureicon);
}
+
+ /**
+ * Tests for lti_build_content_item_selection_request().
+ */
+ public function test_lti_build_content_item_selection_request() {
+ $this->resetAfterTest();
+
+ $this->setAdminUser();
+ // Create a tool proxy.
+ $proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
+
+ // Create a tool type, associated with that proxy.
+ $type = new stdClass();
+ $data = new stdClass();
+ $data->lti_contentitem = true;
+ $type->state = LTI_TOOL_STATE_CONFIGURED;
+ $type->name = "Test tool";
+ $type->description = "Example description";
+ $type->toolproxyid = $proxy->id;
+ $type->baseurl = $this->getExternalTestFileUrl('/test.html');
+
+ $typeid = lti_add_type($type, $data);
+
+ $typeconfig = lti_get_type_config($typeid);
+
+ $course = $this->getDataGenerator()->create_course();
+ $returnurl = new moodle_url('/');
+
+ // Default parameters.
+ $result = lti_build_content_item_selection_request($typeid, $course, $returnurl);
+ $this->assertNotEmpty($result);
+ $this->assertNotEmpty($result->params);
+ $this->assertNotEmpty($result->url);
+ $params = $result->params;
+ $url = $result->url;
+ $this->assertEquals($typeconfig['toolurl'], $url);
+ $this->assertEquals('ContentItemSelectionRequest', $params['lti_message_type']);
+ $this->assertEquals(LTI_VERSION_2, $params['lti_version']);
+ $this->assertEquals('application/vnd.ims.lti.v1.ltilink', $params['accept_media_types']);
+ $this->assertEquals('frame,iframe,window', $params['accept_presentation_document_targets']);
+ $this->assertEquals($returnurl->out(false), $params['content_item_return_url']);
+ $this->assertEquals('false', $params['accept_unsigned']);
+ $this->assertEquals('false', $params['accept_multiple']);
+ $this->assertEquals('false', $params['accept_copy_advice']);
+ $this->assertEquals('false', $params['auto_create']);
+ $this->assertEquals($type->name, $params['title']);
+ $this->assertFalse(isset($params['resource_link_id']));
+ $this->assertFalse(isset($params['resource_link_title']));
+ $this->assertFalse(isset($params['resource_link_description']));
+ $this->assertFalse(isset($params['launch_presentation_return_url']));
+ $this->assertFalse(isset($params['lis_result_sourcedid']));
+
+ // Custom parameters.
+ $title = 'My custom title';
+ $text = 'This is the tool description';
+ $mediatypes = ['image/*', 'video/*'];
+ $targets = ['embed', 'iframe'];
+ $result = lti_build_content_item_selection_request($typeid, $course, $returnurl, $title, $text, $mediatypes, $targets,
+ true, true, true, true, true);
+ $this->assertNotEmpty($result);
+ $this->assertNotEmpty($result->params);
+ $this->assertNotEmpty($result->url);
+ $params = $result->params;
+ $this->assertEquals(implode(',', $mediatypes), $params['accept_media_types']);
+ $this->assertEquals(implode(',', $targets), $params['accept_presentation_document_targets']);
+ $this->assertEquals('true', $params['accept_unsigned']);
+ $this->assertEquals('true', $params['accept_multiple']);
+ $this->assertEquals('true', $params['accept_copy_advice']);
+ $this->assertEquals('true', $params['auto_create']);
+ $this->assertEquals($title, $params['title']);
+ $this->assertEquals($text, $params['text']);
+
+ // Invalid flag values.
+ $result = lti_build_content_item_selection_request($typeid, $course, $returnurl, $title, $text, $mediatypes, $targets,
+ 'aa', -1, 0, 1, 0xabc);
+ $this->assertNotEmpty($result);
+ $this->assertNotEmpty($result->params);
+ $this->assertNotEmpty($result->url);
+ $params = $result->params;
+ $this->assertEquals(implode(',', $mediatypes), $params['accept_media_types']);
+ $this->assertEquals(implode(',', $targets), $params['accept_presentation_document_targets']);
+ $this->assertEquals('false', $params['accept_unsigned']);
+ $this->assertEquals('false', $params['accept_multiple']);
+ $this->assertEquals('false', $params['accept_copy_advice']);
+ $this->assertEquals('false', $params['auto_create']);
+ $this->assertEquals($title, $params['title']);
+ $this->assertEquals($text, $params['text']);
+ }
+
+ /**
+ * Test for lti_build_content_item_selection_request() with nonexistent tool type ID parameter.
+ */
+ public function test_lti_build_content_item_selection_request_invalid_tooltype() {
+ $this->resetAfterTest();
+
+ $this->setAdminUser();
+ $course = $this->getDataGenerator()->create_course();
+ $returnurl = new moodle_url('/');
+
+ // Should throw Exception on non-existent tool type.
+ $this->expectException('moodle_exception');
+ lti_build_content_item_selection_request(1, $course, $returnurl);
+ }
+
+ /**
+ * Test for lti_build_content_item_selection_request() with invalid media types parameter.
+ */
+ public function test_lti_build_content_item_selection_request_invalid_mediatypes() {
+ $this->resetAfterTest();
+
+ $this->setAdminUser();
+
+ // Create a tool type, associated with that proxy.
+ $type = new stdClass();
+ $data = new stdClass();
+ $data->lti_contentitem = true;
+ $type->state = LTI_TOOL_STATE_CONFIGURED;
+ $type->name = "Test tool";
+ $type->description = "Example description";
+ $type->baseurl = $this->getExternalTestFileUrl('/test.html');
+
+ $typeid = lti_add_type($type, $data);
+ $course = $this->getDataGenerator()->create_course();
+ $returnurl = new moodle_url('/');
+
+ // Should throw coding_exception on non-array media types.
+ $mediatypes = 'image/*,video/*';
+ $this->expectException('coding_exception');
+ lti_build_content_item_selection_request($typeid, $course, $returnurl, '', '', $mediatypes);
+ }
+
+ /**
+ * Test for lti_build_content_item_selection_request() with invalid presentation targets parameter.
+ */
+ public function test_lti_build_content_item_selection_request_invalid_presentationtargets() {
+ $this->resetAfterTest();
+
+ $this->setAdminUser();
+
+ // Create a tool type, associated with that proxy.
+ $type = new stdClass();
+ $data = new stdClass();
+ $data->lti_contentitem = true;
+ $type->state = LTI_TOOL_STATE_CONFIGURED;
+ $type->name = "Test tool";
+ $type->description = "Example description";
+ $type->baseurl = $this->getExternalTestFileUrl('/test.html');
+
+ $typeid = lti_add_type($type, $data);
+ $course = $this->getDataGenerator()->create_course();
+ $returnurl = new moodle_url('/');
+
+ // Should throw coding_exception on non-array presentation targets.
+ $targets = 'frame,iframe';
+ $this->expectException('coding_exception');
+ lti_build_content_item_selection_request($typeid, $course, $returnurl, '', '', [], $targets);
+ }
}
diff --git a/mod/lti/version.php b/mod/lti/version.php
index ce66b5156dd..5549b1f5975 100644
--- a/mod/lti/version.php
+++ b/mod/lti/version.php
@@ -48,7 +48,7 @@
defined('MOODLE_INTERNAL') || die;
-$plugin->version = 2016052300; // The current module version (Date: YYYYMMDDXX).
+$plugin->version = 2016052301; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2016051900; // Requires this Moodle version.
$plugin->component = 'mod_lti'; // Full name of the plugin (used for diagnostics).
$plugin->cron = 0;