MDL-52335 mod_lti: php7 compatibility in variable syntax

This commit is contained in:
Marina Glancy 2015-12-02 14:01:33 +08:00
parent f9ba07133a
commit ccfd168a6d
2 changed files with 10 additions and 1 deletions

View File

@ -868,7 +868,7 @@ function lti_parse_custom_parameter($toolproxy, $tool, $params, $value, $islti2)
$value = $params[$val];
} else {
$valarr = explode('->', substr($val, 1), 2);
$value = "{${$valarr[0]}->$valarr[1]}";
$value = "{${$valarr[0]}->{$valarr[1]}}";
$value = str_replace('<br />' , ' ', $value);
$value = str_replace('<br>' , ' ', $value);
$value = format_string($value);

View File

@ -63,8 +63,11 @@ require_once($CFG->dirroot . '/mod/lti/servicelib.php');
class mod_lti_locallib_testcase extends advanced_testcase {
public function test_split_custom_parameters() {
$this->resetAfterTest();
$tool = new stdClass();
$tool->enabledcapability = '';
$tool->parameter = '';
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(), "x=1\ny=2", false),
array('custom_x' => '1', 'custom_y' => '2'));
@ -76,6 +79,12 @@ class mod_lti_locallib_testcase extends advanced_testcase {
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(),
'Complex!@#$^*(){}[]KEY=Complex!@#$^*;(){}[]½Value', false),
array('custom_complex____________key' => 'Complex!@#$^*;(){}[]½Value'));
// Test custom parameter that returns $USER property.
$user = $this->getDataGenerator()->create_user(array('middlename' => 'SOMETHING'));
$this->setUser($user);
$this->assertEquals(array('custom_x' => '1', 'custom_y' => 'SOMETHING'),
lti_split_custom_parameters(null, $tool, array(), "x=1\ny=\$Person.name.middle", false));
}
/**