| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_XmlRpc
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
- if (!defined("PHPUnit_MAIN_METHOD")) {
- require_once dirname(__FILE__) . '/../../TestHelper.php';
- define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_ValueTest::main");
- }
- require_once "PHPUnit/Framework/TestCase.php";
- require_once "PHPUnit/Framework/TestSuite.php";
- require_once 'Zend/XmlRpc/Value.php';
- require_once 'Zend/XmlRpc/Value/Scalar.php';
- require_once 'Zend/XmlRpc/Value/BigInteger.php';
- require_once 'Zend/XmlRpc/Value/Collection.php';
- require_once 'Zend/XmlRpc/Value/Array.php';
- require_once 'Zend/XmlRpc/Value/Base64.php';
- require_once 'Zend/XmlRpc/Value/Boolean.php';
- require_once 'Zend/XmlRpc/Value/DateTime.php';
- require_once 'Zend/XmlRpc/Value/Double.php';
- require_once 'Zend/XmlRpc/Value/Integer.php';
- require_once 'Zend/XmlRpc/Value/String.php';
- require_once 'Zend/XmlRpc/Value/Nil.php';
- require_once 'Zend/XmlRpc/Value/Struct.php';
- require_once 'Zend/Crypt/Math/BigInteger.php';
- require_once 'Zend/XmlRpc/Generator/DOMDocument.php';
- require_once 'Zend/XmlRpc/Generator/XMLWriter.php';
- require_once 'Zend/XmlRpc/TestProvider.php';
- /**
- * Test case for Zend_XmlRpc_Value
- *
- * @category Zend
- * @package Zend_XmlRpc
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_XmlRpc
- */
- class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs the test methods of this class.
- *
- * @return void
- */
- public static function main()
- {
- require_once "PHPUnit/TextUI/TestRunner.php";
- $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_ValueTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- // Boolean
- public function testFactoryAutodetectsBoolean()
- {
- foreach (array(true, false) as $native) {
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native);
- $this->assertXmlRpcType('boolean', $val);
- }
- }
- public function testMarshalBooleanFromNative()
- {
- $native = true;
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN);
- $this->assertXmlRpcType('boolean', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalBooleanFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $xml = '<value><boolean>1</boolean></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('boolean', $val);
- $this->assertEquals('boolean', $val->getType());
- $this->assertSame(true, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- // Integer
- public function testFactoryAutodetectsInteger()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue(1);
- $this->assertXmlRpcType('integer', $val);
- }
- public function testMarshalIntegerFromNative()
- {
- $native = 1;
- $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_I4,
- Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
- foreach ($types as $type) {
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
- $this->assertXmlRpcType('integer', $val);
- $this->assertSame($native, $val->getValue());
- }
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalIntegerFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = 1;
- $xmls = array("<value><int>$native</int></value>",
- "<value><i4>$native</i4></value>");
- foreach ($xmls as $xml) {
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('integer', $val);
- $this->assertEquals('int', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- }
- /**
- * @group ZF-3310
- */
- public function testMarshalI4FromOverlongNativeThrowsException()
- {
- $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
- Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_I4);
- }
- /**
- * @group ZF-3310
- */
- public function testMarshalIntegerFromOverlongNativeThrowsException()
- {
- $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
- Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
- }
- // BigInteger
- /**
- * @group ZF-6445
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalBigIntegerFromFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $bigInt = (string)(PHP_INT_MAX + 1);
- $native = new Zend_Crypt_Math_BigInteger();
- $native->init($bigInt);
- $xmlStrings = array("<value><i8>$bigInt</i8></value>",
- "<value><ex:i8 xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">$bigInt</ex:i8></value>");
- foreach ($xmlStrings as $xml) {
- $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
- $this->assertEquals($native, $value->getValue());
- $this->assertEquals('i8', $value->getType());
- $this->assertEquals($this->wrapXml($xml), $value->saveXml());
- }
- }
- /**
- * @group ZF-6445
- */
- public function testMarshalBigIntegerFromNative()
- {
- $native = (string)(PHP_INT_MAX + 1);
- $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8,
- Zend_XmlRpc_Value::XMLRPC_TYPE_I8);
- $bigInt = new Zend_Crypt_Math_BigInteger();
- $bigInt->init($native);
- foreach ($types as $type) {
- $value = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
- $this->assertSame('i8', $value->getType());
- $this->assertEquals($bigInt, $value->getValue());
- }
- }
- // Double
- public function testFactoryAutodetectsFloat()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue((float)1);
- $this->assertXmlRpcType('double', $val);
- }
- public function testMarshalDoubleFromNative()
- {
- $native = 1.1;
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE);
- $this->assertXmlRpcType('double', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalDoubleFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = 1.1;
- $xml = "<value><double>$native</double></value>";
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('double', $val);
- $this->assertEquals('double', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @group ZF-7712
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingDoubleWithHigherPrecisionFromNative(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- if (ini_get('precision') < 7) {
- $this->markTestSkipped('precision is too low');
- }
- $native = 0.1234567;
- $value = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE);
- $this->assertXmlRpcType('double', $value);
- $this->assertSame($native, $value->getValue());
- $this->assertSame('<value><double>0.1234567</double></value>', trim($value->saveXml()));
- }
- /**
- * @group ZF-7712
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingDoubleWithHigherPrecisionFromNativeWithTrailingZeros(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- if (ini_get('precision') < 7) {
- $this->markTestSkipped('precision is too low');
- }
- $native = 0.1;
- $value = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE);
- $this->assertXmlRpcType('double', $value);
- $this->assertSame($native, $value->getValue());
- $this->assertSame('<value><double>0.1</double></value>', trim($value->saveXml()));
- }
- // String
- public function testFactoryAutodetectsString()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue('');
- $this->assertXmlRpcType('string', $val);
- }
- public function testMarshalStringFromNative()
- {
- $native = 'foo';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_STRING);
- $this->assertXmlRpcType('string', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalStringFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = 'foo';
- $xml = "<value><string>$native</string></value>";
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('string', $val);
- $this->assertEquals('string', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalStringFromDefault(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = 'foo';
- $xml = "<string>$native</string>";
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('string', $val);
- $this->assertEquals('string', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- //Nil
- public function testFactoryAutodetectsNil()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue(NULL);
- $this->assertXmlRpcType('nil', $val);
- }
- public function testMarshalNilFromNative()
- {
- $native = NULL;
- $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_NIL,
- Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL);
- foreach ($types as $type) {
- $value = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
- $this->assertXmlRpcType('nil', $value);
- $this->assertSame($native, $value->getValue());
- }
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalNilFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $xmls = array('<value><nil/></value>',
- '<value><ex:nil xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions"/></value>');
- foreach ($xmls as $xml) {
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('nil', $val);
- $this->assertEquals('nil', $val->getType());
- $this->assertSame(NULL, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- }
- // Array
- public function testFactoryAutodetectsArray()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue(array(0, 'foo'));
- $this->assertXmlRpcType('array', $val);
- }
- public function testMarshalArrayFromNative()
- {
- $native = array(0,1);
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY);
- $this->assertXmlRpcType('array', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalArrayFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array(0,1);
- $xml = '<value><array><data><value><int>0</int></value>'
- . '<value><int>1</int></value></data></array></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('array', $val);
- $this->assertEquals('array', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testEmptyXmlRpcArrayResultsInEmptyArray(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array();
- $xml = '<value><array><data/></array></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('array', $val);
- $this->assertEquals('array', $val->getType());
- $this->assertSame($native, $val->getValue());
- $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('array', $value);
- $this->assertEquals('array', $value->getType());
- $this->assertSame($native, $value->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testArrayMustContainDataElement(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array();
- $xml = '<value><array/></value>';
- $this->setExpectedException('Zend_XmlRpc_Value_Exception',
- 'Invalid XML for XML-RPC native array type: ARRAY tag must contain DATA tag');
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- }
- /**
- * @group ZF-5405
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalNilInStructWrappedInArray(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $expected = array(array('id' => '1', 'name' => 'vertebra, caudal', 'description' => null));
- $xml = '<value>'
- . '<array><data><value><struct><member><name>id</name><value><string>1</string></value></member>'
- . '<member><name>name</name><value><string>vertebra, caudal</string></value></member>'
- . '<member><name>description</name><value><nil/></value></member></struct></value></data></array>'
- . '</value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
- $this->assertSame($expected, $val->getValue());
- }
- // Struct
- public function testFactoryAutodetectsStruct()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue(array('foo' => 0));
- $this->assertXmlRpcType('struct', $val);
- }
- public function testFactoryAutodetectsStructFromObject()
- {
- $val = Zend_XmlRpc_Value::getXmlRpcValue((object)array('foo' => 0));
- $this->assertXmlRpcType('struct', $val);
- }
- public function testMarshalStructFromNative()
- {
- $native = array('foo' => 0);
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
- $this->assertXmlRpcType('struct', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalStructFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array('foo' => 0);
- $xml = '<value><struct><member><name>foo</name><value><int>0</int>'
- . '</value></member></struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertEquals('struct', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingStructWithMemberWithoutValue(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array('foo' => 0, 'bar' => 1);
- $xml = '<value><struct>'
- . '<member><name>foo</name><value><int>0</int></value></member>'
- . '<member><name>foo</name><bar/></member>'
- . '<member><name>bar</name><value><int>1</int></value></member>'
- . '</struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertEquals('struct', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingStructWithMemberWithoutName(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array('foo' => 0, 'bar' => 1);
- $xml = '<value><struct>'
- . '<member><name>foo</name><value><int>0</int></value></member>'
- . '<member><value><string>foo</string></value></member>'
- . '<member><name>bar</name><value><int>1</int></value></member>'
- . '</struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertEquals('struct', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @group ZF-7639
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalStructFromXmlRpcWithEntities(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array(' ' => 0);
- $xml = '<value><struct><member><name>&nbsp;</name><value><int>0</int>'
- . '</value></member></struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertSame($native, $val->getValue());
- $this->assertSame($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @group ZF-3947
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingStructsWithEmptyValueFromXmlRpcShouldRetainKeys(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array('foo' => '');
- $xml = '<value><struct><member><name>foo</name>'
- . '<value><string/></value></member></struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertEquals('struct', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshallingStructWithMultibyteValueFromXmlRpcRetainsMultibyteValue(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = array('foo' => 'ß');
- $xmlDecl = '<?xml version="1.0" encoding="UTF-8"?>';
- $xml = '<value><struct><member><name>foo</name><value><string>ß</string></value></member></struct></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xmlDecl . $xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('struct', $val);
- $this->assertEquals('struct', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
- $this->assertSame($native, $val->getValue());
- $this->assertSame(trim($xml), trim($val->saveXml()));
- }
- // DateTime
- public function testMarshalDateTimeFromNativeString()
- {
- $native = '1997-07-16T19:20+01:00';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
- $this->assertXmlRpcType('dateTime', $val);
- $expected = '1997-07-16T19:20+01:00';
- $this->assertSame(strtotime($native), strtotime($val->getValue()));
- }
- public function testMarshalDateTimeFromNativeStringProducesIsoOutput()
- {
- $native = '1997-07-16T19:20+01:00';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
- $this->assertXmlRpcType('dateTime', $val);
- $expected = date('c', strtotime($native));
- $expected = substr($expected, 0, strlen($expected) - 6);
- $expected = str_replace('-', '', $expected);
- $received = $val->getValue();
- $this->assertEquals($expected, $received);
- }
- public function testMarshalDateTimeFromInvalidString()
- {
- $this->setExpectedException('Zend_XmlRpc_Value_Exception',
- "Cannot convert given value 'foobarbaz' to a timestamp");
- Zend_XmlRpc_Value::getXmlRpcValue('foobarbaz', Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
- }
- public function testMarshalDateTimeFromNativeInteger()
- {
- $native = strtotime('1997-07-16T19:20+01:00');
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
- $this->assertXmlRpcType('dateTime', $val);
- $this->assertSame($native, strtotime($val->getValue()));
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalDateTimeFromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $iso8601 = '1997-07-16T19:20+01:00';
- $xml = "<value><dateTime.iso8601>$iso8601</dateTime.iso8601></value>";
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('dateTime', $val);
- $this->assertEquals('dateTime.iso8601', $val->getType());
- $this->assertSame(strtotime($iso8601), strtotime($val->getValue()));
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- // Base64
- public function testMarshalBase64FromString()
- {
- $native = 'foo';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
- $this->assertXmlRpcType('base64', $val);
- $this->assertSame($native, $val->getValue());
- }
- /**
- * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
- */
- public function testMarshalBase64FromXmlRpc(Zend_XmlRpc_Generator_Abstract $generator)
- {
- Zend_XmlRpc_Value::setGenerator($generator);
- $native = 'foo';
- $xml = '<value><base64>' .base64_encode($native). '</base64></value>';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
- Zend_XmlRpc_Value::XML_STRING);
- $this->assertXmlRpcType('base64', $val);
- $this->assertEquals('base64', $val->getType());
- $this->assertSame($native, $val->getValue());
- $this->assertEquals($this->wrapXml($xml), $val->saveXml());
- }
- public function testXmlRpcValueBase64GeneratedXmlContainsBase64EncodedText()
- {
- $native = 'foo';
- $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
- Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
- $this->assertXmlRpcType('base64', $val);
- $xml = $val->saveXml();
- $encoded = base64_encode($native);
- $this->assertContains($encoded, $xml);
- }
- /**
- * @group ZF-3862
- */
- public function testMarshalSerializedObjectAsBase64()
- {
- $o = new Zend_XmlRpc_SerializableTestClass();
- $o->setProperty('foobar');
- $serialized = serialize($o);
- $val = Zend_XmlRpc_Value::getXmlRpcValue($serialized,
- Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
- $this->assertXmlRpcType('base64', $val);
- $o2 = unserialize($val->getValue());
- $this->assertSame('foobar', $o2->getProperty());
- }
- // Exceptions
- public function testFactoryThrowsWhenInvalidTypeSpecified()
- {
- try {
- Zend_XmlRpc_Value::getXmlRpcValue('', 'bad type here');
- $this->fail();
- } catch (Exception $e) {
- $this->assertRegexp('/given type is not/i', $e->getMessage());
- }
- }
- // Custom Assertions and Helper Methods
- public function assertXmlRpcType($type, $object)
- {
- $type = 'Zend_XmlRpc_Value_' . ucfirst($type);
- $this->assertType($type, $object);
- }
- public function wrapXml($xml)
- {
- return $xml . "\n";
- }
- }
- class Zend_XmlRpc_SerializableTestClass
- {
- protected $_property;
- public function setProperty($property)
- {
- $this->_property = $property;
- }
- public function getProperty()
- {
- return $this->_property;
- }
- }
- // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ValueTest::main") {
- Zend_XmlRpc_ValueTest::main();
- }
|