<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.9.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>Serialize</name>
<channel>pear.horde.org</channel>
<summary>Data Encapulation API</summary>
<description>The Horde_Serialize:: class provides various methods of
- encapsulating data.
- </description>
+ encapsulating data.</description>
<lead>
<name>Chuck Hagenbuch</name>
<user>chuck</user>
<email>jan@horde.org</email>
<active>yes</active>
</lead>
- <date>2009-02-12</date>
+ <date>2011-01-21</date>
+ <time>16:40:16</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Throw exceptions rather than returning PEAR_Errors.
+ <notes>
+* Throw exceptions rather than returning PEAR_Errors.
* Add support for limited error handling for json encoding errors
(requires PHP 5.3+).
- * Initial Horde 4 package.</notes>
+ * Initial Horde 4 package.
+ </notes>
<contents>
- <dir name="/">
+ <dir baseinstalldir="/" name="/">
+ <dir name="doc">
+ <dir name="Horde">
+ <dir name="Serialize">
+ <dir name="examples">
+ <file name="json.php" role="doc" />
+ </dir> <!-- /doc/Horde/Serialize/examples -->
+ </dir> <!-- /doc/Horde/Serialize -->
+ </dir> <!-- /doc/Horde -->
+ </dir> <!-- /doc -->
<dir name="lib">
<dir name="Horde">
<dir name="Serialize">
</dir> <!-- /lib/Horde/Serialize -->
<file name="Serialize.php" role="php" />
</dir> <!-- /lib/Horde -->
- </dir> <!-- /lib/ -->
+ </dir> <!-- /lib -->
<dir name="test">
<dir name="Horde">
<dir name="Serialize">
<dir name="fixtures">
<file name="badutf8.txt" role="test" />
</dir> <!-- /test/Horde/Serialize/fixtures -->
- <file name="json_assoc_array.phpt" role="test" />
- <file name="json_empty.phpt" role="test" />
- <file name="json_encode_decode.phpt" role="test" />
- <file name="json_encode_badutf8.phpt" role="test" />
- <file name="json_nested_array.phpt" role="test" />
- <file name="json_object.phpt" role="test" />
- <file name="json_spaces_comments.phpt" role="test" />
- <file name="json_unquoted_keys.phpt" role="test" />
+ <file name="AllTests.php" role="test" />
+ <file name="Autoload.php" role="test" />
+ <file name="JsonTest.php" role="test" />
</dir> <!-- /test/Horde/Serialize -->
</dir> <!-- /test/Horde -->
</dir> <!-- /test -->
</dependencies>
<phprelease>
<filelist>
- <install name="lib/Horde/Serialize/Exception.php" as="Horde/Serialize/Exception.php" />
- <install name="lib/Horde/Serialize.php" as="Horde/Serialize.php" />
+ <install as="Horde/Serialize/examples/json.php" name="doc/Horde/Serialize/examples/json.php" />
+ <install as="Horde/Serialize.php" name="lib/Horde/Serialize.php" />
+ <install as="Horde/Serialize/Exception.php" name="lib/Horde/Serialize/Exception.php" />
+ <install as="Horde/Serialize/AllTests.php" name="test/Horde/Serialize/AllTests.php" />
+ <install as="Horde/Serialize/Autoload.php" name="test/Horde/Serialize/Autoload.php" />
+ <install as="Horde/Serialize/JsonTest.php" name="test/Horde/Serialize/JsonTest.php" />
+ <install as="Horde/Serialize/fixtures/badutf8.txt" name="test/Horde/Serialize/fixtures/badutf8.txt" />
</filelist>
</phprelease>
<changelog>
<release>
+ <version>
+ <release>0.0.1</release>
+ <api>0.0.1</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2004-01-01</date>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>
+Initial packaging.
+ </notes>
+ </release>
+ <release>
<date>2006-05-08</date>
<time>23:12:48</time>
<version>
<api>alpha</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>Converted to package.xml 2.0 for pear.horde.org</notes>
+ <notes>
+Converted to package.xml 2.0 for pear.horde.org
+ </notes>
</release>
<release>
<version>
- <release>0.0.1</release>
- <api>0.0.1</api>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
</version>
<stability>
- <release>alpha</release>
- <api>alpha</api>
+ <release>beta</release>
+ <api>beta</api>
</stability>
- <date>2004-01-01</date>
+ <date>2011-01-21</date>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>Initial packaging.
+ <notes>
+* Throw exceptions rather than returning PEAR_Errors.
+ * Add support for limited error handling for json encoding errors
+ (requires PHP 5.3+).
+ * Initial Horde 4 package.
</notes>
</release>
</changelog>
--- /dev/null
+<?php
+/**
+ * Tests for the horde/Serialize package.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Serialize
+ * @package Serialize
+ * @subpackage UnitTests
+ */
+
+/**
+ * Define the main method
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Horde_Serialize_AllTests::main');
+}
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Horde/Test/AllTests.php';
+
+/**
+ * @category Horde
+ * @package Serialize
+ * @subpackage UnitTests
+ */
+class Horde_Serialize_AllTests extends Horde_Test_AllTests
+{
+}
+
+Horde_Serialize_AllTests::init('Horde_Serialize', __FILE__);
+
+if (PHPUnit_MAIN_METHOD == 'Horde_Serialize_AllTests::main') {
+ Horde_Serialize_AllTests::main();
+}
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Serialize
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Serialize
+ */
+
+if (!spl_autoload_functions()) {
+ spl_autoload_register(
+ create_function(
+ '$class',
+ '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);'
+ . '$err_mask = E_ALL ^ E_WARNING;'
+ . '$oldErrorReporting = error_reporting($err_mask);'
+ . 'include "$filename.php";'
+ . 'error_reporting($oldErrorReporting);'
+ )
+ );
+}
+
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
--- /dev/null
+<?php
+/**
+ * Json serialization tests.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package Serialize
+ * @subpackage UnitTests
+ */
+
+class Horde_Serialize_JsonTest extends PHPUnit_Framework_TestCase
+{
+ // JSON associative arrays tests.
+ public function testJsonAssociativeArray()
+ {
+ // array case - strict: associative array with nested associative
+ // arrays
+ $arr = array(
+ 'car1'=> array(
+ 'color'=> 'tan',
+ 'model' => 'sedan'
+ ),
+ 'car2' => array(
+ 'color' => 'red',
+ 'model' => 'sports'
+ )
+ );
+
+ $this->assertEquals(
+ '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}',
+ Horde_Serialize::serialize($arr, Horde_Serialize::JSON)
+ );
+
+ // array case - strict: associative array with nested associative
+ // arrays, and some numeric keys thrown in
+ // Should degrade to a numeric array.
+ $arn = array(
+ 0 => array(
+ 0 => 'tan\\',
+ 'model\\' => 'sedan'
+ ),
+ 1 => array(
+ 0 => 'red',
+ 'model' => 'sports'
+ )
+ );
+ $arn_ja = '[{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}]';
+ $this->assertEquals(
+ $arn_ja,
+ Horde_Serialize::serialize($arn, Horde_Serialize::JSON)
+ );
+
+ $this->assertInternalType(
+ 'array',
+ Horde_Serialize::unserialize($arn_ja, Horde_Serialize::JSON)
+ );
+
+ // sparse numeric assoc array: associative array numeric keys which
+ // are not fully populated in a range of 0 to length-1
+ // Test a sparsely populated numerically indexed associative array.
+ $arrs = array(
+ 1 => 'one',
+ 2 => 'two',
+ 5 => 'five'
+ );
+ $this->assertEquals(
+ '{"1":"one","2":"two","5":"five"}',
+ Horde_Serialize::serialize($arrs, Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON empties tests.
+ public function testJsonEmpties()
+ {
+ $obj0_j = '{}';
+ $obj1_j = '{ }';
+
+ $this->assertInternalType(
+ 'object',
+ Horde_Serialize::unserialize($obj0_j, Horde_Serialize::JSON)
+ );
+ $this->assertEquals(
+ '0',
+ count(get_object_vars(Horde_Serialize::unserialize($obj0_j, Horde_Serialize::JSON)))
+ );
+
+ $this->assertInternalType(
+ 'object',
+ Horde_Serialize::unserialize($obj1_j, Horde_Serialize::JSON)
+ );
+ $this->assertEquals(
+ '0',
+ count(get_object_vars(Horde_Serialize::unserialize($obj1_j, Horde_Serialize::JSON)))
+ );
+ }
+
+ // JSON encode/decode tests (invalid UTF-8 input).
+ public function testJsonInvalidUTF8Input()
+ {
+ if (version_compare(phpversion(), '5.3.0') == -1) {
+ $this->markTestSkipped("skip Test requires PHP 5.3+");
+ }
+
+ $this->assertEquals(
+ '"Note: To play video messages sent to email, QuickTime\u00ae 6.5 or higher is required.\n"',
+ Horde_Serialize::serialize(file_get_contents('./fixtures/badutf8.txt'), Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON encode/decode tests.
+ public function testJsonEncodeAndDecode()
+ {
+ $obj = new stdClass();
+ $obj->a_string = '"he":llo}:{world';
+ $obj->an_array = array(1, 2, 3);
+ $obj->obj = new stdClass();
+ $obj->obj->a_number = 123;
+ $obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
+
+ $arr = array(null, true, array(1, 2, 3), "hello\"],[world!");
+ $arr_j = '[null,true,[1,2,3],"hello\"],[world!"]';
+
+ $str1 = 'hello world';
+ $str1_j = '"hello world"';
+ $str1_j_ = "'hello world'";
+
+ $str2 = "hello\t\"world\"";
+ $str2_j = '"hello\\t\\"world\\""';
+
+ $str3 = "\\\r\n\t\"/";
+ $str3_j = '"\\\\\\r\\n\\t\\"\\/"';
+
+ $str4 = 'héllö wørłd';
+ $str4_j = '"h\u00e9ll\u00f6 w\u00f8r\u0142d"';
+ $str4_j_ = '"héllö wørłd"';
+
+ // type case: null
+ $this->assertEquals(
+ 'null',
+ Horde_Serialize::serialize(null, Horde_Serialize::JSON)
+ );
+
+ // type case: boolean true
+ $this->assertEquals(
+ 'true',
+ Horde_Serialize::serialize(true, Horde_Serialize::JSON)
+ );
+
+ // type case: boolean false
+ $this->assertEquals(
+ 'false',
+ Horde_Serialize::serialize(false, Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1
+ $this->assertEquals(
+ 1,
+ Horde_Serialize::serialize(1, Horde_Serialize::JSON)
+ );
+
+ // numeric case: -1
+ $this->assertEquals(
+ -1,
+ Horde_Serialize::serialize(-1, Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.0
+ $this->assertEquals(
+ 1,
+ Horde_Serialize::serialize(1.0, Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.1
+ $this->assertEquals(
+ 1.1,
+ Horde_Serialize::serialize(1.1, Horde_Serialize::JSON)
+ );
+
+ // string case: hello world
+ $this->assertEquals(
+ $str1_j,
+ Horde_Serialize::serialize($str1, Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with tab, double-quotes
+ $this->assertEquals(
+ $str2_j,
+ Horde_Serialize::serialize($str2, Horde_Serialize::JSON)
+ );
+
+ // string case: backslash, return, newline, tab, double-quote
+ $this->assertEquals(
+ $str3_j,
+ Horde_Serialize::serialize($str3, Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with unicode
+ $this->assertEquals(
+ $str4_j,
+ Horde_Serialize::serialize($str4, Horde_Serialize::JSON)
+ );
+
+ // array case: array with elements and nested arrays
+ $this->assertEquals(
+ '[null,true,[1,2,3],"hello\"],[world!"]',
+ Horde_Serialize::serialize($arr, Horde_Serialize::JSON)
+ );
+
+ // object case: object with properties, nested object and arrays
+ $this->assertEquals(
+ '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}',
+ Horde_Serialize::serialize($obj, Horde_Serialize::JSON)
+ );
+
+ // type case: null
+ $this->assertNull(
+ Horde_Serialize::unserialize('null', Horde_Serialize::JSON)
+ );
+
+ // type case: boolean true
+ $this->assertTrue(
+ Horde_Serialize::unserialize('true', Horde_Serialize::JSON)
+ );
+
+ // type case: boolean false
+ $this->assertFalse(
+ Horde_Serialize::unserialize('false', Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1
+ $this->assertEquals(
+ 1,
+ Horde_Serialize::unserialize('1', Horde_Serialize::JSON)
+ );
+
+ // numeric case: -1
+ $this->assertEquals(
+ -1,
+ Horde_Serialize::unserialize('-1', Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.0
+ $this->assertEquals(
+ 1.0,
+ Horde_Serialize::unserialize('1.0', Horde_Serialize::JSON)
+ );
+ $this->assertInternalType(
+ 'float',
+ Horde_Serialize::unserialize('1.0', Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.1
+ $this->assertEquals(
+ 1.1,
+ Horde_Serialize::unserialize('1.1', Horde_Serialize::JSON)
+ );
+ $this->assertInternalType(
+ 'float',
+ Horde_Serialize::unserialize('1.1', Horde_Serialize::JSON)
+ );
+
+
+ // string case: hello world
+ $this->assertEquals(
+ $str1,
+ Horde_Serialize::unserialize($str1_j, Horde_Serialize::JSON)
+ );
+ $this->assertEquals(
+ "'" . $str1 . "'",
+ Horde_Serialize::unserialize($str1_j_, Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with tab, double-quotes
+ $this->assertEquals(
+ $str2,
+ Horde_Serialize::unserialize($str2_j, Horde_Serialize::JSON)
+ );
+
+ // string case: backslash, return, newline, tab, double-quote
+ $this->assertEquals(
+ $str3,
+ Horde_Serialize::unserialize($str3_j, Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with unicode
+ $this->assertEquals(
+ $str4,
+ Horde_Serialize::unserialize($str4_j, Horde_Serialize::JSON)
+ );
+ $this->assertEquals(
+ $str4,
+ Horde_Serialize::unserialize($str4_j_, Horde_Serialize::JSON)
+ );
+
+ // array case: array with elements and nested arrays
+ $this->assertEquals(
+ $arr,
+ Horde_Serialize::unserialize($arr_j, Horde_Serialize::JSON)
+ );
+
+ // object case: object with properties, nested object and arrays
+ $this->assertEquals(
+ $obj,
+ Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON)
+ );
+
+ // type case: null
+ $this->assertNull(
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(null, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // type case: boolean true
+ $this->assertTrue(
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(true, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // type case: boolean false
+ $this->assertFalse(
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(false, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1
+ $this->assertEquals(
+ 1,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(1, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: -1
+ $this->assertEquals(
+ -1,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(-1, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.0
+ $this->assertEquals(
+ 1,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(1.0, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.1
+ $this->assertEquals(
+ 1.1,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize(1.1, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world
+ $this->assertEquals(
+ $str1,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($str1, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with tab, double-quotes
+ $this->assertEquals(
+ $str2,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($str2, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: backslash, return, newline, tab, double-quote
+ $this->assertEquals(
+ $str3,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($str3, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with unicode
+ $this->assertEquals(
+ $str4,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($str4, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // array case: array with elements and nested arrays
+ $this->assertEquals(
+ $arr,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($arr, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // object case: object with properties, nested object and arrays
+ $this->assertEquals(
+ $obj,
+ Horde_Serialize::unserialize(Horde_Serialize::serialize($obj, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // type case: null
+ $this->assertEquals(
+ 'null',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('null', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // type case: boolean true
+ $this->assertEquals(
+ 'true',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('true', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // type case: boolean false
+ $this->assertEquals(
+ 'false',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('false', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1
+ $this->assertEquals(
+ '1',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('1', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: -1
+ $this->assertEquals(
+ '-1',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('-1', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.0
+ $this->assertEquals(
+ '1.0',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('1.0', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // numeric case: 1.1
+ $this->assertEquals(
+ '1.1',
+ Horde_Serialize::serialize(Horde_Serialize::unserialize('1.1', Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world
+ $this->assertEquals(
+ $str1_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($str1_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with tab, double-quotes
+ $this->assertEquals(
+ $str2_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($str2_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: backslash, return, newline, tab, double-quote
+ $this->assertEquals(
+ $str3_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($str3_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // string case: hello world, with unicode
+ $this->assertEquals(
+ $str4_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($str4_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+ $this->assertEquals(
+ $str4_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($str4_j_, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // array case: array with elements and nested arrays
+ $this->assertEquals(
+ $arr_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($arr_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+
+ // object case: object with properties, nested object and arrays
+ $this->assertEquals(
+ $obj_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON nested arrays tests.
+ public function testJsonNestedArrays()
+ {
+ $str1 = '[{"this":"that"}]';
+ $str1_ob = new stdClass;
+ $str1_ob->this = 'that';
+
+ $str2 = '{"this":["that"]}';
+ $str2_ob = new stdClass;
+ $str2_ob->this = array('that');
+
+ $str3 = '{"params":[{"foo":["1"],"bar":"1"}]}';
+ $str3_ob = new stdClass;
+ $str3_ob2 = new stdClass;
+ $str3_ob2->foo = array(1);
+ $str3_ob2->bar = 1;
+ $str3_ob->params = array($str3_ob2);
+
+ $str4 = '[{"foo": "bar", "baz": "winkle"}]';
+ $str4_ob2 = new stdClass;
+ $str4_ob2->foo = 'bar';
+ $str4_ob2->baz = 'winkle';
+ $str4_ob = array($str4_ob2);
+
+ $str5 = '{"params":[{"options": {"old": [ ], "new": [{"elements": {"old": [], "new": [{"elementName": "aa", "isDefault": false, "elementRank": "0", "priceAdjust": "0", "partNumber": ""}]}}], "optionName": "aa", "isRequired": false, "optionDesc": ""}}]}';
+
+ $str5_ob = new stdClass;
+ $str5_ob->params = array(new stdClass);
+ $str5_ob->params[0]->options = new stdClass;
+ $str5_ob->params[0]->options->old = array();
+ $str5_ob->params[0]->options->new = array(new stdClass);
+ $str5_ob->params[0]->options->new[0]->elements = new stdClass;
+ $str5_ob->params[0]->options->new[0]->elements->old = array();
+ $str5_ob->params[0]->options->new[0]->elements->new = array(new stdClass);
+ $str5_ob->params[0]->options->new[0]->elements->new[0]->elementName = 'aa';
+ $str5_ob->params[0]->options->new[0]->elements->new[0]->isDefault = false;
+ $str5_ob->params[0]->options->new[0]->elements->new[0]->elementRank = 0;
+ $str5_ob->params[0]->options->new[0]->elements->new[0]->priceAdjust = 0;
+ $str5_ob->params[0]->options->new[0]->elements->new[0]->partNumber = '';
+ $str5_ob->params[0]->options->optionName = 'aa';
+ $str5_ob->params[0]->options->isRequired = false;
+ $str5_ob->params[0]->options->optionDesc = '';
+
+ // simple compactly-nested array
+ $this->assertEquals(
+ array($str1_ob),
+ Horde_Serialize::unserialize($str1, Horde_Serialize::JSON)
+ );
+
+ // simple compactly-nested array
+ $this->assertEquals(
+ $str2_ob,
+ Horde_Serialize::unserialize($str2, Horde_Serialize::JSON)
+ );
+
+ // complex compactly nested array
+ $this->assertEquals(
+ $str3_ob,
+ Horde_Serialize::unserialize($str3, Horde_Serialize::JSON)
+ );
+
+ // complex compactly nested array
+ $this->assertEquals(
+ $str4_ob,
+ Horde_Serialize::unserialize($str4, Horde_Serialize::JSON)
+ );
+
+ // super complex compactly nested array
+ $this->assertEquals(
+ $str5_ob,
+ Horde_Serialize::unserialize($str5, Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON objects tests.
+ public function testJsonObjects()
+ {
+ $obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
+
+ $obj1 = new stdClass;
+ $obj1->car1 = new stdClass;
+ $obj1->car1->color = 'tan';
+ $obj1->car1->model = 'sedan';
+ $obj1->car2 = new stdClass;
+ $obj1->car2->color = 'red';
+ $obj1->car2->model = 'sports';
+ $obj1_j = '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}';
+
+ $this->assertInternalType(
+ 'object',
+ Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON)
+ );
+
+ // object - strict: Object with nested objects
+ $this->assertEquals(
+ $obj1_j,
+ Horde_Serialize::serialize($obj1, Horde_Serialize::JSON)
+ );
+
+ // object case
+ $this->assertEquals(
+ $obj_j,
+ Horde_Serialize::serialize(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON), Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON spaces tests.
+ public function testJsonSpaces()
+ {
+ $obj = new stdClass;
+ $obj->a_string = "\"he\":llo}:{world";
+ $obj->an_array = array(1, 2, 3);
+ $obj->obj = new stdClass;
+ $obj->obj->a_number = 123;
+
+ $obj_js = '{"a_string": "\"he\":llo}:{world",
+ "an_array":[1, 2, 3],
+ "obj": {"a_number":123}}';
+
+ // checking whether notation with spaces works
+ $this->assertEquals(
+ $obj,
+ Horde_Serialize::unserialize($obj_js, Horde_Serialize::JSON)
+ );
+ }
+
+ // JSON unquoted keys tests.
+ public function testJsonUnquotedKeys()
+ {
+ $ob1 = new stdClass;
+ $ob1->{'0'} = 'tan';
+ $ob1->model = 'sedan';
+
+ $ob2 = new stdClass;
+ $ob2->{'0'} = 'red';
+ $ob2->model = 'sports';
+
+ $arn = array($ob1, $ob2);
+ $arn_ja = '[{"0":"tan","model":"sedan"},{"0":"red","model":"sports"}]';
+
+ $arrs = new stdClass;
+ $arrs->{'1'} = 'one';
+ $arrs->{'2'} = 'two';
+ $arrs->{'5'} = 'fi"ve';
+ $arrs_jo = '{"1":"one","2":"two","5":"fi\"ve"}';
+
+ // array case - strict: associative array with unquoted keys, nested
+ // associative arrays, and some numeric keys thrown in
+ // ...unless the input array has some numeric indices, in which case
+ // the behavior is to degrade to a regular array
+ $this->assertEquals(
+ $arn_ja,
+ Horde_Serialize::serialize($arn, Horde_Serialize::JSON)
+ );
+
+ // sparse numeric assoc array: associative array with unquoted keys,
+ // single-quoted values, numeric keys which are not fully populated in
+ // a range of 0 to length-1
+ // Test a sparsely populated numerically indexed associative array
+ $this->assertEquals(
+ $arrs_jo,
+ Horde_Serialize::serialize($arrs, Horde_Serialize::JSON)
+ );
+ }
+
+}
+++ /dev/null
---TEST--
-JSON associative arrays tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-function out($str)
-{
- echo "$str\n";
-}
-
-$arr = array('car1'=> array('color'=> 'tan', 'model' => 'sedan'),
- 'car2' => array('color' => 'red', 'model' => 'sports'));
-$arr_jo = '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}';
-
-$arn = array(0 => array(0 => 'tan\\', 'model\\' => 'sedan'), 1 => array(0 => 'red', 'model' => 'sports'));
-$arn_ja = '[{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}]';
-
-$arrs = array(1 => 'one', 2 => 'two', 5 => 'five');
-$arrs_jo = '{"1":"one","2":"two","5":"five"}';
-
-/* Types test */
-
-// strict type should be array
-out(gettype(Horde_Serialize::unserialize($arn_ja, Horde_Serialize::JSON)));
-
-echo"============================================================================\n";
-
-/* Encode tests */
-
-// array case - strict: associative array with nested associative arrays
-out(Horde_Serialize::serialize($arr, Horde_Serialize::JSON));
-
-// array case - strict: associative array with nested associative arrays, and
-// some numeric keys thrown in
-// Should degrade to a numeric array.
-out(Horde_Serialize::serialize($arn, Horde_Serialize::JSON));
-
-// sparse numeric assoc array: associative array numeric keys which are not
-// fully populated in a range of 0 to length-1
-// Test a sparsely populated numerically indexed associative array.
-out(Horde_Serialize::serialize($arrs, Horde_Serialize::JSON));
-
-?>
---EXPECT--
-array
-============================================================================
-{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}
-[{"0":"tan\\","model\\":"sedan"},{"0":"red","model":"sports"}]
-{"1":"one","2":"two","5":"five"}
+++ /dev/null
---TEST--
-JSON empties tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-function out($str)
-{
- echo "$str\n";
-}
-
-$obj0_j = '{}';
-$obj1_j = '{ }';
-$obj2_j = '{ /* comment inside */ }';
-
-/* Types tests */
-
-// should be object
-out(gettype(Horde_Serialize::unserialize($obj0_j, Horde_Serialize::JSON)));
-// should be empty object
-out(count(get_object_vars(Horde_Serialize::unserialize($obj0_j, Horde_Serialize::JSON))));
-
-// should be object, even with space
-out(gettype(Horde_Serialize::unserialize($obj1_j, Horde_Serialize::JSON)));
-// should be empty object, even with space
-out(count(get_object_vars(Horde_Serialize::unserialize($obj1_j, Horde_Serialize::JSON))));
-
-// should be object, despite comment
-out(gettype(Horde_Serialize::unserialize($obj2_j, Horde_Serialize::JSON)));
-// should be empty object, despite comment
-out(count(get_object_vars(Horde_Serialize::unserialize($obj2_j, Horde_Serialize::JSON))));
-
-?>
---EXPECT--
-object
-0
-object
-0
-object
-0
+++ /dev/null
---TEST--
-JSON encode/decode tests (invalid UTF-8 input).
---SKIPIF--
-<?php
- if (version_compare(phpversion(), '5.3.0') == -1) {
- echo "skip Test requires PHP 5.3+";
- }
-?>
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-require dirname(__FILE__) . '/../../../../Util/lib/Horde/String.php';
-require dirname(__FILE__) . '/../../../../Util/lib/Horde/Util.php';
-
-echo Horde_Serialize::serialize(file_get_contents('./fixtures/badutf8.txt'), Horde_Serialize::JSON);
-
-?>
---EXPECT--
-"Note: To play video messages sent to email, QuickTime\u00ae 6.5 or higher is required.\n"
+++ /dev/null
---TEST--
-JSON encode/decode tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-function out($str)
-{
- echo "$str\n";
-}
-
-$obj = new stdClass();
-$obj->a_string = '"he":llo}:{world';
-$obj->an_array = array(1, 2, 3);
-$obj->obj = new stdClass();
-$obj->obj->a_number = 123;
-$obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
-
-$arr = array(null, true, array(1, 2, 3), "hello\"],[world!");
-$arr_j = '[null,true,[1,2,3],"hello\"],[world!"]';
-
-$str1 = 'hello world';
-$str1_j = '"hello world"';
-$str1_j_ = "'hello world'";
-
-$str2 = "hello\t\"world\"";
-$str2_j = '"hello\\t\\"world\\""';
-
-$str3 = "\\\r\n\t\"/";
-$str3_j = '"\\\\\\r\\n\\t\\"\\/"';
-
-$str4 = 'héllö wørłd';
-$str4_j = '"h\u00e9ll\u00f6 w\u00f8r\u0142d"';
-$str4_j_ = '"héllö wørłd"';
-
-/* Encode tests. */
-
-// type case: null
-out(Horde_Serialize::serialize(null, Horde_Serialize::JSON));
-// type case: boolean true
-out(Horde_Serialize::serialize(true, Horde_Serialize::JSON));
-// type case: boolean false
-out(Horde_Serialize::serialize(false, Horde_Serialize::JSON));
-
-// numeric case: 1
-out(Horde_Serialize::serialize(1, Horde_Serialize::JSON));
-// numeric case: -1
-out(Horde_Serialize::serialize(-1, Horde_Serialize::JSON));
-// numeric case: 1.0
-out(Horde_Serialize::serialize(1.0, Horde_Serialize::JSON));
-// numeric case: 1.1
-out(Horde_Serialize::serialize(1.1, Horde_Serialize::JSON));
-
-// string case: hello world
-out(Horde_Serialize::serialize($str1, Horde_Serialize::JSON));
-// string case: hello world, with tab, double-quotes
-out(Horde_Serialize::serialize($str2, Horde_Serialize::JSON));
-// string case: backslash, return, newline, tab, double-quote
-out(Horde_Serialize::serialize($str3, Horde_Serialize::JSON));
-// string case: hello world, with unicode
-out(Horde_Serialize::serialize($str4, Horde_Serialize::JSON));
-
-// array case: array with elements and nested arrays
-out(Horde_Serialize::serialize($arr, Horde_Serialize::JSON));
-// object case: object with properties, nested object and arrays
-out(Horde_Serialize::serialize($obj, Horde_Serialize::JSON));
-
-echo"============================================================================\n";
-
-/* Decode tests */
-
-// type case: null
-var_dump(Horde_Serialize::unserialize('null', Horde_Serialize::JSON));
-// type case: boolean true
-var_dump(Horde_Serialize::unserialize('true', Horde_Serialize::JSON));
-// type case: boolean false
-var_dump(Horde_Serialize::unserialize('false', Horde_Serialize::JSON));
-
-// numeric case: 1
-var_dump(Horde_Serialize::unserialize('1', Horde_Serialize::JSON));
-// numeric case: -1
-var_dump(Horde_Serialize::unserialize('-1', Horde_Serialize::JSON));
-// numeric case: 1.0
-var_dump(Horde_Serialize::unserialize('1.0', Horde_Serialize::JSON));
-// numeric case: 1.1
-var_dump(Horde_Serialize::unserialize('1.1', Horde_Serialize::JSON));
-
-// string case: hello world
-var_dump(Horde_Serialize::unserialize($str1_j, Horde_Serialize::JSON));
-var_dump(Horde_Serialize::unserialize($str1_j_, Horde_Serialize::JSON));
-// string case: hello world, with tab, double-quotes
-var_dump(Horde_Serialize::unserialize($str2_j, Horde_Serialize::JSON));
-// string case: backslash, return, newline, tab, double-quote
-var_dump(Horde_Serialize::unserialize($str3_j, Horde_Serialize::JSON));
-// string case: hello world, with unicode
-var_dump(Horde_Serialize::unserialize($str4_j, Horde_Serialize::JSON));
-var_dump(Horde_Serialize::unserialize($str4_j_, Horde_Serialize::JSON));
-
-// array case: array with elements and nested arrays
-var_dump(Horde_Serialize::unserialize($arr_j, Horde_Serialize::JSON));
-// object case: object with properties, nested object and arrays
-var_dump(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON));
-
-echo"============================================================================\n";
-
-/* Encode-decode tests */
-
-// type case: null
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(null, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// type case: boolean true
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(true, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// type case: boolean false
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(false, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// numeric case: 1
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(1, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: -1
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(-1, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: 1.0
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(1.0, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: 1.1
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize(1.1, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// string case: hello world
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($str1, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: hello world, with tab, double-quotes
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($str2, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: backslash, return, newline, tab, double-quote
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($str3, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: hello world, with unicode
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($str4, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// array case: array with elements and nested arrays
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($arr, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// object case: object with properties, nested object and arrays
-var_dump(Horde_Serialize::unserialize(Horde_Serialize::serialize($obj, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-echo"============================================================================\n";
-
-/* Decode-encode tests */
-
-// type case: null
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('null', Horde_Serialize::JSON), Horde_Serialize::JSON));
-// type case: boolean true
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('true', Horde_Serialize::JSON), Horde_Serialize::JSON));
-// type case: boolean false
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('false', Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// numeric case: 1
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('1', Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: -1
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('-1', Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: 1.0
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('1.0', Horde_Serialize::JSON), Horde_Serialize::JSON));
-// numeric case: 1.1
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize('1.1', Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// string case: hello world
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($str1_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: hello world, with tab, double-quotes
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($str2_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: backslash, return, newline, tab, double-quote
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($str3_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// string case: hello world, with unicode
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($str4_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($str4_j_, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-// array case: array with elements and nested arrays
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($arr_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-// object case: object with properties, nested object and arrays
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-?>
---EXPECT--
-null
-true
-false
-1
--1
-1
-1.1
-"hello world"
-"hello\t\"world\""
-"\\\r\n\t\"\/"
-"h\u00e9ll\u00f6 w\u00f8r\u0142d"
-[null,true,[1,2,3],"hello\"],[world!"]
-{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}
-============================================================================
-NULL
-bool(true)
-bool(false)
-int(1)
-int(-1)
-float(1)
-float(1.1)
-string(11) "hello world"
-string(11) "hello world"
-string(13) "hello "world""
-string(6) "\
- "/"
-string(15) "héllö wørłd"
-string(15) "héllö wørłd"
-array(4) {
- [0]=>
- NULL
- [1]=>
- bool(true)
- [2]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- [3]=>
- string(15) "hello"],[world!"
-}
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-============================================================================
-NULL
-bool(true)
-bool(false)
-int(1)
-int(-1)
-int(1)
-float(1.1)
-string(11) "hello world"
-string(13) "hello "world""
-string(6) "\
- "/"
-string(15) "héllö wørłd"
-array(4) {
- [0]=>
- NULL
- [1]=>
- bool(true)
- [2]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- [3]=>
- string(15) "hello"],[world!"
-}
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-============================================================================
-null
-true
-false
-1
--1
-1
-1.1
-"hello world"
-"hello\t\"world\""
-"\\\r\n\t\"\/"
-"h\u00e9ll\u00f6 w\u00f8r\u0142d"
-"h\u00e9ll\u00f6 w\u00f8r\u0142d"
-[null,true,[1,2,3],"hello\"],[world!"]
-{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}
+++ /dev/null
---TEST--
-JSON nested arrays tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-$str1 = '[{"this":"that"}]';
-$str2 = '{"this":["that"]}';
-$str3 = '{"params":[{"foo":["1"],"bar":"1"}]}';
-$str4 = '{"0": {"foo": "bar", "baz": "winkle"}}';
-$str5 = '{"params":[{"options": {"old": [ ], "new": {"0": {"elements": {"old": [], "new": {"0": {"elementName": "aa", "isDefault": false, "elementRank": "0", "priceAdjust": "0", "partNumber": ""}}}, "optionName": "aa", "isRequired": false, "optionDesc": ""}}}}]}';
-
-/* Decode tests */
-
-// simple compactly-nested array
-var_dump(Horde_Serialize::unserialize($str1, Horde_Serialize::JSON));
-// simple compactly-nested array
-var_dump(Horde_Serialize::unserialize($str2, Horde_Serialize::JSON));
-// complex compactly nested array
-var_dump(Horde_Serialize::unserialize($str3, Horde_Serialize::JSON));
-// complex compactly nested array
-var_dump(Horde_Serialize::unserialize($str4, Horde_Serialize::JSON));
-// super complex compactly nested array
-var_dump(Horde_Serialize::unserialize($str5, Horde_Serialize::JSON));
-
-?>
---EXPECT--
-array(1) {
- [0]=>
- object(stdClass)(1) {
- ["this"]=>
- string(4) "that"
- }
-}
-object(stdClass)(1) {
- ["this"]=>
- array(1) {
- [0]=>
- string(4) "that"
- }
-}
-object(stdClass)(1) {
- ["params"]=>
- array(1) {
- [0]=>
- object(stdClass)(2) {
- ["foo"]=>
- array(1) {
- [0]=>
- string(1) "1"
- }
- ["bar"]=>
- string(1) "1"
- }
- }
-}
-object(stdClass)(1) {
- [0]=>
- object(stdClass)(2) {
- ["foo"]=>
- string(3) "bar"
- ["baz"]=>
- string(6) "winkle"
- }
-}
-object(stdClass)(1) {
- ["params"]=>
- array(1) {
- [0]=>
- object(stdClass)(1) {
- ["options"]=>
- object(stdClass)(2) {
- ["old"]=>
- array(0) {
- }
- ["new"]=>
- object(stdClass)(1) {
- [0]=>
- object(stdClass)(4) {
- ["elements"]=>
- object(stdClass)(2) {
- ["old"]=>
- array(0) {
- }
- ["new"]=>
- object(stdClass)(1) {
- [0]=>
- object(stdClass)(5) {
- ["elementName"]=>
- string(2) "aa"
- ["isDefault"]=>
- bool(false)
- ["elementRank"]=>
- string(1) "0"
- ["priceAdjust"]=>
- string(1) "0"
- ["partNumber"]=>
- string(0) ""
- }
- }
- }
- ["optionName"]=>
- string(2) "aa"
- ["isRequired"]=>
- bool(false)
- ["optionDesc"]=>
- string(0) ""
- }
- }
- }
- }
- }
-}
+++ /dev/null
---TEST--
-JSON objects tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-function out($str)
-{
- echo "$str\n";
-}
-
-$obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
-
-$obj1->car1->color = 'tan';
-$obj1->car1->model = 'sedan';
-$obj1->car2->color = 'red';
-$obj1->car2->model = 'sports';
-$obj1_j = '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}';
-
-/* Types test */
-
-// checking whether decoded type is object
-out(gettype(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON)));
-
-/* Encode test */
-
-// object - strict: Object with nested objects
-out(Horde_Serialize::serialize($obj1, Horde_Serialize::JSON));
-
-/* Decode/encode test */
-
-// object case
-out(Horde_Serialize::serialize(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON), Horde_Serialize::JSON));
-
-?>
---EXPECT--
-object
-{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}
-{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}
+++ /dev/null
---TEST--
-JSON spaces and comments tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-$obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
-
-$obj_js = '{"a_string": "\"he\":llo}:{world",
- "an_array":[1, 2, 3],
- "obj": {"a_number":123}}';
-
-$obj_jc1 = '{"a_string": "\"he\":llo}:{world",
- // here is a comment, hoorah
- "an_array":[1, 2, 3],
- "obj": {"a_number":123}}';
-
-$obj_jc2 = '/* this here is the sneetch */ "the sneetch"
- // this has been the sneetch.';
-
-$obj_jc3 = '{"a_string": "\"he\":llo}:{world",
- /* here is a comment, hoorah */
- "an_array":[1, 2, 3 /* and here is another */],
- "obj": {"a_number":123}}';
-
-$obj_jc4 = '{\'a_string\': "\"he\":llo}:{world",
- /* here is a comment, hoorah */
- \'an_array\':[1, 2, 3 /* and here is another */],
- "obj": {"a_number":123}}';
-
-// Base result
-var_dump(Horde_Serialize::unserialize($obj_j, Horde_Serialize::JSON));
-
-/* Spaces tests */
-
-// checking whether notation with spaces works
-var_dump(Horde_Serialize::unserialize($obj_js, Horde_Serialize::JSON));
-
-/* Comments tests */
-
-// checking whether notation with single line comments works
-var_dump(Horde_Serialize::unserialize($obj_jc1, Horde_Serialize::JSON));
-
-// checking whether notation with multiline comments works
-var_dump(Horde_Serialize::unserialize($obj_jc2, Horde_Serialize::JSON));
-var_dump(Horde_Serialize::unserialize($obj_jc3, Horde_Serialize::JSON));
-
-// checking whether notation with single-quotes and multiline comments works
-var_dump(Horde_Serialize::unserialize($obj_jc4, Horde_Serialize::JSON));
-
-?>
---EXPECT--
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-string(11) "the sneetch"
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
-object(stdClass)(3) {
- ["a_string"]=>
- string(16) ""he":llo}:{world"
- ["an_array"]=>
- array(3) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- }
- ["obj"]=>
- object(stdClass)(1) {
- ["a_number"]=>
- int(123)
- }
-}
+++ /dev/null
---TEST--
-JSON unquoted keys tests.
---FILE--
-<?php
-
-error_reporting(E_ALL);
-require dirname(__FILE__) . '/../../../lib/Horde/Serialize.php';
-
-$ob1->{'0'} = 'tan';
-$ob1->model = 'sedan';
-$ob2->{'0'} = 'red';
-$ob2->model = 'sports';
-$arn = array($ob1, $ob2);
-$arn_ja = '[{0:"tan","model":"sedan"},{"0":"red",model:"sports"}]';
-
-$arrs->{'1'} = 'one';
-$arrs->{'2'} = 'two';
-$arrs->{'5'} = 'fi"ve';
-$arrs_jo = '{"1":"one",2:"two","5":\'fi"ve\'}';
-
-/* Decode tests */
-
-// array case - strict: associative array with unquoted keys, nested
-// associative arrays, and some numeric keys thrown in
-// ...unless the input array has some numeric indeces, in which case the
-// behavior is to degrade to a regular array
-var_dump(Horde_Serialize::unserialize($arn_ja, Horde_Serialize::JSON));
-
-// sparse numeric assoc array: associative array with unquoted keys,
-// single-quoted values, numeric keys which are not fully populated in a range
-// of 0 to length-1
-// Test a sparsely populated numerically indexed associative array
-var_dump(Horde_Serialize::unserialize($arrs_jo, Horde_Serialize::JSON));
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- object(stdClass)(2) {
- [0]=>
- string(3) "tan"
- ["model"]=>
- string(5) "sedan"
- }
- [1]=>
- object(stdClass)(2) {
- [0]=>
- string(3) "red"
- ["model"]=>
- string(6) "sports"
- }
-}
-object(stdClass)(3) {
- [1]=>
- string(3) "one"
- [2]=>
- string(3) "two"
- [5]=>
- string(5) "fi"ve"
-}