MDL-52335 mod_lti: php7 compatibility in variable syntax
authorMarina Glancy <marina@moodle.com>
Wed, 2 Dec 2015 06:01:33 +0000 (14:01 +0800)
committerMarina Glancy <marina@moodle.com>
Thu, 3 Dec 2015 01:31:20 +0000 (09:31 +0800)
mod/lti/locallib.php
mod/lti/tests/locallib_test.php

index 2306de3..9840dba 100644 (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);
index 6b185aa..350e5aa 100644 (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));
     }
 
     /**