diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index ddec86456c4..23c358e9f7c 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -1193,6 +1193,10 @@ function lti_get_url_thumbprint($url) { $urlparts['path'] = ''; } + if (!isset($urlparts['query'])) { + $urlparts['query'] = ''; + } + if (!isset($urlparts['host'])) { $urlparts['host'] = ''; } @@ -1201,7 +1205,13 @@ function lti_get_url_thumbprint($url) { $urlparts['host'] = substr($urlparts['host'], 4); } - return $urllower = $urlparts['host'] . '/' . $urlparts['path']; + $urllower = $urlparts['host'] . '/' . $urlparts['path']; + + if ($urlparts['query'] != '') { + $urllower .= '?' . $urlparts['query']; + } + + return $urllower; } function lti_get_best_tool_by_url($url, $tools, $courseid = null) { diff --git a/mod/lti/tests/locallib_test.php b/mod/lti/tests/locallib_test.php index 399b429f713..2418b865bb0 100644 --- a/mod/lti/tests/locallib_test.php +++ b/mod/lti/tests/locallib_test.php @@ -185,7 +185,8 @@ class mod_lti_locallib_testcase extends advanced_testcase { $this->assertEquals('moodle.org//this/is/moodle', lti_get_url_thumbprint('http://moodle.org/this/is/moodle')); $this->assertEquals('moodle.org//this/is/moodle', lti_get_url_thumbprint('https://moodle.org/this/is/moodle')); $this->assertEquals('moodle.org//this/is/moodle', lti_get_url_thumbprint('moodle.org/this/is/moodle')); - $this->assertEquals('moodle.org//this/is/moodle', lti_get_url_thumbprint('moodle.org/this/is/moodle?foo=bar')); + $this->assertEquals('moodle.org//this/is/moodle', lti_get_url_thumbprint('moodle.org/this/is/moodle?')); + $this->assertEquals('moodle.org//this/is/moodle?foo=bar', lti_get_url_thumbprint('moodle.org/this/is/moodle?foo=bar')); } /* @@ -325,4 +326,115 @@ 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); } + + /** + * Provider for test_lti_get_best_tool_by_url. + * + * @return array of [urlToTest, expectedTool, allTools] + */ + public function lti_get_best_tool_by_url_provider() { + $tools = [ + (object) [ + 'name' => 'Here', + 'baseurl' => 'https://example.com/i/am/?where=here', + 'tooldomain' => 'example.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + (object) [ + 'name' => 'There', + 'baseurl' => 'https://example.com/i/am/?where=there', + 'tooldomain' => 'example.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + (object) [ + 'name' => 'Not here', + 'baseurl' => 'https://example.com/i/am/?where=not/here', + 'tooldomain' => 'example.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + (object) [ + 'name' => 'Here', + 'baseurl' => 'https://example.com/i/am/', + 'tooldomain' => 'example.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + (object) [ + 'name' => 'Here', + 'baseurl' => 'https://example.com/i/was', + 'tooldomain' => 'example.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + (object) [ + 'name' => 'Here', + 'baseurl' => 'https://badexample.com/i/am/?where=here', + 'tooldomain' => 'badexample.com', + 'state' => LTI_TOOL_STATE_CONFIGURED, + 'course' => SITEID + ], + ]; + + $data = [ + [ + 'url' => $tools[0]->baseurl, + 'expected' => $tools[0], + ], + [ + 'url' => $tools[1]->baseurl, + 'expected' => $tools[1], + ], + [ + 'url' => $tools[2]->baseurl, + 'expected' => $tools[2], + ], + [ + 'url' => $tools[3]->baseurl, + 'expected' => $tools[3], + ], + [ + 'url' => $tools[4]->baseurl, + 'expected' => $tools[4], + ], + [ + 'url' => $tools[5]->baseurl, + 'expected' => $tools[5], + ], + [ + 'url' => 'https://nomatch.com/i/am/', + 'expected' => null + ], + [ + 'url' => 'https://example.com', + 'expected' => null + ], + [ + 'url' => 'https://example.com/i/am/?where=unknown', + 'expected' => $tools[3] + ] + ]; + + // Construct the final array as required by the provider API. Each row + // of the array contains the URL to test, the expected tool, and + // the complete list of tools. + return array_map(function($data) use ($tools) { + return [$data['url'], $data['expected'], $tools]; + }, $data); + } + + /** + * Test lti_get_best_tool_by_url. + * + * @dataProvider lti_get_best_tool_by_url_provider + * @param string $url The URL to test. + * @param object $expected The expected tool matching the URL. + * @param array $tools The pool of tools to match the URL with. + */ + public function test_lti_get_best_tool_by_url($url, $expected, $tools) { + $actual = lti_get_best_tool_by_url($url, $tools, null); + $this->assertSame($expected, $actual); + } } diff --git a/repository/skydrive/microsoftliveapi.php b/repository/skydrive/microsoftliveapi.php index 710777bdc67..9fe541a6cd6 100644 --- a/repository/skydrive/microsoftliveapi.php +++ b/repository/skydrive/microsoftliveapi.php @@ -60,18 +60,6 @@ class microsoft_skydrive extends oauth2_client { $this->foldernamecache = cache::make('repository_skydrive', 'foldername'); } - /** - * Should HTTP GET be used instead of POST? - * - * The Microsoft API does not support POST, so we should use - * GET instead (with the auth_token passed as a GET param). - * - * @return bool true if GET should be used - */ - protected function use_http_get() { - return true; - } - /** * Returns the auth url for OAuth 2.0 request * @return string the auth url @@ -88,6 +76,20 @@ class microsoft_skydrive extends oauth2_client { return 'https://login.live.com/oauth20_token.srf'; } + /** + * Post request. + * + * Overridden to convert the data to a string, else curl will set the wrong headers. + * + * @param string $url The URL. + * @param array|string $params The parameters. + * @param array $options The options. + * @return bool + */ + public function post($url, $params = '', $options = array()) { + return parent::post($url, format_postdata_for_curlcall($params), $options); + } + /** * Downloads a file to a file from skydrive using authenticated request * diff --git a/version.php b/version.php index 223f7a47134..c129c6b5d56 100644 --- a/version.php +++ b/version.php @@ -29,11 +29,11 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2016052303.02; // 20160523 = branching date YYYYMMDD - do not modify! +$version = 2016052303.03; // 20160523 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. -$release = '3.1.3+ (Build: 20161118)'; // Human-friendly version name +$release = '3.1.3+ (Build: 20161122)'; // Human-friendly version name $branch = '31'; // This version's branch. $maturity = MATURITY_STABLE; // This version's maturity level.