mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-71343-master' of https://github.com/rjnl/moodle
This commit is contained in:
commit
e9f457e3c3
@ -409,6 +409,8 @@ class helper {
|
|||||||
* @return array The JS array converted to PHP array.
|
* @return array The JS array converted to PHP array.
|
||||||
*/
|
*/
|
||||||
public static function parse_js_array(string $jscontent): array {
|
public static function parse_js_array(string $jscontent): array {
|
||||||
|
// Convert all line-endings to UNIX format first.
|
||||||
|
$jscontent = str_replace(array("\r\n", "\r"), "\n", $jscontent);
|
||||||
$jsarray = preg_split('/,\n\s+/', substr($jscontent, 0, -1));
|
$jsarray = preg_split('/,\n\s+/', substr($jscontent, 0, -1));
|
||||||
$jsarray = preg_replace('~{?\\n~', '', $jsarray);
|
$jsarray = preg_replace('~{?\\n~', '', $jsarray);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ use advanced_testcase;
|
|||||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class helper_testcase extends \advanced_testcase {
|
class helper_test extends \advanced_testcase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the behaviour of get_display_options().
|
* Test the behaviour of get_display_options().
|
||||||
@ -379,4 +379,49 @@ class helper_testcase extends \advanced_testcase {
|
|||||||
$helperfile = helper::get_export_info('nofileexist.h5p', $url);
|
$helperfile = helper::get_export_info('nofileexist.h5p', $url);
|
||||||
$this->assertNull($helperfile);
|
$this->assertNull($helperfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the parse_js_array function with a range of content.
|
||||||
|
*
|
||||||
|
* @dataProvider parse_js_array_provider
|
||||||
|
* @param string $content
|
||||||
|
* @param array $expected
|
||||||
|
*/
|
||||||
|
public function test_parse_js_array(string $content, array $expected): void {
|
||||||
|
$this->assertEquals($expected, helper::parse_js_array($content));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for test_parse_js_array().
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function parse_js_array_provider(): array {
|
||||||
|
$lines = [
|
||||||
|
"{",
|
||||||
|
" missingTranslation: '[Missing translation :key]',",
|
||||||
|
" loading: 'Loading, please wait...',",
|
||||||
|
" selectLibrary: 'Select the library you wish to use for your content.',",
|
||||||
|
"}",
|
||||||
|
];
|
||||||
|
$expected = [
|
||||||
|
'missingTranslation' => '[Missing translation :key]',
|
||||||
|
'loading' => 'Loading, please wait...',
|
||||||
|
'selectLibrary' => 'Select the library you wish to use for your content.',
|
||||||
|
];
|
||||||
|
return [
|
||||||
|
'Strings with \n' => [
|
||||||
|
implode("\n", $lines),
|
||||||
|
$expected,
|
||||||
|
],
|
||||||
|
'Strings with \r\n' => [
|
||||||
|
implode("\r\n", $lines),
|
||||||
|
$expected,
|
||||||
|
],
|
||||||
|
'Strings with \r' => [
|
||||||
|
implode("\r", $lines),
|
||||||
|
$expected,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user