Merge branch 'MDL-74576-master' of https://github.com/snake/moodle

This commit is contained in:
Jun Pataleta 2022-05-05 09:55:37 +08:00
commit 53ad985457
2 changed files with 27 additions and 15 deletions

View File

@ -86,7 +86,7 @@ class ags_info {
* @throws \coding_exception if any of the scopes is invalid.
*/
private function validate_scopes(array $scopes): void {
$validscopes = [
$supportedscopes = [
self::SCOPES_LINEITEM_READONLY,
self::SCOPES_LINEITEM_MANAGE,
self::SCOPES_RESULT_READONLY,
@ -96,17 +96,14 @@ class ags_info {
if (!is_string($scope)) {
throw new \coding_exception('Scope must be a string value');
}
$key = array_search($scope, $validscopes);
if ($key === false) {
throw new \coding_exception("Scope '{$scope}' is invalid.");
}
if ($key == 0) {
$key = array_search($scope, $supportedscopes);
if ($key === 0) {
$this->lineitemscopes[] = self::SCOPES_LINEITEM_READONLY;
} else if ($key == 1) {
} else if ($key === 1) {
$this->lineitemscopes[] = self::SCOPES_LINEITEM_MANAGE;
} else if ($key == 2) {
} else if ($key === 2) {
$this->resultscope = self::SCOPES_RESULT_READONLY;
} else if ($key == 3) {
} else if ($key === 3) {
$this->scorescope = self::SCOPES_SCORES_POST;
}
}

View File

@ -42,7 +42,12 @@ class ags_info_test extends \advanced_testcase {
$agsinfo = ags_info::create(...array_values($args));
$this->assertEquals($args['lineitemsurl'], $agsinfo->get_lineitemsurl());
$this->assertEquals($args['lineitemurl'], $agsinfo->get_lineitemurl());
$this->assertEquals($args['scopes'], $agsinfo->get_scopes());
if (isset($expectations['scopes'])) {
$this->assertEquals($expectations['scopes'], $agsinfo->get_scopes());
} else {
$this->assertEquals($args['scopes'], $agsinfo->get_scopes());
}
$this->assertEquals($expectations['lineitemscope'], $agsinfo->get_lineitemscope());
$this->assertEquals($expectations['scorescope'], $agsinfo->get_scorescope());
$this->assertEquals($expectations['resultscope'], $agsinfo->get_resultscope());
@ -239,7 +244,7 @@ class ags_info_test extends \advanced_testcase {
'exceptionmessage' => 'Scope must be a string value'
]
],
'Both lineitems and lineitem URL provided with invalid scopes' => [
'Both lineitems and lineitem URL provided with unsupported scopes' => [
'args' => [
'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
@ -248,13 +253,23 @@ class ags_info_test extends \advanced_testcase {
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/score',
'https://example.com/invalid/scope'
'https://example.com/unsupported/scope'
]
],
'expectations' => [
'valid' => false,
'exception' => \coding_exception::class,
'exceptionmessage' => "Scope 'https://example.com/invalid/scope' is invalid."
'valid' => true,
'scopes' => [
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/score',
],
'lineitemscope' => [
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly'
],
'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score'
]
],
'Both lineitems and lineitem URL provided with invalid scope types' => [