RequestTest.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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_Amf
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Amf_RequestTest::main');
  24. }
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. require_once 'Zend/Amf/Request.php';
  27. require_once 'Zend/Amf/Parse/TypeLoader.php';
  28. require_once 'Zend/Locale.php';
  29. require_once 'Contact.php';
  30. /**
  31. * Test case for Zend_Amf_Request
  32. *
  33. * @package Zend_Amf
  34. * @subpackage UnitTests
  35. */
  36. class Zend_Amf_RequestTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Zend_Amf_Request object
  40. * @var Zend_Amf_Request
  41. */
  42. protected $_request;
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_RequestTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Setup environment
  55. */
  56. public function setUp()
  57. {
  58. date_default_timezone_set("America/Chicago");
  59. Zend_Locale::setDefault('en');
  60. Zend_Amf_Parse_TypeLoader::resetMap();
  61. $this->_request = new Zend_Amf_Request();
  62. }
  63. /**
  64. * Teardown environment
  65. */
  66. public function tearDown()
  67. {
  68. unset($this->_request);
  69. }
  70. /**
  71. * ActionScript undef to PHP null
  72. *
  73. */
  74. public function testAmf3RemoteObjectUndefParameterDeserializedToNativePhpNull()
  75. {
  76. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/undefAmf3Request.bin');
  77. // send the mock object request to be deserialized
  78. $this->_request->initialize($myRequest);
  79. // Make sure the encoding type is properly set.
  80. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  81. // Make sure that no headers where recievedpbs
  82. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  83. // Make sure that the message body was set after deserialization
  84. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  85. $bodies = $this->_request->getAmfBodies();
  86. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  87. $message = $bodies[0]->getData();
  88. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  89. // Make sure that our endpoint is properly set.
  90. $this->assertEquals('returnUndefined', $message->operation);
  91. $this->assertEquals('RoundTrip', $message->source);
  92. $data = $message->body;
  93. // Make sure that we are dealing with a PHP null
  94. $this->assertTrue(is_null($data[0]));
  95. }
  96. /**
  97. * ActionScript String to PHP String
  98. *
  99. */
  100. public function testAmf3RemoteObjectStringParameterDeserializedToNativePhpString()
  101. {
  102. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/stringAmf3Request.bin');
  103. // send the mock object request to be deserialized
  104. $this->_request->initialize($myRequest);
  105. // Make sure the encoding type is properly set.
  106. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  107. // Make sure that no headers where recieved
  108. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  109. // Make sure that the message body was set after deserialization
  110. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  111. $bodies = $this->_request->getAmfBodies();
  112. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  113. $message = $bodies[0]->getData();
  114. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  115. // Make sure that our endpoint is properly set.
  116. $this->assertEquals('returnString', $message->operation);
  117. $this->assertEquals('RoundTrip', $message->source);
  118. $data = $message->body;
  119. // Make sure that we are dealing with a PHP string
  120. $this->assertTrue(is_string($data[0]));
  121. // Make sure that the string was deserialized properly and check its value
  122. $this->assertEquals('abcdefghijklmpqrstuvwxyz', $data[0]);
  123. }
  124. /**
  125. * ActionScript Array to Php Array
  126. *
  127. */
  128. public function testAmf3RemoteObjectArrayParameterDeserializedToNativePhpArray()
  129. {
  130. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/arrayAmf3Request.bin');
  131. // send the mock object request to be deserialized
  132. $this->_request->initialize($myRequest);
  133. // Make sure the encoding type is properly set.
  134. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  135. // Make sure that no headers where recieved
  136. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  137. // Make sure that the message body was set after deserialization
  138. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  139. $bodies = $this->_request->getAmfBodies();
  140. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  141. $message = $bodies[0]->getData();
  142. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  143. // Make sure that our endpoint is properly set.
  144. $this->assertEquals('returnArray', $message->operation);
  145. $this->assertEquals('RoundTrip', $message->source);
  146. $data = $message->body;
  147. // Make sure that we are dealing with a PHP array
  148. $this->assertTrue(is_array($data[0]));
  149. // Make sure that the array was deserialized properly and check its value
  150. $this->assertEquals('a', $data[0][0]);
  151. $this->assertEquals('g', $data[0][6]);
  152. }
  153. /**
  154. * ActionScript Numnber to PHP float
  155. *
  156. */
  157. public function testAmf3NumberParameterDeserializedToNativePhpFloat()
  158. {
  159. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/numberAmf3Request.bin');
  160. // send the mock object request to be deserialized
  161. $this->_request->initialize($myRequest);
  162. // Make sure the encoding type is properly set.
  163. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  164. // Make sure that no headers where recieved
  165. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  166. // Make sure that the message body was set after deserialization
  167. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  168. $bodies = $this->_request->getAmfBodies();
  169. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  170. $message = $bodies[0]->getData();
  171. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  172. // Make sure that our endpoint is properly set.
  173. $this->assertEquals('returnNumber', $message->operation);
  174. $this->assertEquals('RoundTrip', $message->source);
  175. $data = $message->body;
  176. // Make sure that we are dealing with a PHP float
  177. $this->assertTrue(is_float($data[0]));
  178. // Make sure that the float was deserialized properly and check its value
  179. $this->assertEquals(31.57, $data[0]);
  180. }
  181. /**
  182. * ActionScript Date to Php DateTime
  183. *
  184. */
  185. public function testAmf3DateParameterDeserializedToNativeDateTime()
  186. {
  187. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/dateAmf3Request.bin');
  188. // send the mock object request to be deserialized
  189. $this->_request->initialize($myRequest);
  190. // Make sure the encoding type is properly set.
  191. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  192. // Make sure that no headers where recieved
  193. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  194. // Make sure that the message body was set after deserialization
  195. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  196. $bodies = $this->_request->getAmfBodies();
  197. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  198. $message = $bodies[0]->getData();
  199. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  200. // Make sure that our endpoint is properly set.
  201. $this->assertEquals('returnDate', $message->operation);
  202. $this->assertEquals('RoundTrip', $message->source);
  203. $data = $message->body;
  204. // Make sure that the array was deserialized properly and check its value
  205. $this->assertEquals(1978, $data[0]->toString('Y'));
  206. }
  207. /**
  208. * Try and read in the largest Amf Integer to PHP int
  209. *
  210. */
  211. public function testAmf3LargeIntParameterDeserializedToNativePhpInt()
  212. {
  213. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/largeIntAmf3Request.bin');
  214. // send the mock object request to be deserialized
  215. $this->_request->initialize($myRequest);
  216. // Make sure the encoding type is properly set.
  217. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  218. // Make sure that no headers where recieved
  219. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  220. // Make sure that the message body was set after deserialization
  221. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  222. $bodies = $this->_request->getAmfBodies();
  223. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  224. $message = $bodies[0]->getData();
  225. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  226. // Make sure that our endpoint is properly set.
  227. $this->assertEquals('returnInt', $message->operation);
  228. $this->assertEquals('RoundTrip', $message->source);
  229. $data = $message->body;
  230. // Make sure that we are dealing with a PHP array
  231. $this->assertTrue(is_int($data[0]));
  232. // Make sure that the array was deserialized properly and check its value
  233. $this->assertEquals(268435455, $data[0]);
  234. }
  235. /**
  236. * Read boolean true and convert it to php boolean true
  237. *
  238. */
  239. public function testAmf3BoolTrueParameterDeserializedToNativePhpBool()
  240. {
  241. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/boolTrueAmf3Request.bin');
  242. // send the mock object request to be deserialized
  243. $this->_request->initialize($myRequest);
  244. // Make sure the encoding type is properly set.
  245. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  246. // Make sure that the message body was set after deserialization
  247. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  248. $bodies = $this->_request->getAmfBodies();
  249. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  250. $message = $bodies[0]->getData();
  251. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  252. // Make sure that our endpoint is properly set.
  253. $this->assertEquals('returnBool', $message->operation);
  254. $this->assertEquals('RoundTrip', $message->source);
  255. $data = $message->body;
  256. // Make sure that we are dealing with a PHP array
  257. $this->assertTrue(is_bool($data[0]));
  258. // Make sure that the Bool was deserialized properly and check its value
  259. $this->assertEquals(true, $data[0]);
  260. }
  261. /**
  262. * Convert boolean false to php boolean false.
  263. *
  264. */
  265. public function testAmf3BoolFalseParameterDeserializedToNativePhpBool()
  266. {
  267. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/boolFalseAmf3Request.bin');
  268. // send the mock object request to be deserialized
  269. $this->_request->initialize($myRequest);
  270. // Make sure the encoding type is properly set.
  271. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  272. // Make sure that the message body was set after deserialization
  273. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  274. $bodies = $this->_request->getAmfBodies();
  275. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  276. $message = $bodies[0]->getData();
  277. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  278. // Make sure that our endpoint is properly set.
  279. $this->assertEquals('returnBool', $message->operation);
  280. $this->assertEquals('RoundTrip', $message->source);
  281. $data = $message->body;
  282. // Make sure that we are dealing with a PHP array
  283. $this->assertTrue(is_bool($data[0]));
  284. // Make sure that the Bool was deserialized properly and check its value
  285. $this->assertEquals(false, $data[0]);
  286. }
  287. public function testAmf3XmlParameterDeserializedToNativePhpSimpleXml()
  288. {
  289. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/xmlAmf3Request.bin');
  290. // send the mock object request to be deserialized
  291. $this->_request->initialize($myRequest);
  292. // Make sure the encoding type is properly set.
  293. $this->assertEquals(0x03, $this->_request->getObjectEncoding());
  294. // Make sure that no headers where recieved
  295. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  296. // Make sure that the message body was set after deserialization
  297. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  298. $bodies = $this->_request->getAmfBodies();
  299. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  300. $message = $bodies[0]->getData();
  301. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_RemotingMessage);
  302. // Make sure that our endpoint is properly set.
  303. $this->assertEquals('returnXml', $message->operation);
  304. $this->assertEquals('RoundTrip', $message->source);
  305. $data = $message->body;
  306. // Make sure that we are dealing with a PHP simpleXml element
  307. $this->assertTrue($data[0] instanceof SimpleXMLElement);
  308. // Make sure that the xml was deserialized properly and check its value
  309. $this->assertEquals('hello', (string) $data[0]->p);
  310. }
  311. public function testAmf3ByteArrayDeserializedToNativePhpString()
  312. {
  313. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/byteArrayAmf3Request.bin');
  314. // send the mock object request to be deserialized
  315. $this->_request->initialize($myRequest);
  316. // Make sure that no headers where recieved
  317. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  318. // Make sure that the message body was set after deserialization
  319. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  320. $requestBody = $this->_request->getAmfBodies();
  321. $this->assertTrue($requestBody[0] instanceof Zend_Amf_Value_MessageBody);
  322. $data = $requestBody[0]->getData();
  323. // Make sure that we are dealing with a PHP string
  324. $this->assertTrue(is_string($data[0]));
  325. // Make sure that the string was deserialized properly and check its value
  326. $byteArray = file_get_contents(dirname(__FILE__) .'/Request/bytearray.bin');
  327. $this->assertEquals($byteArray, $data[0]);
  328. }
  329. /**
  330. * Actionscript String to PHP String
  331. *
  332. */
  333. public function testAmf0StringParameterDeserializedToNativePhpString()
  334. {
  335. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/stringAmf0Request.bin');
  336. // send the mock object request to be deserialized
  337. $this->_request->initialize($myRequest);
  338. // Make sure that no headers where recieved
  339. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  340. // Make sure that the message body was set after deserialization
  341. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  342. $requestBody = $this->_request->getAmfBodies();
  343. $this->assertTrue($requestBody[0] instanceof Zend_Amf_Value_MessageBody);
  344. $this->assertEquals('RoundTrip.returnString', $requestBody[0]->getTargetURI());
  345. $data = $requestBody[0]->getData();
  346. // Make sure that we are dealing with a PHP string
  347. $this->assertTrue(is_string($data[0]));
  348. // Make sure that the string was deserialized properly and check its value
  349. $this->assertEquals('abcdefghijklmpqrstuvwxyz', $data[0]);
  350. }
  351. /**
  352. * ActionScript Object to PHP Object for Amf0
  353. *
  354. */
  355. public function testAmf0ObjectParameterDeserializedToNativePhpObject()
  356. {
  357. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/objectAmf0Request.bin');
  358. // send the mock object request to be deserialized
  359. $this->_request->initialize($myRequest);
  360. // Make sure that no headers where recieved
  361. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  362. // Make sure that the message body was set after deserialization
  363. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  364. $bodies = $this->_request->getAmfBodies();
  365. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  366. $data = $bodies[0]->getData();
  367. // Make sure that we are dealing with a PHP string
  368. // Make sure that the string was deserialized properly and check its value
  369. $this->assertEquals('foo', $data[0]->a);
  370. $this->assertEquals('bar', $data[0]->b);
  371. }
  372. /**
  373. * Test to make sure that a generic object as the first paramater does not crash
  374. * @group ZF-5346
  375. */
  376. public function testAmf0ObjectFirstParameter()
  377. {
  378. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/objectFirstParamRequest.bin');
  379. // send the mock object request to be deserialized
  380. $this->_request->initialize($myRequest);
  381. // Make sure that no headers where recieved
  382. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  383. // Make sure that the message body was set after deserialization
  384. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  385. $bodies = $this->_request->getAmfBodies();
  386. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  387. $data = $bodies[0]->getData();
  388. // Make sure that we are dealing with a PHP string
  389. // Make sure that the string was deserialized properly and check its value
  390. $this->assertEquals('foo', $data[0]->a);
  391. $this->assertEquals('bar', $data[0]->b);
  392. $this->assertEquals(1234, $data[1]);
  393. }
  394. /**
  395. * ActionScript Mixed Array to PHP Object for Amf0
  396. *
  397. */
  398. public function testAmf0MixedArrayParameterDeserializedToNativePhpObject()
  399. {
  400. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/mixedArrayAmf0Request.bin');
  401. // send the mock object request to be deserialized
  402. $this->_request->initialize($myRequest);
  403. // Make sure that no headers where recieved
  404. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  405. // Make sure that the message body was set after deserialization
  406. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  407. $bodies = $this->_request->getAmfBodies();
  408. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  409. $data = $bodies[0]->getData();
  410. // Make sure that the string was deserialized properly and check its value
  411. $this->assertTrue(array_key_exists(1, $data[0]));
  412. $this->assertEquals('two', $data[0]->two);
  413. }
  414. /**
  415. * ActionScript Numnber to PHP float
  416. *
  417. */
  418. public function testAmf0NumberParameterDeserializedToNativePhpFloat()
  419. {
  420. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/numberAmf0Request.bin');
  421. // send the mock object request to be deserialized
  422. $this->_request->initialize($myRequest);
  423. // Make sure that no headers where recieved
  424. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  425. // Make sure that the message body was set after deserialization
  426. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  427. $bodies = $this->_request->getAmfBodies();
  428. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  429. $data = $bodies[0]->getData();
  430. // Make sure that the string was deserialized properly and check its value
  431. $this->assertTrue(is_float($data[0]));
  432. $this->assertEquals(31.57, $data[0]);
  433. }
  434. /**
  435. * ActionScript Date to PHP DateTime
  436. *
  437. */
  438. public function testAmf0DateParameterDeserializedToNativePhpDateTime()
  439. {
  440. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/dateAmf0Request.bin');
  441. // send the mock object request to be deserialized
  442. $this->_request->initialize($myRequest);
  443. // Make sure that no headers where recieved
  444. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  445. // Make sure that the message body was set after deserialization
  446. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  447. $bodies = $this->_request->getAmfBodies();
  448. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  449. $data = $bodies[0]->getData();
  450. // Make sure that the string was deserialized properly and check its value
  451. $this->assertEquals(10, $data[0]->toString('M'));
  452. $this->assertEquals(1978, $data[0]->toString('Y'));
  453. }
  454. /**
  455. * ActionScript Integer to PHP int
  456. *
  457. */
  458. public function testAmf0IntParameterDeserializedToNativePhpint()
  459. {
  460. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/intAmf0Request.bin');
  461. // send the mock object request to be deserialized
  462. $this->_request->initialize($myRequest);
  463. // Make sure that no headers where recieved
  464. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  465. // Make sure that the message body was set after deserialization
  466. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  467. $bodies = $this->_request->getAmfBodies();
  468. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  469. $data = $bodies[0]->getData();
  470. // Make sure that the string was deserialized properly and check its value
  471. $this->assertEquals(268435456, $data[0]);
  472. }
  473. /**
  474. * Convert an Amf0 boolean true to php boolean
  475. *
  476. */
  477. public function testAmf0BoolTrueParameterDeserializedToNativePhpBool()
  478. {
  479. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/boolTrueAmf0Request.bin');
  480. // send the mock object request to be deserialized
  481. $this->_request->initialize($myRequest);
  482. // Make sure that no headers where recieved
  483. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  484. // Make sure that the message body was set after deserialization
  485. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  486. $bodies = $this->_request->getAmfBodies();
  487. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  488. $data = $bodies[0]->getData();
  489. // Make sure that the string was deserialized properly and check its value
  490. $this->assertTrue(is_bool($data[0]));
  491. $this->assertEquals(true, $data[0]);
  492. }
  493. /**
  494. * Convert an Amf0 boolean false to php boolean
  495. *
  496. */
  497. public function testAmf0BoolFalseParameterDeserializedToNativePhpBool()
  498. {
  499. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/boolFalseAmf0Request.bin');
  500. // send the mock object request to be deserialized
  501. $this->_request->initialize($myRequest);
  502. // Make sure that no headers where recieved
  503. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  504. // Make sure that the message body was set after deserialization
  505. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  506. $bodies = $this->_request->getAmfBodies();
  507. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  508. $data = $bodies[0]->getData();
  509. // Make sure that the string was deserialized properly and check its value
  510. $this->assertTrue(is_bool($data[0]));
  511. $this->assertEquals(false, $data[0]);
  512. }
  513. public function testAmf0NullDeserializedToNativePhpNull()
  514. {
  515. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/nullAmf0Request.bin');
  516. // send the mock object request to be deserialized
  517. $this->_request->initialize($myRequest);
  518. // Make sure that no headers where recieved
  519. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  520. // Make sure that the message body was set after deserialization
  521. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  522. $bodies = $this->_request->getAmfBodies();
  523. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  524. $data = $bodies[0]->getData();
  525. // Make sure that the string was deserialized properly and check its value
  526. $this->assertTrue(is_null($data[0]));
  527. }
  528. public function testAmf0UndefinedDeserializedToNativePhpNull()
  529. {
  530. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/undefinedAmf0Request.bin');
  531. // send the mock object request to be deserialized
  532. $this->_request->initialize($myRequest);
  533. // Make sure that no headers where recieved
  534. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  535. // Make sure that the message body was set after deserialization
  536. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  537. $bodies = $this->_request->getAmfBodies();
  538. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  539. $data = $bodies[0]->getData();
  540. // Make sure that the string was deserialized properly and check its value
  541. $this->assertTrue(is_null($data[0]));
  542. }
  543. public function testAmf0XmlParameterDeserializedToNativePhpSimpleXml()
  544. {
  545. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/xmlAmf0Request.bin');
  546. // send the mock object request to be deserialized
  547. $this->_request->initialize($myRequest);
  548. // Make sure that no headers where recieved
  549. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  550. // Make sure that the message body was set after deserialization
  551. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  552. $bodies = $this->_request->getAmfBodies();
  553. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  554. $data = $bodies[0]->getData();
  555. // Make sure that we are dealing with a PHP simpleXml element
  556. $this->assertTrue($data[0] instanceof SimpleXMLElement);
  557. // Make sure that the xml was deserialized properly and check its value
  558. $this->assertEquals('hello', (string) $data[0]->p);
  559. }
  560. public function testAmf0ReferenceDeserialized()
  561. {
  562. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/referenceAmf0Request.bin');
  563. // send the mock object request to be deserialized
  564. $this->_request->initialize($myRequest);
  565. // Make sure that no headers where recieved
  566. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  567. // Make sure that the message body was set after deserialization
  568. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  569. $bodies = $this->_request->getAmfBodies();
  570. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  571. $data = $bodies[0]->getData();
  572. // Make sure that we are dealing with a PHP a number
  573. // Make sure that the xml was deserialized properly and check its value
  574. $this->assertEquals('foo', (string) $data[0]->a);
  575. }
  576. public function testAmf0TypedObjecDeserializedToNativePHPObject()
  577. {
  578. Zend_Amf_Parse_TypeLoader::setMapping("ContactVO","Contact");
  579. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/typedObjectAmf0Request.bin');
  580. // send the mock object request to be deserialized
  581. $this->_request->initialize($myRequest);
  582. // Make sure that no headers where recieved
  583. $this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
  584. // Make sure that the message body was set after deserialization
  585. $this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
  586. $bodies = $this->_request->getAmfBodies();
  587. $this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
  588. $data = $bodies[0]->getData();
  589. // Make sure that we are dealing with a PHP simpleXml element
  590. $this->assertTrue($data[0] instanceof Contact);
  591. // Make sure that the xml was deserialized properly and check its value
  592. $this->assertEquals('arnold', (string) $data[0]->lastname);
  593. }
  594. public function testAmf0TypedObjecDeserializedToNativePHPObjectUnknownType()
  595. {
  596. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/bogusTypedObjectAmf0Request.bin');
  597. // send the mock object request to be deserialized
  598. $this->_request->initialize($myRequest);
  599. $requestBodies = $this->_request->getAmfBodies();
  600. $messageBody = reset($requestBodies);
  601. $data = $messageBody->getData();
  602. $dataObject = reset($data);
  603. $this->assertEquals('stdClass', get_class($dataObject));
  604. }
  605. /**
  606. * Test Amf0 credentials sent to the server
  607. *
  608. */
  609. public function testAmf0CredentialsInHeader()
  610. {
  611. $myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/credentialsheaderAmf0.bin');
  612. // send the mock object request to be deserialized
  613. $this->_request->initialize($myRequest);
  614. // Make sure that no headers where recieved
  615. $this->assertEquals(1 , sizeof($this->_request->getAmfHeaders()));
  616. $requestHeaders = $this->_request->getAmfHeaders();
  617. $this->assertTrue($requestHeaders[0] instanceof Zend_Amf_Value_MessageHeader);
  618. $this->assertEquals('Credentials', $requestHeaders[0]->name);
  619. $this->assertFalse($requestHeaders[0]->mustRead);
  620. $data = $requestHeaders[0]->data;
  621. // Check the resulting header
  622. $this->assertEquals('admin', $data->userid);
  623. $this->assertEquals('pw123', $data->password);
  624. }
  625. }
  626. if (PHPUnit_MAIN_METHOD == 'Zend_Amf_RequestTest::main') {
  627. Zend_Amf_RequestTest::main();
  628. }