ValueTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_XmlRpc
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. require_once dirname(__FILE__) . '/../../TestHelper.php';
  25. define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_ValueTest::main");
  26. }
  27. require_once "PHPUnit/Framework/TestCase.php";
  28. require_once "PHPUnit/Framework/TestSuite.php";
  29. require_once 'Zend/XmlRpc/Value.php';
  30. require_once 'Zend/XmlRpc/Value/Scalar.php';
  31. require_once 'Zend/XmlRpc/Value/Collection.php';
  32. require_once 'Zend/XmlRpc/Value/Array.php';
  33. require_once 'Zend/XmlRpc/Value/Base64.php';
  34. require_once 'Zend/XmlRpc/Value/Boolean.php';
  35. require_once 'Zend/XmlRpc/Value/DateTime.php';
  36. require_once 'Zend/XmlRpc/Value/Double.php';
  37. require_once 'Zend/XmlRpc/Value/Integer.php';
  38. require_once 'Zend/XmlRpc/Value/String.php';
  39. require_once 'Zend/XmlRpc/Value/Nil.php';
  40. require_once 'Zend/XmlRpc/Value/Struct.php';
  41. /**
  42. * Test case for Zend_XmlRpc_Value
  43. *
  44. * @category Zend
  45. * @package Zend_XmlRpc
  46. * @subpackage UnitTests
  47. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. * @group Zend_XmlRpc
  50. */
  51. class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
  52. {
  53. /**
  54. * Runs the test methods of this class.
  55. *
  56. * @return void
  57. */
  58. public static function main()
  59. {
  60. require_once "PHPUnit/TextUI/TestRunner.php";
  61. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_ValueTest");
  62. $result = PHPUnit_TextUI_TestRunner::run($suite);
  63. }
  64. // Boolean
  65. public function testFactoryAutodetectsBoolean()
  66. {
  67. foreach (array(true, false) as $native) {
  68. $val = Zend_XmlRpc_Value::getXmlRpcValue($native);
  69. $this->assertXmlRpcType('boolean', $val);
  70. }
  71. }
  72. public function testMarshalBooleanFromNative()
  73. {
  74. $native = true;
  75. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  76. Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN);
  77. $this->assertXmlRpcType('boolean', $val);
  78. $this->assertSame($native, $val->getValue());
  79. }
  80. public function testMarshalBooleanFromXmlRpc()
  81. {
  82. $xml = '<value><boolean>1</boolean></value>';
  83. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  84. Zend_XmlRpc_Value::XML_STRING);
  85. $this->assertXmlRpcType('boolean', $val);
  86. $this->assertEquals('boolean', $val->getType());
  87. $this->assertSame(true, $val->getValue());
  88. $this->assertType('DomElement', $val->getAsDOM());
  89. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  90. }
  91. // Integer
  92. public function testFactoryAutodetectsInteger()
  93. {
  94. $val = Zend_XmlRpc_Value::getXmlRpcValue(1);
  95. $this->assertXmlRpcType('integer', $val);
  96. }
  97. public function testMarshalIntegerFromNative()
  98. {
  99. $native = 1;
  100. $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_I4,
  101. Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
  102. foreach ($types as $type) {
  103. $val = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
  104. $this->assertXmlRpcType('integer', $val);
  105. $this->assertSame($native, $val->getValue());
  106. }
  107. }
  108. public function testMarshalIntegerFromXmlRpc()
  109. {
  110. $native = 1;
  111. $xmls = array("<value><int>$native</int></value>",
  112. "<value><i4>$native</i4></value>");
  113. foreach ($xmls as $xml) {
  114. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  115. Zend_XmlRpc_Value::XML_STRING);
  116. $this->assertXmlRpcType('integer', $val);
  117. $this->assertEquals('int', $val->getType());
  118. $this->assertSame($native, $val->getValue());
  119. $this->assertType('DomElement', $val->getAsDOM());
  120. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  121. }
  122. }
  123. /**
  124. * @group ZF-3310
  125. */
  126. public function testMarshalI4FromOverlongNativeThrowsException()
  127. {
  128. $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
  129. Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_I4);
  130. }
  131. /**
  132. * @group ZF-3310
  133. */
  134. public function testMarshalIntegerFromOverlongNativeThrowsException()
  135. {
  136. $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
  137. Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
  138. }
  139. // Double
  140. public function testFactoryAutodetectsFloat()
  141. {
  142. $val = Zend_XmlRpc_Value::getXmlRpcValue((float)1);
  143. $this->assertXmlRpcType('double', $val);
  144. }
  145. public function testMarshalDoubleFromNative()
  146. {
  147. $native = 1.1;
  148. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  149. Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE);
  150. $this->assertXmlRpcType('double', $val);
  151. $this->assertSame($native, $val->getValue());
  152. }
  153. public function testMarshalDoubleFromXmlRpc()
  154. {
  155. $native = 1.1;
  156. $xml = "<value><double>$native</double></value>";
  157. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  158. Zend_XmlRpc_Value::XML_STRING);
  159. $this->assertXmlRpcType('double', $val);
  160. $this->assertEquals('double', $val->getType());
  161. $this->assertSame($native, $val->getValue());
  162. $this->assertType('DomElement', $val->getAsDOM());
  163. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  164. }
  165. /**
  166. * @group ZF-7712
  167. */
  168. public function testMarshallingDoubleWithHigherPrecisionFromNative()
  169. {
  170. if (ini_get('precision') < 7) {
  171. $this->markTestSkipped('precision is too low');
  172. }
  173. $native = 0.1234567;
  174. $value = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE);
  175. $this->assertXmlRpcType('double', $value);
  176. $this->assertSame($native, $value->getValue());
  177. }
  178. // String
  179. public function testFactoryAutodetectsString()
  180. {
  181. $val = Zend_XmlRpc_Value::getXmlRpcValue('');
  182. $this->assertXmlRpcType('string', $val);
  183. }
  184. public function testMarshalStringFromNative()
  185. {
  186. $native = 'foo';
  187. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  188. Zend_XmlRpc_Value::XMLRPC_TYPE_STRING);
  189. $this->assertXmlRpcType('string', $val);
  190. $this->assertSame($native, $val->getValue());
  191. }
  192. public function testMarshalStringFromXmlRpc()
  193. {
  194. $native = 'foo';
  195. $xml = "<value><string>$native</string></value>";
  196. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  197. Zend_XmlRpc_Value::XML_STRING);
  198. $this->assertXmlRpcType('string', $val);
  199. $this->assertEquals('string', $val->getType());
  200. $this->assertSame($native, $val->getValue());
  201. $this->assertType('DomElement', $val->getAsDOM());
  202. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  203. }
  204. public function testMarshalStringFromDefault()
  205. {
  206. $native = 'foo';
  207. $xml = "<string>$native</string>";
  208. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  209. Zend_XmlRpc_Value::XML_STRING);
  210. $this->assertXmlRpcType('string', $val);
  211. $this->assertEquals('string', $val->getType());
  212. $this->assertSame($native, $val->getValue());
  213. $this->assertType('DomElement', $val->getAsDOM());
  214. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  215. }
  216. //Nil
  217. public function testFactoryAutodetectsNil()
  218. {
  219. $val = Zend_XmlRpc_Value::getXmlRpcValue(NULL);
  220. $this->assertXmlRpcType('nil', $val);
  221. }
  222. public function testMarshalNilFromNative()
  223. {
  224. $native = NULL;
  225. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  226. Zend_XmlRpc_Value::XMLRPC_TYPE_NIL);
  227. $this->assertXmlRpcType('nil', $val);
  228. $this->assertSame($native, $val->getValue());
  229. }
  230. public function testMarshalNilFromXmlRpc()
  231. {
  232. $xml = '<value><nil/></value>';
  233. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  234. Zend_XmlRpc_Value::XML_STRING);
  235. $this->assertXmlRpcType('nil', $val);
  236. $this->assertEquals('nil', $val->getType());
  237. $this->assertSame(NULL, $val->getValue());
  238. $this->assertType('DomElement', $val->getAsDOM());
  239. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  240. }
  241. // Array
  242. public function testFactoryAutodetectsArray()
  243. {
  244. $val = Zend_XmlRpc_Value::getXmlRpcValue(array(0, 'foo'));
  245. $this->assertXmlRpcType('array', $val);
  246. }
  247. public function testMarshalArrayFromNative()
  248. {
  249. $native = array(0,1);
  250. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  251. Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY);
  252. $this->assertXmlRpcType('array', $val);
  253. $this->assertSame($native, $val->getValue());
  254. }
  255. public function testMarshalArrayFromXmlRpc()
  256. {
  257. $native = array(0,1);
  258. $xml = '<value><array><data><value><int>0</int></value>'
  259. . '<value><int>1</int></value></data></array></value>';
  260. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  261. Zend_XmlRpc_Value::XML_STRING);
  262. $this->assertXmlRpcType('array', $val);
  263. $this->assertEquals('array', $val->getType());
  264. $this->assertSame($native, $val->getValue());
  265. $this->assertType('DomElement', $val->getAsDOM());
  266. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  267. }
  268. public function testEmptyXmlRpcArrayResultsInEmptyArray()
  269. {
  270. $native = array();
  271. $xml = '<value><array><data/></array></value>';
  272. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  273. Zend_XmlRpc_Value::XML_STRING);
  274. $this->assertXmlRpcType('array', $val);
  275. $this->assertEquals('array', $val->getType());
  276. $this->assertSame($native, $val->getValue());
  277. $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  278. $this->assertXmlRpcType('array', $value);
  279. $this->assertEquals('array', $value->getType());
  280. $this->assertSame($native, $value->getValue());
  281. }
  282. public function testArrayMustContainDataElement()
  283. {
  284. $native = array();
  285. $xml = '<value><array/></value>';
  286. $this->setExpectedException('Zend_XmlRpc_Value_Exception',
  287. 'Invalid XML for XML-RPC native array type: ARRAY tag must contain DATA tag');
  288. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  289. Zend_XmlRpc_Value::XML_STRING);
  290. }
  291. /**
  292. * @group ZF-5405
  293. */
  294. public function testMarshalNilInStructWrappedInArray()
  295. {
  296. $expected = array(array('id' => '1', 'name' => 'vertebra, caudal', 'description' => null));
  297. $xml = '<value>'
  298. . '<array><data><value><struct><member><name>id</name><value><string>1</string></value></member>'
  299. . '<member><name>name</name><value><string>vertebra, caudal</string></value></member>'
  300. . '<member><name>description</name><value><nil/></value></member></struct></value></data></array>'
  301. . '</value>';
  302. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  303. $this->assertSame($expected, $val->getValue());
  304. }
  305. // Struct
  306. public function testFactoryAutodetectsStruct()
  307. {
  308. $val = Zend_XmlRpc_Value::getXmlRpcValue(array('foo' => 0));
  309. $this->assertXmlRpcType('struct', $val);
  310. }
  311. public function testFactoryAutodetectsStructFromObject()
  312. {
  313. $val = Zend_XmlRpc_Value::getXmlRpcValue((object)array('foo' => 0));
  314. $this->assertXmlRpcType('struct', $val);
  315. }
  316. public function testMarshalStructFromNative()
  317. {
  318. $native = array('foo' => 0);
  319. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  320. Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
  321. $this->assertXmlRpcType('struct', $val);
  322. $this->assertSame($native, $val->getValue());
  323. }
  324. public function testMarshalStructFromXmlRpc()
  325. {
  326. $native = array('foo' => 0);
  327. $xml = '<value><struct><member><name>foo</name><value><int>0</int>'
  328. . '</value></member></struct></value>';
  329. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  330. Zend_XmlRpc_Value::XML_STRING);
  331. $this->assertXmlRpcType('struct', $val);
  332. $this->assertEquals('struct', $val->getType());
  333. $this->assertSame($native, $val->getValue());
  334. $this->assertType('DomElement', $val->getAsDOM());
  335. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  336. }
  337. public function testMarshallingStructWithMemberWithoutValue()
  338. {
  339. $native = array('foo' => 0, 'bar' => 1);
  340. $xml = '<value><struct>'
  341. . '<member><name>foo</name><value><int>0</int></value></member>'
  342. . '<member><name>foo</name><bar/></member>'
  343. . '<member><name>bar</name><value><int>1</int></value></member>'
  344. . '</struct></value>';
  345. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  346. Zend_XmlRpc_Value::XML_STRING);
  347. $this->assertXmlRpcType('struct', $val);
  348. $this->assertEquals('struct', $val->getType());
  349. $this->assertSame($native, $val->getValue());
  350. $this->assertType('DomElement', $val->getAsDOM());
  351. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  352. }
  353. public function testMarshallingStructWithMemberWithoutName()
  354. {
  355. $native = array('foo' => 0, 'bar' => 1);
  356. $xml = '<value><struct>'
  357. . '<member><name>foo</name><value><int>0</int></value></member>'
  358. . '<member><value><string>foo</string></value></member>'
  359. . '<member><name>bar</name><value><int>1</int></value></member>'
  360. . '</struct></value>';
  361. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  362. Zend_XmlRpc_Value::XML_STRING);
  363. $this->assertXmlRpcType('struct', $val);
  364. $this->assertEquals('struct', $val->getType());
  365. $this->assertSame($native, $val->getValue());
  366. $this->assertType('DomElement', $val->getAsDOM());
  367. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  368. }
  369. /**
  370. * @group ZF-7639
  371. */
  372. public function testMarshalStructFromXmlRpcWithEntities()
  373. {
  374. $native = array('&nbsp;' => 0);
  375. $xml = '<value><struct><member><name>&amp;nbsp;</name><value><int>0</int>'
  376. . '</value></member></struct></value>';
  377. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  378. $this->assertXmlRpcType('struct', $val);
  379. $this->assertSame($native, $val->getValue());
  380. $this->assertSame($this->wrapXml($xml), $val->saveXML());
  381. }
  382. /**
  383. * @group ZF-3947
  384. */
  385. public function testMarshallingStructsWithEmptyValueFromXmlRpcShouldRetainKeys()
  386. {
  387. $native = array('foo' => '');
  388. $xml = '<value><struct><member><name>foo</name>'
  389. . '<value/></member></struct></value>';
  390. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  391. Zend_XmlRpc_Value::XML_STRING);
  392. $this->assertXmlRpcType('struct', $val);
  393. $this->assertEquals('struct', $val->getType());
  394. $this->assertSame($native, $val->getValue());
  395. $this->assertType('DomElement', $val->getAsDOM());
  396. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  397. }
  398. // DateTime
  399. public function testMarshalDateTimeFromNativeString()
  400. {
  401. $native = '1997-07-16T19:20+01:00';
  402. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  403. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  404. $this->assertXmlRpcType('dateTime', $val);
  405. $expected = '1997-07-16T19:20+01:00';
  406. $this->assertSame(strtotime($native), strtotime($val->getValue()));
  407. }
  408. public function testMarshalDateTimeFromNativeStringProducesIsoOutput()
  409. {
  410. $native = '1997-07-16T19:20+01:00';
  411. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  412. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  413. $this->assertXmlRpcType('dateTime', $val);
  414. $expected = date('c', strtotime($native));
  415. $expected = substr($expected, 0, strlen($expected) - 6);
  416. $expected = str_replace('-', '', $expected);
  417. $received = $val->getValue();
  418. $this->assertEquals($expected, $received);
  419. }
  420. public function testMarshalDateTimeFromInvalidString()
  421. {
  422. $this->setExpectedException('Zend_XmlRpc_Value_Exception',
  423. "Cannot convert given value 'foobarbaz' to a timestamp");
  424. Zend_XmlRpc_Value::getXmlRpcValue('foobarbaz', Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  425. }
  426. public function testMarshalDateTimeFromNativeInteger()
  427. {
  428. $native = strtotime('1997-07-16T19:20+01:00');
  429. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  430. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  431. $this->assertXmlRpcType('dateTime', $val);
  432. $this->assertSame($native, strtotime($val->getValue()));
  433. }
  434. public function testMarshalDateTimeFromXmlRpc()
  435. {
  436. $iso8601 = '1997-07-16T19:20+01:00';
  437. $xml = "<value><dateTime.iso8601>$iso8601</dateTime.iso8601></value>";
  438. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  439. Zend_XmlRpc_Value::XML_STRING);
  440. $this->assertXmlRpcType('dateTime', $val);
  441. $this->assertEquals('dateTime.iso8601', $val->getType());
  442. $this->assertSame(strtotime($iso8601), strtotime($val->getValue()));
  443. $this->assertType('DomElement', $val->getAsDOM());
  444. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  445. }
  446. // Base64
  447. public function testMarshalBase64FromString()
  448. {
  449. $native = 'foo';
  450. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  451. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  452. $this->assertXmlRpcType('base64', $val);
  453. $this->assertSame($native, $val->getValue());
  454. }
  455. public function testMarshalBase64FromXmlRpc()
  456. {
  457. $native = 'foo';
  458. $xml = '<value><base64>' .base64_encode($native). '</base64></value>';
  459. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  460. Zend_XmlRpc_Value::XML_STRING);
  461. $this->assertXmlRpcType('base64', $val);
  462. $this->assertEquals('base64', $val->getType());
  463. $this->assertSame($native, $val->getValue());
  464. $this->assertType('DomElement', $val->getAsDOM());
  465. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  466. }
  467. public function testXmlRpcValueBase64GeneratedXmlContainsBase64EncodedText()
  468. {
  469. $native = 'foo';
  470. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  471. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  472. $this->assertXmlRpcType('base64', $val);
  473. $xml = $val->saveXML();
  474. $encoded = base64_encode($native);
  475. $this->assertContains($encoded, $xml);
  476. }
  477. /**
  478. * @group ZF-3862
  479. */
  480. public function testMarshalSerializedObjectAsBase64()
  481. {
  482. $o = new Zend_XmlRpc_SerializableTestClass();
  483. $o->setProperty('foobar');
  484. $serialized = serialize($o);
  485. $val = Zend_XmlRpc_Value::getXmlRpcValue($serialized,
  486. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  487. $this->assertXmlRpcType('base64', $val);
  488. $o2 = unserialize($val->getValue());
  489. $this->assertSame('foobar', $o2->getProperty());
  490. }
  491. // Exceptions
  492. public function testFactoryThrowsWhenInvalidTypeSpecified()
  493. {
  494. try {
  495. Zend_XmlRpc_Value::getXmlRpcValue('', 'bad type here');
  496. $this->fail();
  497. } catch (Exception $e) {
  498. $this->assertRegexp('/given type is not/i', $e->getMessage());
  499. }
  500. }
  501. // Custom Assertions and Helper Methods
  502. public function assertXmlRpcType($type, $object)
  503. {
  504. $type = 'Zend_XmlRpc_Value_' . ucfirst($type);
  505. $this->assertType($type, $object);
  506. }
  507. public function wrapXml($xml)
  508. {
  509. return "<?xml version=\"1.0\"?>\n$xml\n";
  510. }
  511. }
  512. class Zend_XmlRpc_SerializableTestClass
  513. {
  514. protected $_property;
  515. public function setProperty($property)
  516. {
  517. $this->_property = $property;
  518. }
  519. public function getProperty()
  520. {
  521. return $this->_property;
  522. }
  523. }
  524. // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
  525. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ValueTest::main") {
  526. Zend_XmlRpc_ValueTest::main();
  527. }