ValueTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. vaR_dump($val);
  191. $this->assertSame($native, $val->getValue());
  192. }
  193. public function testMarshalStringFromXmlRpc()
  194. {
  195. $native = 'foo';
  196. $xml = "<value><string>$native</string></value>";
  197. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  198. Zend_XmlRpc_Value::XML_STRING);
  199. $this->assertXmlRpcType('string', $val);
  200. $this->assertEquals('string', $val->getType());
  201. $this->assertSame($native, $val->getValue());
  202. $this->assertType('DomElement', $val->getAsDOM());
  203. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  204. }
  205. public function testMarshalStringFromDefault()
  206. {
  207. $native = 'foo';
  208. $xml = "<string>$native</string>";
  209. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  210. Zend_XmlRpc_Value::XML_STRING);
  211. $this->assertXmlRpcType('string', $val);
  212. $this->assertEquals('string', $val->getType());
  213. $this->assertSame($native, $val->getValue());
  214. $this->assertType('DomElement', $val->getAsDOM());
  215. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  216. }
  217. //Nil
  218. public function testFactoryAutodetectsNil()
  219. {
  220. $val = Zend_XmlRpc_Value::getXmlRpcValue(NULL);
  221. $this->assertXmlRpcType('nil', $val);
  222. }
  223. public function testMarshalNilFromNative()
  224. {
  225. $native = NULL;
  226. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  227. Zend_XmlRpc_Value::XMLRPC_TYPE_NIL);
  228. $this->assertXmlRpcType('nil', $val);
  229. $this->assertSame($native, $val->getValue());
  230. }
  231. public function testMarshalNilFromXmlRpc()
  232. {
  233. $xml = '<value><nil/></value>';
  234. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  235. Zend_XmlRpc_Value::XML_STRING);
  236. $this->assertXmlRpcType('nil', $val);
  237. $this->assertEquals('nil', $val->getType());
  238. $this->assertSame(NULL, $val->getValue());
  239. $this->assertType('DomElement', $val->getAsDOM());
  240. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  241. }
  242. // Array
  243. public function testFactoryAutodetectsArray()
  244. {
  245. $val = Zend_XmlRpc_Value::getXmlRpcValue(array(0, 'foo'));
  246. $this->assertXmlRpcType('array', $val);
  247. }
  248. public function testMarshalArrayFromNative()
  249. {
  250. $native = array(0,1);
  251. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  252. Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY);
  253. $this->assertXmlRpcType('array', $val);
  254. $this->assertSame($native, $val->getValue());
  255. }
  256. public function testMarshalArrayFromXmlRpc()
  257. {
  258. $native = array(0,1);
  259. $xml = '<value><array><data><value><int>0</int></value>'
  260. . '<value><int>1</int></value></data></array></value>';
  261. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  262. Zend_XmlRpc_Value::XML_STRING);
  263. $this->assertXmlRpcType('array', $val);
  264. $this->assertEquals('array', $val->getType());
  265. $this->assertSame($native, $val->getValue());
  266. $this->assertType('DomElement', $val->getAsDOM());
  267. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  268. }
  269. public function testEmptyXmlRpcArrayResultsInEmptyArray()
  270. {
  271. $native = array();
  272. $xml = '<value><array><data/></array></value>';
  273. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  274. Zend_XmlRpc_Value::XML_STRING);
  275. $this->assertXmlRpcType('array', $val);
  276. $this->assertEquals('array', $val->getType());
  277. $this->assertSame($native, $val->getValue());
  278. $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  279. $this->assertXmlRpcType('array', $value);
  280. $this->assertEquals('array', $value->getType());
  281. $this->assertSame($native, $value->getValue());
  282. }
  283. public function testArrayMustContainDataElement()
  284. {
  285. $native = array();
  286. $xml = '<value><array/></value>';
  287. $this->setExpectedException('Zend_XmlRpc_Value_Exception',
  288. 'Invalid XML for XML-RPC native array type: ARRAY tag must contain DATA tag');
  289. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  290. Zend_XmlRpc_Value::XML_STRING);
  291. }
  292. /**
  293. * @group ZF-5405
  294. */
  295. public function testMarshalNilInStructWrappedInArray()
  296. {
  297. $expected = array(array('id' => '1', 'name' => 'vertebra, caudal', 'description' => null));
  298. $xml = '<value>'
  299. . '<array><data><value><struct><member><name>id</name><value><string>1</string></value></member>'
  300. . '<member><name>name</name><value><string>vertebra, caudal</string></value></member>'
  301. . '<member><name>description</name><value><nil/></value></member></struct></value></data></array>'
  302. . '</value>';
  303. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  304. $this->assertSame($expected, $val->getValue());
  305. }
  306. // Struct
  307. public function testFactoryAutodetectsStruct()
  308. {
  309. $val = Zend_XmlRpc_Value::getXmlRpcValue(array('foo' => 0));
  310. $this->assertXmlRpcType('struct', $val);
  311. }
  312. public function testFactoryAutodetectsStructFromObject()
  313. {
  314. $val = Zend_XmlRpc_Value::getXmlRpcValue((object)array('foo' => 0));
  315. $this->assertXmlRpcType('struct', $val);
  316. }
  317. public function testMarshalStructFromNative()
  318. {
  319. $native = array('foo' => 0);
  320. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  321. Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
  322. $this->assertXmlRpcType('struct', $val);
  323. $this->assertSame($native, $val->getValue());
  324. }
  325. public function testMarshalStructFromXmlRpc()
  326. {
  327. $native = array('foo' => 0);
  328. $xml = '<value><struct><member><name>foo</name><value><int>0</int>'
  329. . '</value></member></struct></value>';
  330. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  331. Zend_XmlRpc_Value::XML_STRING);
  332. $this->assertXmlRpcType('struct', $val);
  333. $this->assertEquals('struct', $val->getType());
  334. $this->assertSame($native, $val->getValue());
  335. $this->assertType('DomElement', $val->getAsDOM());
  336. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  337. }
  338. public function testMarshallingStructWithMemberWithoutValue()
  339. {
  340. $native = array('foo' => 0, 'bar' => 1);
  341. $xml = '<value><struct>'
  342. . '<member><name>foo</name><value><int>0</int></value></member>'
  343. . '<member><name>foo</name><bar/></member>'
  344. . '<member><name>bar</name><value><int>1</int></value></member>'
  345. . '</struct></value>';
  346. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  347. Zend_XmlRpc_Value::XML_STRING);
  348. $this->assertXmlRpcType('struct', $val);
  349. $this->assertEquals('struct', $val->getType());
  350. $this->assertSame($native, $val->getValue());
  351. $this->assertType('DomElement', $val->getAsDOM());
  352. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  353. }
  354. public function testMarshallingStructWithMemberWithoutName()
  355. {
  356. $native = array('foo' => 0, 'bar' => 1);
  357. $xml = '<value><struct>'
  358. . '<member><name>foo</name><value><int>0</int></value></member>'
  359. . '<member><value><string>foo</string></value></member>'
  360. . '<member><name>bar</name><value><int>1</int></value></member>'
  361. . '</struct></value>';
  362. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  363. Zend_XmlRpc_Value::XML_STRING);
  364. $this->assertXmlRpcType('struct', $val);
  365. $this->assertEquals('struct', $val->getType());
  366. $this->assertSame($native, $val->getValue());
  367. $this->assertType('DomElement', $val->getAsDOM());
  368. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  369. }
  370. /**
  371. * @group ZF-7639
  372. */
  373. public function testMarshalStructFromXmlRpcWithEntities()
  374. {
  375. $native = array('&nbsp;' => 0);
  376. $xml = '<value><struct><member><name>&amp;nbsp;</name><value><int>0</int>'
  377. . '</value></member></struct></value>';
  378. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
  379. $this->assertXmlRpcType('struct', $val);
  380. $this->assertSame($native, $val->getValue());
  381. $this->assertSame($this->wrapXml($xml), $val->saveXML());
  382. }
  383. /**
  384. * @group ZF-3947
  385. */
  386. public function testMarshallingStructsWithEmptyValueFromXmlRpcShouldRetainKeys()
  387. {
  388. $native = array('foo' => '');
  389. $xml = '<value><struct><member><name>foo</name>'
  390. . '<value/></member></struct></value>';
  391. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  392. Zend_XmlRpc_Value::XML_STRING);
  393. $this->assertXmlRpcType('struct', $val);
  394. $this->assertEquals('struct', $val->getType());
  395. $this->assertSame($native, $val->getValue());
  396. $this->assertType('DomElement', $val->getAsDOM());
  397. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  398. }
  399. // DateTime
  400. public function testMarshalDateTimeFromNativeString()
  401. {
  402. $native = '1997-07-16T19:20+01:00';
  403. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  404. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  405. $this->assertXmlRpcType('dateTime', $val);
  406. $expected = '1997-07-16T19:20+01:00';
  407. $this->assertSame(strtotime($native), strtotime($val->getValue()));
  408. }
  409. public function testMarshalDateTimeFromNativeStringProducesIsoOutput()
  410. {
  411. $native = '1997-07-16T19:20+01:00';
  412. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  413. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  414. $this->assertXmlRpcType('dateTime', $val);
  415. $expected = date('c', strtotime($native));
  416. $expected = substr($expected, 0, strlen($expected) - 6);
  417. $expected = str_replace('-', '', $expected);
  418. $received = $val->getValue();
  419. $this->assertEquals($expected, $received);
  420. }
  421. public function testMarshalDateTimeFromInvalidString()
  422. {
  423. $this->setExpectedException('Zend_XmlRpc_Value_Exception',
  424. "Cannot convert given value 'foobarbaz' to a timestamp");
  425. Zend_XmlRpc_Value::getXmlRpcValue('foobarbaz', Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  426. }
  427. public function testMarshalDateTimeFromNativeInteger()
  428. {
  429. $native = strtotime('1997-07-16T19:20+01:00');
  430. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  431. Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
  432. $this->assertXmlRpcType('dateTime', $val);
  433. $this->assertSame($native, strtotime($val->getValue()));
  434. }
  435. public function testMarshalDateTimeFromXmlRpc()
  436. {
  437. $iso8601 = '1997-07-16T19:20+01:00';
  438. $xml = "<value><dateTime.iso8601>$iso8601</dateTime.iso8601></value>";
  439. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  440. Zend_XmlRpc_Value::XML_STRING);
  441. $this->assertXmlRpcType('dateTime', $val);
  442. $this->assertEquals('dateTime.iso8601', $val->getType());
  443. $this->assertSame(strtotime($iso8601), strtotime($val->getValue()));
  444. $this->assertType('DomElement', $val->getAsDOM());
  445. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  446. }
  447. // Base64
  448. public function testMarshalBase64FromString()
  449. {
  450. $native = 'foo';
  451. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  452. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  453. $this->assertXmlRpcType('base64', $val);
  454. $this->assertSame($native, $val->getValue());
  455. }
  456. public function testMarshalBase64FromXmlRpc()
  457. {
  458. $native = 'foo';
  459. $xml = '<value><base64>' .base64_encode($native). '</base64></value>';
  460. $val = Zend_XmlRpc_Value::getXmlRpcValue($xml,
  461. Zend_XmlRpc_Value::XML_STRING);
  462. $this->assertXmlRpcType('base64', $val);
  463. $this->assertEquals('base64', $val->getType());
  464. $this->assertSame($native, $val->getValue());
  465. $this->assertType('DomElement', $val->getAsDOM());
  466. $this->assertEquals($this->wrapXml($xml), $val->saveXML());
  467. }
  468. public function testXmlRpcValueBase64GeneratedXmlContainsBase64EncodedText()
  469. {
  470. $native = 'foo';
  471. $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
  472. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  473. $this->assertXmlRpcType('base64', $val);
  474. $xml = $val->saveXML();
  475. $encoded = base64_encode($native);
  476. $this->assertContains($encoded, $xml);
  477. }
  478. /**
  479. * @group ZF-3862
  480. */
  481. public function testMarshalSerializedObjectAsBase64()
  482. {
  483. $o = new Zend_XmlRpc_SerializableTestClass();
  484. $o->setProperty('foobar');
  485. $serialized = serialize($o);
  486. $val = Zend_XmlRpc_Value::getXmlRpcValue($serialized,
  487. Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
  488. $this->assertXmlRpcType('base64', $val);
  489. $o2 = unserialize($val->getValue());
  490. $this->assertSame('foobar', $o2->getProperty());
  491. }
  492. // Exceptions
  493. public function testFactoryThrowsWhenInvalidTypeSpecified()
  494. {
  495. try {
  496. Zend_XmlRpc_Value::getXmlRpcValue('', 'bad type here');
  497. $this->fail();
  498. } catch (Exception $e) {
  499. $this->assertRegexp('/given type is not/i', $e->getMessage());
  500. }
  501. }
  502. // Custom Assertions and Helper Methods
  503. public function assertXmlRpcType($type, $object)
  504. {
  505. $type = 'Zend_XmlRpc_Value_' . ucfirst($type);
  506. $this->assertType($type, $object);
  507. }
  508. public function wrapXml($xml)
  509. {
  510. return "<?xml version=\"1.0\"?>\n$xml\n";
  511. }
  512. }
  513. class Zend_XmlRpc_SerializableTestClass
  514. {
  515. protected $_property;
  516. public function setProperty($property)
  517. {
  518. $this->_property = $property;
  519. }
  520. public function getProperty()
  521. {
  522. return $this->_property;
  523. }
  524. }
  525. // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
  526. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ValueTest::main") {
  527. Zend_XmlRpc_ValueTest::main();
  528. }