Commit 9c075209 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

Merge branch 'MDL-70891-master' of git://github.com/marinaglancy/moodle

parents 4f0b5871 9e896524
......@@ -10530,10 +10530,14 @@ class lang_string {
/**
* Magic __set_state method used for var_export
*
* @return string
* @param array $array
* @return self
*/
public function __set_state() {
return $this->get_string();
public static function __set_state(array $array): self {
$tmp = new lang_string($array['identifier'], $array['component'], $array['a'], $array['lang']);
$tmp->string = $array['string'];
$tmp->forcedstring = $array['forcedstring'];
return $tmp;
}
/**
......
......@@ -2261,6 +2261,39 @@ class core_moodlelib_testcase extends advanced_testcase {
$COURSE->lang = $originallang;
}
public function test_lang_string_var_export() {
// Call var_export() on a newly generated lang_string.
$str = new lang_string('no');
$expected1 = <<<EOF
lang_string::__set_state(array(
'identifier' => 'no',
'component' => 'moodle',
'a' => NULL,
'lang' => NULL,
'string' => NULL,
'forcedstring' => false,
))
EOF;
$v = var_export($str, true);
$this->assertEquals($expected1, $v);
// Now execute the code that was returned - it should produce a correct string.
$str = lang_string::__set_state(array(
'identifier' => 'no',
'component' => 'moodle',
'a' => NULL,
'lang' => NULL,
'string' => NULL,
'forcedstring' => false,
));
$this->assertInstanceOf(lang_string::class, $str);
$this->assertEquals('No', $str);
}
public function test_get_string_limitation() {
// This is one of the limitations to the lang_string class. It can't be
// used as a key.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment