mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-67695-master_get_lti_proxies' of https://github.com/andrewmadden/moodle
This commit is contained in:
commit
6325f848d8
@ -138,22 +138,18 @@ class mod_lti_external extends external_api {
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_tool_proxies($orphanedonly) {
|
||||
global $PAGE;
|
||||
$params = self::validate_parameters(self::get_tool_proxies_parameters(),
|
||||
array(
|
||||
'orphanedonly' => $orphanedonly
|
||||
));
|
||||
$orphanedonly = $params['orphanedonly'];
|
||||
|
||||
$proxies = array();
|
||||
$context = context_system::instance();
|
||||
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
$proxies = lti_get_tool_proxies($orphanedonly);
|
||||
|
||||
return array_map('serialise_tool_proxy', $proxies);
|
||||
return lti_get_tool_proxies($orphanedonly);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,7 +160,7 @@ class mod_lti_external extends external_api {
|
||||
*/
|
||||
public static function get_tool_proxies_returns() {
|
||||
return new external_multiple_structure(
|
||||
self::tool_type_return_structure()
|
||||
self::tool_proxy_return_structure()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -4173,9 +4173,14 @@ function serialise_tool_type(stdClass $type) {
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
function serialise_tool_proxy(stdClass $proxy) {
|
||||
$deprecatedtext = __FUNCTION__ . '() is deprecated. Please remove all references to this method.';
|
||||
debugging($deprecatedtext, DEBUG_DEVELOPER);
|
||||
|
||||
return array(
|
||||
'id' => $proxy->id,
|
||||
'name' => $proxy->name,
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
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 ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user