Merge branch 'MDL-67695-master_get_lti_proxies' of https://github.com/andrewmadden/moodle

This commit is contained in:
Jake Dallimore 2020-10-20 11:08:16 +08:00
commit 6325f848d8
4 changed files with 78 additions and 6 deletions

View file

@ -138,22 +138,18 @@ class mod_lti_external extends external_api {
* @throws moodle_exception * @throws moodle_exception
*/ */
public static function get_tool_proxies($orphanedonly) { public static function get_tool_proxies($orphanedonly) {
global $PAGE;
$params = self::validate_parameters(self::get_tool_proxies_parameters(), $params = self::validate_parameters(self::get_tool_proxies_parameters(),
array( array(
'orphanedonly' => $orphanedonly 'orphanedonly' => $orphanedonly
)); ));
$orphanedonly = $params['orphanedonly']; $orphanedonly = $params['orphanedonly'];
$proxies = array();
$context = context_system::instance(); $context = context_system::instance();
self::validate_context($context); self::validate_context($context);
require_capability('moodle/site:config', $context); require_capability('moodle/site:config', $context);
$proxies = lti_get_tool_proxies($orphanedonly); return lti_get_tool_proxies($orphanedonly);
return array_map('serialise_tool_proxy', $proxies);
} }
/** /**
@ -164,7 +160,7 @@ class mod_lti_external extends external_api {
*/ */
public static function get_tool_proxies_returns() { public static function get_tool_proxies_returns() {
return new external_multiple_structure( return new external_multiple_structure(
self::tool_type_return_structure() self::tool_proxy_return_structure()
); );
} }

View file

@ -4173,9 +4173,14 @@ function serialise_tool_type(stdClass $type) {
* *
* @param stdClass $proxy The tool proxy * @param stdClass $proxy The tool proxy
* *
* @deprecated since Moodle 3.10
* @todo This will be finally removed for Moodle 4.2 as part of MDL-69976.
* @return array An array of values representing this type * @return array An array of values representing this type
*/ */
function serialise_tool_proxy(stdClass $proxy) { function serialise_tool_proxy(stdClass $proxy) {
$deprecatedtext = __FUNCTION__ . '() is deprecated. Please remove all references to this method.';
debugging($deprecatedtext, DEBUG_DEVELOPER);
return array( return array(
'id' => $proxy->id, 'id' => $proxy->id,
'name' => $proxy->name, 'name' => $proxy->name,

View file

@ -88,6 +88,75 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
]; ];
} }
/**
* Generate a tool type.
*
* @param string $uniqueid Each tool type needs a different base url. Provide a unique string for every tool type created.
* @param int|null $toolproxyid Optional proxy to associate with tool type.
* @return stdClass A tool type.
*/
protected function generate_tool_type(string $uniqueid, int $toolproxyid = null) : stdClass {
// Create a tool type.
$type = new stdClass();
$type->state = LTI_TOOL_STATE_CONFIGURED;
$type->name = "Test tool $uniqueid";
$type->description = "Example description $uniqueid";
$type->toolproxyid = $toolproxyid;
$type->baseurl = $this->getExternalTestFileUrl("/test$uniqueid.html");
lti_add_type($type, new stdClass());
return $type;
}
/**
* Generate a tool proxy.
*
* @param string $uniqueid Each tool proxy needs a different reg url. Provide a unique string for every tool proxy created.
* @return stdClass A tool proxy.
*/
protected function generate_tool_proxy(string $uniqueid) : stdClass {
// Create a tool proxy.
$proxy = mod_lti_external::create_tool_proxy("Test proxy $uniqueid",
$this->getExternalTestFileUrl("/proxy$uniqueid.html"), array(), array());
$proxy = (object)external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
return $proxy;
}
/**
* Test get_tool_proxies.
*/
public function test_mod_lti_get_tool_proxies() {
// Create two tool proxies. One to associate with tool, and one to leave orphaned.
$this->setAdminUser();
$proxy = $this->generate_tool_proxy("1");
$orphanedproxy = $this->generate_tool_proxy("2");
$this->generate_tool_type("1", $proxy->id); // Associate proxy 1 with tool type.
// Fetch all proxies.
$proxies = mod_lti_external::get_tool_proxies(false);
$proxies = external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
$this->assertCount(2, $proxies);
$this->assertEqualsCanonicalizing([(array) $proxy, (array) $orphanedproxy], $proxies);
}
/**
* Test get_tool_proxies with orphaned proxies only.
*/
public function test_mod_lti_get_orphaned_tool_proxies() {
// Create two tool proxies. One to associate with tool, and one to leave orphaned.
$this->setAdminUser();
$proxy = $this->generate_tool_proxy("1");
$orphanedproxy = $this->generate_tool_proxy("2");
$this->generate_tool_type("1", $proxy->id); // Associate proxy 1 with tool type.
// Fetch all proxies.
$proxies = mod_lti_external::get_tool_proxies(true);
$proxies = external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
$this->assertCount(1, $proxies);
$this->assertEqualsCanonicalizing([(array) $orphanedproxy], $proxies);
}
/** /**
* Test get_tool_launch_data. * Test get_tool_launch_data.
*/ */

View file

@ -4,6 +4,8 @@ This files describes API changes in the lti code.
* Select Content supports multiple, allowing a tool to return more than one link at a time. * Select Content supports multiple, allowing a tool to return more than one link at a time.
Parameter multiple in function lti_build_content_item_selection_request() is now set to true. Parameter multiple in function lti_build_content_item_selection_request() is now set to true.
* Deprecated unused function after external function, 'get_tool_proxies()', was refactored:
- serialise_tool_proxy()
=== 3.8 === === 3.8 ===