mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-67695 mod_lti: Use correct return structure for get_tool_proxies.
* Use tool_proxy_return_structure for each proxy. * Added tests for getting all proxies and orphaned proxies.
This commit is contained in:
parent
eda7eb44b3
commit
41121d705f
2 changed files with 71 additions and 6 deletions
|
@ -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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue