MDL-53779 external: get_string and get_strings use PARAM_RAW

For the string parameters and translated strings.
This commit is contained in:
Frederic Massart 2016-04-12 16:55:21 +08:00
parent b611ade3ab
commit bf6239eddb
2 changed files with 47 additions and 4 deletions

View File

@ -92,7 +92,7 @@ class core_external extends external_api {
new external_single_structure(array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
- if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
'value' => new external_value(PARAM_TEXT,'param value'))),
'value' => new external_value(PARAM_RAW,'param value'))),
'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
)
)
@ -124,7 +124,7 @@ class core_external extends external_api {
* @since Moodle 2.4
*/
public static function get_string_returns() {
return new external_value(PARAM_TEXT, 'translated string');
return new external_value(PARAM_RAW, 'translated string');
}
/**
@ -144,7 +144,7 @@ class core_external extends external_api {
new external_single_structure(array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
- if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
'value' => new external_value(PARAM_TEXT, 'param value'))),
'value' => new external_value(PARAM_RAW, 'param value'))),
'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
))
)
@ -198,7 +198,7 @@ class core_external extends external_api {
'stringid' => new external_value(PARAM_STRINGID, 'string id'),
'component' => new external_value(PARAM_COMPONENT, 'string component'),
'lang' => new external_value(PARAM_LANG, 'lang'),
'string' => new external_value(PARAM_TEXT, 'translated string'))
'string' => new external_value(PARAM_RAW, 'translated string'))
));
}

View File

@ -78,6 +78,26 @@ class core_external_testcase extends externallib_advanced_testcase {
array('name' => 'id', 'value' => $service->id)));
}
/**
* Test get_string with HTML.
*/
public function test_get_string_containing_html() {
$result = core_external::get_string('registrationinfo');
$actual = external_api::clean_returnvalue(core_external::get_string_returns(), $result);
$expected = get_string('registrationinfo', 'moodle');
$this->assertSame($expected, $actual);
}
/**
* Test get_string with arguments containing HTML.
*/
public function test_get_string_with_args_containing_html() {
$result = core_external::get_string('added', 'moodle', null, [['value' => '<strong>Test</strong>']]);
$actual = external_api::clean_returnvalue(core_external::get_string_returns(), $result);
$expected = get_string('added', 'moodle', '<strong>Test</strong>');
$this->assertSame($expected, $actual);
}
/**
* Test get_strings
*/
@ -114,6 +134,29 @@ class core_external_testcase extends externallib_advanced_testcase {
}
}
/**
* Test get_strings with HTML.
*/
public function test_get_strings_containing_html() {
$result = core_external::get_strings([['stringid' => 'registrationinfo'], ['stringid' => 'loginaspasswordexplain']]);
$actual = external_api::clean_returnvalue(core_external::get_strings_returns(), $result);
$this->assertSame(get_string('registrationinfo', 'moodle'), $actual[0]['string']);
$this->assertSame(get_string('loginaspasswordexplain', 'moodle'), $actual[1]['string']);
}
/**
* Test get_strings with arguments containing HTML.
*/
public function test_get_strings_with_args_containing_html() {
$result = core_external::get_strings([
['stringid' => 'added', 'stringparams' => [['value' => '<strong>Test</strong>']]],
['stringid' => 'loggedinas', 'stringparams' => [['value' => '<strong>Test</strong>']]]]
);
$actual = external_api::clean_returnvalue(core_external::get_strings_returns(), $result);
$this->assertSame(get_string('added', 'moodle', '<strong>Test</strong>'), $actual[0]['string']);
$this->assertSame(get_string('loggedinas', 'moodle', '<strong>Test</strong>'), $actual[1]['string']);
}
/**
* Test get_component_strings
*/