MDL-67173 core_h5p: Translate non-localURL in WS to invalidurl

The WebService should return invalidurl when the coding error is
"Coding error detected, it must be fixed by a programmer: out_al_local_url called on a non-local URL"
So, we translate the error to be used by Mobile App.
This commit is contained in:
cescobedo
2019-11-07 23:05:41 +01:00
parent 65ae2441f3
commit 3b85322940
2 changed files with 24 additions and 4 deletions
+13 -4
View File
@@ -63,9 +63,9 @@ class external extends external_api {
/**
* Return the H5P file trusted.
*
* The Mobile App needs to work with an H5P package which can trust.
* And this H5P package is only trusted by the Mobile App once it's been processed
* by the core checking the right caps, validating the H5P package
* The Mobile App needs to work with an H5P package which can trust.
* And this H5P package is only trusted by the Mobile App once it's been processed
* by the core checking the right caps, validating the H5P package
* and doing any clean-up process involved.
*
* @since Moodle 3.8
@@ -99,9 +99,18 @@ class external extends external_api {
$messages = $h5pplayer->get_messages();
} catch (\moodle_exception $e) {
$messages = (object) [
'exception' => $e->getMessage(),
'code' => $e->getCode(),
];
// To mantain the coherence between web coding error and Mobile coding errors.
// We need to return the same message error to Mobile.
// The 'out_al_local_url called on a non-local URL' error is provided by the \moodle_exception.
// We have to translate to h5pinvalidurl which is the same coding error showed in web.
if ($e->errorcode === 'codingerror' &&
$e->a === 'out_as_local_url called on a non-local URL') {
$messages->exception = get_string('h5pinvalidurl', 'core_h5p');
} else {
$messages->exception = $e->getMessage();
}
}
if (empty($messages->error) && empty($messages->exception)) {
+11
View File
@@ -124,6 +124,17 @@ class core_h5p_external_testcase extends externallib_advanced_testcase {
// Check the warnings to be sure that h5pinvalidurl is the message by moodle_exception.
$this->assertEquals($urlempty, $result['warnings'][0]['item']);
$this->assertEquals(get_string('h5pinvalidurl', 'core_h5p'), $result['warnings'][0]['message']);
// Create a non-local URL.
$urlnonlocal = 'http://www.google.com/pluginfile.php/644/block_html/content/arithmetic-quiz-1-1.h5p';
$result = external::get_trusted_h5p_file($urlnonlocal, 0, 0, 0, 0);
$result = external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on warnings and none on files.
$this->assertCount(0, $result['files']);
$this->assertCount(1, $result['warnings']);
// Check the warnings to be sure that h5pinvalidurl is the message by moodle_exception.
$this->assertEquals($urlnonlocal, $result['warnings'][0]['item']);
$this->assertEquals(get_string('h5pinvalidurl', 'core_h5p'), $result['warnings'][0]['message']);
}
/**