assertTrue(common_Utils::isUri($toto)); $this->assertFalse(common_Utils::isUri($toto2)); $this->assertFalse(common_Utils::isUri($toto3)); } public function testPhpStringEscaping() { // normal chars $utf = 'ÆýЉϿϫ˲ ˦ˈŒ\'"\\\\'; $value = eval("return " . common_Utils::toPHPVariableString($utf) . ";"); $this->assertEquals($utf, $value); // test binary safe $binaryString = $this->buildBinString(); $value = eval("return " . common_Utils::toPHPVariableString($binaryString) . ";"); $this->assertEquals($binaryString, $value); $all = ''; for ($i = 0; $i <= 255; $i++) { $all .= chr($i); } $value = eval("return " . common_Utils::toPHPVariableString($all) . ";"); $this->assertEquals($all, $value); $serialized = serialize(new stdClass()); $value = eval("return " . common_Utils::toPHPVariableString($serialized) . ";"); $this->assertEquals($serialized, $value); } public function testSerialisation() { $toSerialize = [ 'a' => "te\0st \\ ", 'b' => new AuthAdapter(), 'c' => [ '1', '2', [common_user_auth_Service::singleton()] ], 'd' => 'aaaaa' . PHP_EOL . 'bbbbb' . PHP_EOL . 'ccccc' ]; $value = eval("return " . common_Utils::toPHPVariableString($toSerialize) . ";"); $this->assertEquals($toSerialize, $value); $valueNice = eval("return " . common_Utils::toHumanReadablePhpString($toSerialize) . ";"); $this->assertEquals($toSerialize, $valueNice); } private function buildBinString() { $position = pack('S', 0); // Q01 $state = "\x01"; // INTERACTING $navigationMode = "\x00"; // LINEAR $submissionMode = "\x00"; // INDIVIDUAL $attempting = "\x00"; // false $hasItemSessionControl = "\x00"; // false $numAttempts = "\x02"; // 2 $duration = pack('S', 4) . 'PT0S'; // 0 seconds recorded yet. $completionStatus = pack('S', 10) . 'incomplete'; $timeReference = pack('l', 1378302030); // Wednesday, September 4th 2013, 13:40:30 (GMT) $varCount = "\x02"; // 2 variables (SCORE & RESPONSE). $score = "\x01" . pack('S', 8) . "\x00" . "\x01" . pack('d', 1.0); $response = "\x00" . pack('S', 0) . "\x00" . "\x01" . pack('S', 7) . 'ChoiceA'; return implode('', [$position, $state, $navigationMode, $submissionMode, $attempting, $hasItemSessionControl, $numAttempts, $duration, $completionStatus, $timeReference, $varCount, $score, $response]); } }