ServerTest.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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-2011 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_Amf_ServerTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Amf_ServerTest::main");
  25. }
  26. require_once 'Zend/Amf/Server.php';
  27. require_once 'Zend/Amf/Request.php';
  28. require_once 'Zend/Amf/Parse/TypeLoader.php';
  29. require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
  30. require_once 'Zend/Amf/Adobe/Auth.php';
  31. require_once 'Zend/Acl.php';
  32. require_once 'ServiceA.php';
  33. require_once 'ServiceB.php';
  34. require_once 'Zend/Session.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Amf
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Amf
  42. */
  43. class Zend_Amf_ServerTest extends PHPUnit_Framework_TestCase
  44. {
  45. protected $_server;
  46. public static function main()
  47. {
  48. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_ServerTest");
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. public function setUp()
  52. {
  53. $this->_server = new Zend_Amf_Server();
  54. $this->_server->setProduction(false);
  55. Zend_Amf_Parse_TypeLoader::resetMap();
  56. }
  57. public function tearDown()
  58. {
  59. unset($this->_server);
  60. //Zend_Amf_Parse_TypeLoader::resetMap();
  61. }
  62. /**
  63. * Call as method call
  64. *
  65. * Returns: void
  66. */
  67. public function test__construct()
  68. {
  69. $this->assertTrue($this->_server instanceof Zend_Amf_Server);
  70. }
  71. public function testIsProductionByDefault()
  72. {
  73. $this->_server = new Zend_Amf_Server;
  74. $this->assertTrue($this->_server->isProduction());
  75. }
  76. public function testProductionFlagShouldBeMutable()
  77. {
  78. $this->testIsProductionByDefault();
  79. $this->_server->setProduction(false);
  80. $this->assertFalse($this->_server->isProduction());
  81. $this->_server->setProduction(true);
  82. $this->assertTrue($this->_server->isProduction());
  83. }
  84. public function testSetClass()
  85. {
  86. $this->_server->setClass('Zend_Amf_testclass', 'test');
  87. $methods = $this->_server->listMethods();
  88. $this->assertTrue(in_array('test.test1', $methods));
  89. $this->assertTrue(in_array('test.test2', $methods));
  90. $this->assertFalse(in_array('test._test3', $methods));
  91. $this->assertFalse(in_array('test.__construct', $methods));
  92. }
  93. /**
  94. * @expectedException Zend_Amf_Server_Exception
  95. */
  96. public function testSetClassShouldRaiseExceptionOnInvalidClassname()
  97. {
  98. $this->_server->setClass('foobar');
  99. }
  100. /**
  101. * @expectedException Zend_Amf_Server_Exception
  102. */
  103. public function testSetClassShouldRaiseExceptionOnInvalidClasstype()
  104. {
  105. $this->_server->setClass(array('foobar'));
  106. }
  107. /**
  108. * @expectedException Zend_Amf_Server_Exception
  109. */
  110. public function testSetClassShouldRaiseExceptionOnDuplicateMethodName()
  111. {
  112. $this->_server->setClass('Zend_Amf_testclass', 'tc');
  113. $this->_server->setClass('Zend_Amf_testclassPrivate', 'tc');
  114. }
  115. /**
  116. * ZF-5393
  117. */
  118. public function testSetClassUsingObject()
  119. {
  120. $testClass = new Zend_Amf_testclass();
  121. $this->_server->setClass($testClass);
  122. $this->assertEquals(8, count($this->_server->getFunctions()));
  123. }
  124. /**
  125. * addFunction() test
  126. *
  127. * Call as method call
  128. *
  129. * Expects:
  130. * - function:
  131. * - namespace: Optional; has default;
  132. *
  133. * Returns: void
  134. */
  135. public function testAddFunction()
  136. {
  137. try {
  138. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'test');
  139. } catch (Exception $e) {
  140. $this->fail('Attachment should have worked');
  141. }
  142. $methods = $this->_server->listMethods();
  143. $this->assertTrue(in_array('test.Zend_Amf_Server_testFunction', $methods), var_export($methods, 1));
  144. try {
  145. $this->_server->addFunction('nosuchfunction');
  146. $this->fail('nosuchfunction() should not exist and should throw an exception');
  147. } catch (Exception $e) {
  148. // do nothing
  149. }
  150. $server = new Zend_Amf_Server();
  151. try {
  152. $server->addFunction(
  153. array(
  154. 'Zend_Amf_Server_testFunction',
  155. 'Zend_Amf_Server_testFunction2',
  156. ),
  157. 'zsr'
  158. );
  159. } catch (Exception $e) {
  160. $this->fail('Error attaching array of functions: ' . $e->getMessage());
  161. }
  162. $methods = $server->listMethods();
  163. $this->assertTrue(in_array('zsr.Zend_Amf_Server_testFunction', $methods));
  164. $this->assertTrue(in_array('zsr.Zend_Amf_Server_testFunction2', $methods));
  165. }
  166. /**
  167. * @expectedException Zend_Amf_Server_Exception
  168. */
  169. public function testAddFunctionShouldRaiseExceptionForInvalidFunctionName()
  170. {
  171. $this->_server->addFunction(true);
  172. }
  173. /**
  174. * @expectedException Zend_Amf_Server_Exception
  175. */
  176. public function testAddFunctionShouldRaiseExceptionOnDuplicateMethodName()
  177. {
  178. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tc');
  179. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tc');
  180. }
  181. /**
  182. * Test sending data to the remote class and make sure we
  183. * recieve the proper response.
  184. *
  185. */
  186. public function testHandleLoadedClassAmf0()
  187. {
  188. // serialize the data to an AMF output stream
  189. $data[] = "12345";
  190. $this->_server->setClass('Zend_Amf_testclass');
  191. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.test1","/1",$data);
  192. $request = new Zend_Amf_Request();
  193. $request->addAmfBody($newBody);
  194. $request->setObjectEncoding(0x00);
  195. $result = $this->_server->handle($request);
  196. $response = $this->_server->getResponse();
  197. $responseBody = $response->getAmfBodies();
  198. // Now check if the return data was properly set.
  199. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  200. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  201. $this->assertEquals("String: 12345", $responseBody[0]->getData(), var_export($responseBody, 1));
  202. }
  203. public function testShouldAllowHandlingFunctionCallsViaAmf0()
  204. {
  205. // serialize the data to an AMF output stream
  206. $data = array('foo', 'bar');
  207. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  208. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_Server_testFunction","/1",$data);
  209. $request = new Zend_Amf_Request();
  210. $request->addAmfBody($newBody);
  211. $request->setObjectEncoding(0x00);
  212. $result = $this->_server->handle($request);
  213. $response = $this->_server->getResponse();
  214. $responseBody = $response->getAmfBodies();
  215. // Now check if the return data was properly set.
  216. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  217. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  218. $this->assertEquals("bar: foo", $responseBody[0]->getData(), var_export($responseBody, 1));
  219. }
  220. /**
  221. * Test to make sure that AMF3 basic requests are handled for loading
  222. * a class.
  223. * This type of call is sent from NetConnection rather than RemoteObject
  224. *
  225. * @group ZF-4680
  226. */
  227. public function testHandleLoadedClassAmf3NetConnection()
  228. {
  229. // serialize the data to an AMF output stream
  230. $data[] = "12345";
  231. $this->_server->setClass('Zend_Amf_testclass');
  232. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.test1","/1",$data);
  233. $request = new Zend_Amf_Request();
  234. $request->addAmfBody($newBody);
  235. $request->setObjectEncoding(0x03);
  236. $result = $this->_server->handle($request);
  237. $response = $this->_server->getResponse();
  238. $responseBody = $response->getAmfBodies();
  239. // Now check if the return data was properly set.
  240. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  241. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  242. $this->assertEquals("String: 12345", $responseBody[0]->getData(), var_export($responseBody, 1));
  243. }
  244. /**
  245. * Test to make sure that AMF3 basic requests are handled for function calls.
  246. * This type of call is sent from net connection rather than RemoteObject
  247. *
  248. * @group ZF-4680
  249. */
  250. public function testShouldAllowHandlingFunctionCallsViaAmf3NetConnection()
  251. {
  252. // serialize the data to an AMF output stream
  253. $data = array('foo', 'bar');
  254. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  255. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_Server_testFunction","/1",$data);
  256. $request = new Zend_Amf_Request();
  257. $request->addAmfBody($newBody);
  258. $request->setObjectEncoding(0x03);
  259. $result = $this->_server->handle($request);
  260. $response = $this->_server->getResponse();
  261. $responseBody = $response->getAmfBodies();
  262. // Now check if the return data was properly set.
  263. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  264. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  265. $this->assertEquals("bar: foo", $responseBody[0]->getData(), var_export($responseBody, 1));
  266. }
  267. /**
  268. * Test sending data to the remote class and make sure we
  269. * recieve the proper response.
  270. *
  271. */
  272. public function testHandleLoadedClassAmf3()
  273. {
  274. // serialize the data to an AMF output stream
  275. $data[] = "12345";
  276. $this->_server->setClass('Zend_Amf_testclass');
  277. // create a mock remoting message
  278. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  279. $message->operation = 'test1';
  280. $message->source = 'Zend_Amf_testclass';
  281. $message->body = $data;
  282. // create a mock message body to place th remoting message inside
  283. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  284. $request = new Zend_Amf_Request();
  285. // at the requested service to a request
  286. $request->addAmfBody($newBody);
  287. $request->setObjectEncoding(0x03);
  288. // let the server handle mock request
  289. $result = $this->_server->handle($request);
  290. $response = $this->_server->getResponse();
  291. $responseBody = $response->getAmfBodies();
  292. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  293. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  294. // Now check if the return data was properly set.
  295. $acknowledgeMessage = $responseBody[0]->getData();
  296. // check that we have a message beening returned
  297. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  298. // Check the message body is the expected data to be returned
  299. $this->assertEquals("String: 12345", $acknowledgeMessage->body);
  300. }
  301. /**
  302. * Test to make sure that you can have the same method name in two different classes.
  303. *
  304. * @group ZF-5040
  305. */
  306. public function testSameMethodNameInTwoServices()
  307. {
  308. $this->_server->setClass('ServiceA');
  309. $this->_server->setClass('ServiceB');
  310. // create a mock remoting message
  311. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  312. $message->operation = 'getMenu';
  313. $message->source = 'ServiceB';
  314. $message->body = array();
  315. // create a mock message body to place th remoting message inside
  316. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  317. $request = new Zend_Amf_Request();
  318. // at the requested service to a request
  319. $request->addAmfBody($newBody);
  320. $request->setObjectEncoding(0x03);
  321. // let the server handle mock request
  322. $result = $this->_server->handle($request);
  323. $response = $this->_server->getResponse();
  324. $responseBody = $response->getAmfBodies();
  325. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  326. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  327. // Now check if the return data was properly set.
  328. $acknowledgeMessage = $responseBody[0]->getData();
  329. // check that we have a message beening returned
  330. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  331. // Check the message body is the expected data to be returned
  332. $this->assertEquals("myMenuB", $acknowledgeMessage->body);
  333. }
  334. /**
  335. * test command message. THis is the first call the Flex
  336. * makes before any subsequent service calls.
  337. */
  338. public function testCommandMessagePingOperation()
  339. {
  340. $message = new Zend_Amf_Value_Messaging_CommandMessage();
  341. $message->operation = 5;
  342. $message->messageId = $message->generateId();
  343. // create a mock message body to place th remoting message inside
  344. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  345. $request = new Zend_Amf_Request();
  346. // at the requested service to a request
  347. $request->addAmfBody($newBody);
  348. $request->setObjectEncoding(0x03);
  349. // let the server handle mock request
  350. $result = $this->_server->handle($request);
  351. $response = $this->_server->getResponse();
  352. $responseBody = $response->getAmfBodies();
  353. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  354. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  355. // Now check if the return data was properly set.
  356. $acknowledgeMessage = $responseBody[0]->getData();
  357. // check that we have a message beening returned
  358. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  359. // Check that the MessageID was not corrupeted when set to the correlationId
  360. $this->assertEquals($acknowledgeMessage->correlationId, $message->messageId);
  361. }
  362. public function testInvalidAmf0MessageShouldResultInErrorMessage()
  363. {
  364. // serialize the data to an AMF output stream
  365. $data[] = "12345";
  366. $this->_server->setClass('Zend_Amf_testclass');
  367. $newBody = new Zend_Amf_Value_MessageBody("bogus","/1",$data);
  368. $request = new Zend_Amf_Request();
  369. $request->addAmfBody($newBody);
  370. $request->setObjectEncoding(0x00);
  371. $result = $this->_server->handle($request);
  372. $bodies = $result->getAmfBodies();
  373. $found = false;
  374. foreach ($bodies as $body) {
  375. $data = $body->getData();
  376. if (!is_array($data)) {
  377. continue;
  378. }
  379. if (!array_key_exists('description', $data)) {
  380. continue;
  381. }
  382. if (strstr($data['description'], 'does not exist')) {
  383. $found = true;
  384. break;
  385. }
  386. }
  387. $this->assertTrue($found, 'Invalid method did not raise error condition' . var_export($bodies, 1));
  388. }
  389. public function testInvalidCommandMessageShouldResultInErrorMessage()
  390. {
  391. $message = new Zend_Amf_Value_Messaging_CommandMessage();
  392. $message->operation = 'pong';
  393. $message->messageId = $message->generateId();
  394. // create a mock message body to place th remoting message inside
  395. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  396. $request = new Zend_Amf_Request();
  397. // at the requested service to a request
  398. $request->addAmfBody($newBody);
  399. $request->setObjectEncoding(0x03);
  400. // let the server handle mock request
  401. $result = $this->_server->handle($request);
  402. $response = $this->_server->getResponse();
  403. $responseBody = $response->getAmfBodies();
  404. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  405. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  406. // Now check if the return data was properly set.
  407. $message = $responseBody[0]->getData();
  408. // check that we have a message beening returned
  409. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  410. }
  411. /**
  412. * Add a class mapping and lookup the mapping to make sure
  413. * the mapping succeeds
  414. */
  415. public function testClassMap()
  416. {
  417. $this->_server->setClassMap('controller.test', 'Zend_Amf_testclass');
  418. $className = Zend_Amf_Parse_TypeLoader::getMappedClassName('Zend_Amf_testclass');
  419. $this->assertEquals('controller.test', $className);
  420. }
  421. public function testDispatchingMethodShouldReturnErrorMessageForInvalidMethod()
  422. {
  423. // serialize the data to an AMF output stream
  424. $data[] = "12345";
  425. $this->_server->setClass('Zend_Amf_testclass');
  426. // create a mock remoting message
  427. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  428. $message->operation = 'bogus'; // INVALID method!
  429. $message->body = $data;
  430. // create a mock message body to place th remoting message inside
  431. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  432. $request = new Zend_Amf_Request();
  433. // at the requested service to a request
  434. $request->addAmfBody($newBody);
  435. $request->setObjectEncoding(0x03);
  436. // let the server handle mock request
  437. $result = $this->_server->handle($request);
  438. $bodies = $result->getAmfBodies();
  439. $found = false;
  440. foreach ($bodies as $body) {
  441. $data = $body->getData();
  442. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  443. if (strstr($data->faultString, 'does not exist')) {
  444. $found = true;
  445. break;
  446. }
  447. }
  448. }
  449. $this->assertTrue($found, 'Invalid method did not raise error condition: ' . var_export($bodies, 1));
  450. }
  451. public function testDispatchingMethodThatThrowsExceptionShouldReturnErrorMessageWhenProductionFlagOff()
  452. {
  453. // serialize the data to an AMF output stream
  454. $data = array();
  455. $this->_server->setClass('Zend_Amf_testclass');
  456. // create a mock remoting message
  457. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  458. $message->operation = 'throwException';
  459. $message->source = 'Zend_Amf_testclass';
  460. $message->body = $data;
  461. // create a mock message body to place th remoting message inside
  462. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  463. $request = new Zend_Amf_Request();
  464. // at the requested service to a request
  465. $request->addAmfBody($newBody);
  466. $request->setObjectEncoding(0x03);
  467. // let the server handle mock request
  468. $result = $this->_server->handle($request);
  469. $bodies = $result->getAmfBodies();
  470. $found = false;
  471. foreach ($bodies as $body) {
  472. $data = $body->getData();
  473. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  474. if (strstr($data->faultString, 'should not be displayed')) {
  475. $found = true;
  476. break;
  477. }
  478. }
  479. }
  480. $this->assertTrue($found, 'Method raising exception should display error message when not in production');
  481. }
  482. public function testDispatchingMethodThatThrowsExceptionShouldNotReturnErrorMessageWhenProductionFlagOn()
  483. {
  484. // serialize the data to an AMF output stream
  485. $data = array();
  486. $this->_server->setClass('Zend_Amf_testclass')
  487. ->setProduction(true);
  488. // create a mock remoting message
  489. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  490. $message->operation = 'throwException';
  491. $message->source = 'Zend_Amf_testclass';
  492. $message->body = $data;
  493. // create a mock message body to place th remoting message inside
  494. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  495. $request = new Zend_Amf_Request();
  496. // at the requested service to a request
  497. $request->addAmfBody($newBody);
  498. $request->setObjectEncoding(0x03);
  499. // let the server handle mock request
  500. $result = $this->_server->handle($request);
  501. $bodies = $result->getAmfBodies();
  502. $found = false;
  503. foreach ($bodies as $body) {
  504. $data = $body->getData();
  505. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  506. if (strstr($data->faultString, 'should not be displayed')) {
  507. $found = true;
  508. break;
  509. }
  510. }
  511. }
  512. $this->assertFalse($found, 'Method raising exception should not display error message when in production');
  513. }
  514. public function testDispatchingMethodShouldPassInvocationArgumentsToMethod()
  515. {
  516. // serialize the data to an AMF output stream
  517. $data[] = "baz";
  518. $this->_server->setClass('Zend_Amf_testclass', '', 'foo', 'bar');
  519. // create a mock remoting message
  520. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  521. $message->operation = 'checkArgv';
  522. $message->source = 'Zend_Amf_testclass';
  523. $message->body = $data;
  524. // create a mock message body to place th remoting message inside
  525. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  526. $request = new Zend_Amf_Request();
  527. // at the requested service to a request
  528. $request->addAmfBody($newBody);
  529. $request->setObjectEncoding(0x03);
  530. // let the server handle mock request
  531. $result = $this->_server->handle($request);
  532. $bodies = $result->getAmfBodies();
  533. $found = false;
  534. foreach ($bodies as $body) {
  535. $data = $body->getData();
  536. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  537. if ('baz:foo:bar' == $data->body) {
  538. $found = true;
  539. break;
  540. }
  541. }
  542. }
  543. $this->assertTrue($found, 'Valid response not found');
  544. }
  545. public function testServerShouldSeamlesslyInvokeStaticMethods()
  546. {
  547. // serialize the data to an AMF output stream
  548. $data[] = "testing";
  549. $this->_server->setClass('Zend_Amf_testclass');
  550. // create a mock remoting message
  551. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  552. $message->operation = 'checkStaticUsage';
  553. $message->source = 'Zend_Amf_testclass';
  554. $message->body = $data;
  555. // create a mock message body to place th remoting message inside
  556. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  557. $request = new Zend_Amf_Request();
  558. // at the requested service to a request
  559. $request->addAmfBody($newBody);
  560. $request->setObjectEncoding(0x03);
  561. // let the server handle mock request
  562. $result = $this->_server->handle($request);
  563. $bodies = $result->getAmfBodies();
  564. $found = false;
  565. foreach ($bodies as $body) {
  566. $data = $body->getData();
  567. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  568. if ('testing' == $data->body) {
  569. $found = true;
  570. break;
  571. }
  572. }
  573. }
  574. $this->assertTrue($found, 'Valid response not found');
  575. }
  576. public function testServerShouldSeamlesslyInvokeFunctions()
  577. {
  578. // serialize the data to an AMF output stream
  579. $data[] = 'foo';
  580. $data[] = 'bar';
  581. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  582. // create a mock remoting message
  583. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  584. $message->operation = 'Zend_Amf_Server_testFunction';
  585. $message->source = null;
  586. $message->body = $data;
  587. // create a mock message body to place th remoting message inside
  588. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  589. $request = new Zend_Amf_Request();
  590. // at the requested service to a request
  591. $request->addAmfBody($newBody);
  592. $request->setObjectEncoding(0x03);
  593. // let the server handle mock request
  594. $result = $this->_server->handle($request);
  595. $bodies = $result->getAmfBodies();
  596. $found = false;
  597. foreach ($bodies as $body) {
  598. $data = $body->getData();
  599. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  600. if ('bar: foo' == $data->body) {
  601. $found = true;
  602. break;
  603. }
  604. }
  605. }
  606. $this->assertTrue($found, 'Valid response not found');
  607. }
  608. public function testDispatchingMethodCorrespondingToClassWithPrivateConstructorShouldReturnErrorMessage()
  609. {
  610. // serialize the data to an AMF output stream
  611. $data[] = "baz";
  612. $this->_server->setClass('Zend_Amf_testclassPrivate');
  613. // create a mock remoting message
  614. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  615. $message->operation = 'test1';
  616. $message->source = 'Zend_Amf_testclassPrivate';
  617. $message->body = $data;
  618. // create a mock message body to place th remoting message inside
  619. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  620. $request = new Zend_Amf_Request();
  621. // at the requested service to a request
  622. $request->addAmfBody($newBody);
  623. $request->setObjectEncoding(0x03);
  624. // let the server handle mock request
  625. $result = $this->_server->handle($request);
  626. $bodies = $result->getAmfBodies();
  627. $found = false;
  628. foreach ($bodies as $body) {
  629. $data = $body->getData();
  630. if ('Zend_Amf_Value_Messaging_ErrorMessage' == get_class($data)) {
  631. if (strstr($data->faultString, 'Error instantiating class')) {
  632. $found = true;
  633. break;
  634. }
  635. }
  636. }
  637. $this->assertTrue($found, 'Method succeeded?');
  638. }
  639. public function testNotPassingRequestToHandleShouldResultInServerCreatingRequest()
  640. {
  641. $this->_server->setClass('Zend_Amf_testclass');
  642. ob_start();
  643. $result = $this->_server->handle();
  644. $content = ob_get_clean();
  645. $request = $this->_server->getRequest();
  646. $this->assertTrue($request instanceof Zend_Amf_Request_Http);
  647. $bodies = $request->getAmfBodies();
  648. $this->assertEquals(0, count($bodies));
  649. $this->assertContains('Endpoint', $content);
  650. }
  651. public function testSetRequestShouldAllowValidStringClassNames()
  652. {
  653. $this->_server->setRequest('Zend_Amf_Request');
  654. $request = $this->_server->getRequest();
  655. $this->assertTrue($request instanceof Zend_Amf_Request);
  656. $this->assertFalse($request instanceof Zend_Amf_Request_Http);
  657. }
  658. /**
  659. * @expectedException Zend_Amf_Server_Exception
  660. */
  661. public function testSetRequestShouldRaiseExceptionOnInvalidStringClassName()
  662. {
  663. $this->_server->setRequest('Zend_Amf_ServerTest_BogusRequest');
  664. }
  665. public function testSetRequestShouldAllowValidRequestObjects()
  666. {
  667. $request = new Zend_Amf_Request;
  668. $this->_server->setRequest($request);
  669. $this->assertSame($request, $this->_server->getRequest());
  670. }
  671. /**
  672. * @expectedException Zend_Amf_Server_Exception
  673. */
  674. public function testSetRequestShouldRaiseExceptionOnInvalidRequestObjects()
  675. {
  676. require_once 'Zend/XmlRpc/Request.php';
  677. $request = new Zend_XmlRpc_Request;
  678. $this->_server->setRequest($request);
  679. }
  680. public function testSetResponseShouldAllowValidStringClassNames()
  681. {
  682. $this->_server->setResponse('Zend_Amf_Response');
  683. $response = $this->_server->getResponse();
  684. $this->assertTrue($response instanceof Zend_Amf_Response);
  685. $this->assertFalse($response instanceof Zend_Amf_Response_Http);
  686. }
  687. /**
  688. * @expectedException Zend_Amf_Server_Exception
  689. */
  690. public function testSetResponseShouldRaiseExceptionOnInvalidStringClassName()
  691. {
  692. $this->_server->setResponse('Zend_Amf_ServerTest_BogusResponse');
  693. }
  694. public function testSetResponseShouldAllowValidResponseObjects()
  695. {
  696. $response = new Zend_Amf_Response;
  697. $this->_server->setResponse($response);
  698. $this->assertSame($response, $this->_server->getResponse());
  699. }
  700. /**
  701. * @expectedException Zend_Amf_Server_Exception
  702. */
  703. public function testSetResponseShouldRaiseExceptionOnInvalidResponseObjects()
  704. {
  705. require_once 'Zend/XmlRpc/Response.php';
  706. $response = new Zend_XmlRpc_Response;
  707. $this->_server->setResponse($response);
  708. }
  709. public function testGetFunctionsShouldReturnArrayOfDispatchables()
  710. {
  711. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tf')
  712. ->setClass('Zend_Amf_testclass', 'tc')
  713. ->setClass('Zend_Amf_testclassPrivate', 'tcp');
  714. $functions = $this->_server->getFunctions();
  715. $this->assertTrue(is_array($functions));
  716. $this->assertTrue(0 < count($functions));
  717. $namespaces = array('tf', 'tc', 'tcp');
  718. foreach ($functions as $key => $value) {
  719. $this->assertTrue(strstr($key, '.') ? true : false, $key);
  720. $ns = substr($key, 0, strpos($key, '.'));
  721. $this->assertContains($ns, $namespaces, $key);
  722. $this->assertTrue($value instanceof Zend_Server_Reflection_Function_Abstract);
  723. }
  724. }
  725. public function testFaultShouldBeUnimplemented()
  726. {
  727. $this->assertNull($this->_server->fault());
  728. }
  729. public function testPersistenceShouldBeUnimplemented()
  730. {
  731. $this->assertNull($this->_server->setPersistence(true));
  732. }
  733. public function testLoadFunctionsShouldBeUnimplemented()
  734. {
  735. $this->assertNull($this->_server->loadFunctions(true));
  736. }
  737. /**
  738. * @group ZF-5388
  739. * Issue if only one parameter of type array is passed it is nested into another array.
  740. */
  741. public function testSingleArrayParamaterAMF3()
  742. {
  743. // serialize the data to an AMF output stream
  744. $data[] = array('item1', 'item2');
  745. $this->_server->setClass('Zend_Amf_testclass');
  746. // create a mock remoting message
  747. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  748. $message->operation = 'testSingleArrayParamater';
  749. $message->source = 'Zend_Amf_testclass';
  750. $message->body = $data;
  751. // create a mock message body to place th remoting message inside
  752. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  753. $request = new Zend_Amf_Request();
  754. // at the requested service to a request
  755. $request->addAmfBody($newBody);
  756. $request->setObjectEncoding(0x03);
  757. // let the server handle mock request
  758. $result = $this->_server->handle($request);
  759. $response = $this->_server->getResponse();
  760. $responseBody = $response->getAmfBodies();
  761. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  762. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  763. // Now check if the return data was properly set.
  764. $acknowledgeMessage = $responseBody[0]->getData();
  765. // check that we have a message beening returned
  766. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  767. // Check the message body is the expected data to be returned
  768. $this->assertTrue($acknowledgeMessage->body);
  769. }
  770. /**
  771. * @group ZF-5388
  772. * Issue if only one parameter of type array is passed it is nested into another array.
  773. */
  774. public function testSingleArrayParamaterAMF0()
  775. {
  776. $data[] = array('item1', 'item2');
  777. $this->_server->setClass('Zend_Amf_testclass');
  778. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.testSingleArrayParamater","/1",$data);
  779. $request = new Zend_Amf_Request();
  780. $request->addAmfBody($newBody);
  781. $request->setObjectEncoding(0x00);
  782. $result = $this->_server->handle($request);
  783. $response = $this->_server->getResponse();
  784. $responseBody = $response->getAmfBodies();
  785. // Now check if the return data was properly set.
  786. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  787. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  788. $this->assertTrue($responseBody[0]->getData(), var_export($responseBody, 1));
  789. }
  790. /**
  791. * @group ZF-5388
  792. * Issue if only one parameter of type array is passed it is nested into another array.
  793. */
  794. public function testMutiArrayParamaterAMF3()
  795. {
  796. // serialize the data to an AMF output stream
  797. $data[] = array('item1', 'item2');
  798. $data[] = array('item3', 'item4');
  799. $this->_server->setClass('Zend_Amf_testclass');
  800. // create a mock remoting message
  801. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  802. $message->operation = 'testMultiArrayParamater';
  803. $message->source = 'Zend_Amf_testclass';
  804. $message->body = $data;
  805. // create a mock message body to place th remoting message inside
  806. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  807. $request = new Zend_Amf_Request();
  808. // at the requested service to a request
  809. $request->addAmfBody($newBody);
  810. $request->setObjectEncoding(0x03);
  811. // let the server handle mock request
  812. $result = $this->_server->handle($request);
  813. $response = $this->_server->getResponse();
  814. $responseBody = $response->getAmfBodies();
  815. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  816. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  817. // Now check if the return data was properly set.
  818. $acknowledgeMessage = $responseBody[0]->getData();
  819. // check that we have a message beening returned
  820. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  821. // Check the message body is the expected data to be returned
  822. $this->assertEquals(4, count($acknowledgeMessage->body));
  823. }
  824. /**
  825. * @group ZF-5388
  826. * Issue if multipol parameters are sent and one is of type array is passed.
  827. */
  828. public function testMutiArrayParamaterAMF0()
  829. {
  830. $data[] = array('item1', 'item2');
  831. $data[] = array('item3', 'item4');
  832. $this->_server->setClass('Zend_Amf_testclass');
  833. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.testMultiArrayParamater","/1",$data);
  834. $request = new Zend_Amf_Request();
  835. $request->addAmfBody($newBody);
  836. $request->setObjectEncoding(0x00);
  837. $result = $this->_server->handle($request);
  838. $response = $this->_server->getResponse();
  839. $responseBody = $response->getAmfBodies();
  840. // Now check if the return data was properly set.
  841. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  842. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  843. $this->assertEquals(4, count($responseBody[0]->getData()), var_export($responseBody, 1));
  844. }
  845. /**
  846. * @group ZF-5346
  847. */
  848. public function testSingleObjectParamaterAMF3()
  849. {
  850. // serialize the data to an AMF output stream
  851. $data[] = array('item1', 'item2');
  852. $data[] = array('item3', 'item4');
  853. $this->_server->setClass('Zend_Amf_testclass');
  854. // create a mock remoting message
  855. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  856. $message->operation = 'testMultiArrayParamater';
  857. $message->source = 'Zend_Amf_testclass';
  858. $message->body = $data;
  859. // create a mock message body to place th remoting message inside
  860. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  861. $request = new Zend_Amf_Request();
  862. // at the requested service to a request
  863. $request->addAmfBody($newBody);
  864. $request->setObjectEncoding(0x03);
  865. // let the server handle mock request
  866. $result = $this->_server->handle($request);
  867. $response = $this->_server->getResponse();
  868. $responseBody = $response->getAmfBodies();
  869. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  870. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  871. // Now check if the return data was properly set.
  872. $acknowledgeMessage = $responseBody[0]->getData();
  873. // check that we have a message beening returned
  874. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  875. // Check the message body is the expected data to be returned
  876. $this->assertEquals(4, count($acknowledgeMessage->body));
  877. }
  878. /**
  879. * Check that when using server->setSession you get an amf header that has an append to gateway sessionID
  880. * @group ZF-5381
  881. */
  882. public function testSessionAmf3()
  883. {
  884. Zend_Session::$_unitTestEnabled = true;
  885. Zend_Session::start();
  886. $this->_server->setClass('Zend_Amf_testSession');
  887. $this->_server->setSession();
  888. // create a mock remoting message
  889. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  890. $message->operation = 'getCount';
  891. $message->source = 'Zend_Amf_testSession';
  892. $message->body = array();
  893. // create a mock message body to place th remoting message inside
  894. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  895. $request = new Zend_Amf_Request();
  896. // at the requested service to a request
  897. $request->addAmfBody($newBody);
  898. $request->setObjectEncoding(0x03);
  899. // let the server handle mock request
  900. $result = $this->_server->handle($request);
  901. $response = $this->_server->getResponse();
  902. $responseBody = $response->getAmfBodies();
  903. // Now check if the return data was properly set.
  904. $acknowledgeMessage = $responseBody[0]->getData();
  905. // check that we have a message beening returned
  906. $this->assertEquals(1, $acknowledgeMessage->body);
  907. // check that a header is being returned for the session id
  908. $headerBody = $response->getAmfHeaders();
  909. $this->assertEquals('AppendToGatewayUrl',$headerBody[0]->name);
  910. // Do not stop session since it still can be used by other tests
  911. // Zend_Session::stop();
  912. }
  913. public function testAddDirectory()
  914. {
  915. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  916. $this->_server->addDirectory(dirname(__FILE__)."/_files/");
  917. $dirs = $this->_server->getDirectory();
  918. $this->assertContains(dirname(__FILE__)."/_files/services/", $dirs);
  919. $this->assertContains(dirname(__FILE__)."/_files/", $dirs);
  920. }
  921. public function testAddDirectoryService()
  922. {
  923. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  924. // should take it from the path above, not include path
  925. $origPath = get_include_path();
  926. set_include_path($origPath.PATH_SEPARATOR.dirname(__FILE__));
  927. // create a mock remoting message
  928. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  929. $message->operation = 'getMenu';
  930. $message->source = 'ServiceC';
  931. $message->body = array();
  932. // create a mock message body to place th remoting message inside
  933. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  934. $request = new Zend_Amf_Request();
  935. // at the requested service to a request
  936. $request->addAmfBody($newBody);
  937. $request->setObjectEncoding(0x03);
  938. // let the server handle mock request
  939. $this->_server->handle($request);
  940. set_include_path($origPath);
  941. $response = $this->_server->getResponse()->getAMFBodies();
  942. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  943. $this->assertEquals("Service: MenuC", $response[0]->getData()->body);
  944. }
  945. public function testAddDirectoryService2()
  946. {
  947. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  948. // create a mock remoting message
  949. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  950. $message->operation = 'getMenu';
  951. $message->source = 'My.ServiceA';
  952. $message->body = array();
  953. // create a mock message body to place th remoting message inside
  954. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  955. $request = new Zend_Amf_Request();
  956. // at the requested service to a request
  957. $request->addAmfBody($newBody);
  958. $request->setObjectEncoding(0x03);
  959. // let the server handle mock request
  960. $this->_server->handle($request);
  961. $response = $this->_server->getResponse()->getAMFBodies();
  962. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  963. $this->assertEquals("Service: myMenuA", $response[0]->getData()->body);
  964. }
  965. /*
  966. * See ZF-6625
  967. */
  968. public function testAddDirectoryServiceNotFound()
  969. {
  970. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  971. // create a mock remoting message
  972. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  973. $message->operation = 'encode';
  974. $message->source = 'Zend_Json';
  975. $message->body = array("123");
  976. // create a mock message body to place th remoting message inside
  977. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  978. $request = new Zend_Amf_Request();
  979. // at the requested service to a request
  980. $request->addAmfBody($newBody);
  981. $request->setObjectEncoding(0x03);
  982. // let the server handle mock request
  983. $this->_server->handle($request);
  984. $response = $this->_server->getResponse()->getAMFBodies();
  985. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  986. // test the same while ensuring Zend_Json is loaded
  987. require_once 'Zend/Json.php';
  988. $this->_server->handle($request);
  989. $response = $this->_server->getResponse()->getAMFBodies();
  990. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  991. }
  992. /* See ZF-7102 */
  993. public function testCtorExcection()
  994. {
  995. $this->_server->setClass('Zend_Amf_testException');
  996. $this->_server->setProduction(false);
  997. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  998. $message->operation = 'hello';
  999. $message->source = 'Zend_Amf_testException';
  1000. $message->body = array("123");
  1001. // create a mock message body to place th remoting message inside
  1002. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  1003. $request = new Zend_Amf_Request();
  1004. // at the requested service to a request
  1005. $request->addAmfBody($newBody);
  1006. $request->setObjectEncoding(0x03);
  1007. // let the server handle mock request
  1008. $this->_server->handle($request);
  1009. $response = $this->_server->getResponse()->getAMFBodies();
  1010. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  1011. $this->assertContains("Oops, exception!", $response[0]->getData()->faultString);
  1012. }
  1013. /** @group ZF-11529 */
  1014. public function testSettingAuthAdapterWithAclSetsServerAcl()
  1015. {
  1016. $aclFile = dirname(__FILE__) . '/_files/acl.xml';
  1017. $authAdapter = new Zend_Amf_Adobe_Auth($aclFile);
  1018. $this->_server->setAuth($authAdapter);
  1019. $this->assertSame($authAdapter->getAcl(), $this->_server->getAcl());
  1020. }
  1021. /** @group ZF-11529 */
  1022. public function testSettingAuthAdapterWithAclWhenServerAclAlreadyPopulatedWillNotChangeServerAcl()
  1023. {
  1024. $acl = new Zend_Acl();
  1025. $this->_server->setAcl($acl);
  1026. $aclFile = dirname(__FILE__) . '/_files/acl.xml';
  1027. $authAdapter = new Zend_Amf_Adobe_Auth($aclFile);
  1028. $this->_server->setAuth($authAdapter);
  1029. $this->assertNotSame($authAdapter->getAcl(), $this->_server->getAcl());
  1030. $this->assertSame($acl, $this->_server->getAcl());
  1031. }
  1032. }
  1033. if (PHPUnit_MAIN_METHOD == "Zend_Amf_ServerTest::main") {
  1034. Zend_Amf_ServerTest::main();
  1035. }
  1036. /**
  1037. * Zend_Amf_Server_testFunction
  1038. *
  1039. * Function for use with Amf server unit tests
  1040. *
  1041. * @param array $var1
  1042. * @param string $var2
  1043. * @return string
  1044. */
  1045. function Zend_Amf_Server_testFunction($var1, $var2 = 'optional')
  1046. {
  1047. return $var2 . ': ' . implode(',', (array) $var1);
  1048. }
  1049. /**
  1050. * Zend_Amf_Server_testFunction2
  1051. *
  1052. * Function for use with Amf server unit tests
  1053. *
  1054. * @return string
  1055. */
  1056. function Zend_Amf_Server_testFunction2()
  1057. {
  1058. return 'function2';
  1059. }
  1060. /**
  1061. * Class to used with Zend_Amf_Server unit tests.
  1062. *
  1063. */
  1064. class Zend_Amf_testclass
  1065. {
  1066. public function __construct()
  1067. {
  1068. }
  1069. /**
  1070. * Concatinate a string
  1071. *
  1072. * @param string
  1073. * @return string
  1074. */
  1075. public function test1($string = '')
  1076. {
  1077. return 'String: '. (string) $string;
  1078. }
  1079. /**
  1080. * Test2
  1081. *
  1082. * Returns imploded array
  1083. *
  1084. * @param array $array
  1085. * @return string
  1086. */
  1087. public static function test2($array)
  1088. {
  1089. return implode('; ', (array) $array);
  1090. }
  1091. /**
  1092. * Test3
  1093. *
  1094. * Should not be available...
  1095. *
  1096. * @return void
  1097. */
  1098. protected function _test3()
  1099. {
  1100. }
  1101. /**
  1102. * Test base64 encoding in request and response
  1103. *
  1104. * @param base64 $data
  1105. * @return base64
  1106. */
  1107. public function base64($data)
  1108. {
  1109. return $data;
  1110. }
  1111. /**
  1112. * Test that invoke arguments are passed
  1113. *
  1114. * @param string $message message argument for comparisons
  1115. * @return string
  1116. */
  1117. public function checkArgv($message)
  1118. {
  1119. $argv = func_get_args();
  1120. return implode(':', $argv);
  1121. }
  1122. /**
  1123. * Test static usage
  1124. *
  1125. * @param string $message
  1126. * @return string
  1127. */
  1128. public static function checkStaticUsage($message)
  1129. {
  1130. return $message;
  1131. }
  1132. /**
  1133. * Test throwing exceptions
  1134. *
  1135. * @return void
  1136. */
  1137. public function throwException()
  1138. {
  1139. throw new Exception('This exception should not be displayed');
  1140. }
  1141. /**
  1142. * test if we can send an array as a paramater without it getting nested two
  1143. * Used to test ZF-5388
  1144. */
  1145. public function testSingleArrayParamater($inputArray){
  1146. if( $inputArray[0] == 'item1' ){
  1147. return true;
  1148. }
  1149. return false;
  1150. }
  1151. /**
  1152. * This will crash if two arrays are not passed into the function.
  1153. * Used to test ZF-5388
  1154. */
  1155. public function testMultiArrayParamater($arrayOne, $arrayTwo)
  1156. {
  1157. return array_merge($arrayOne, $arrayTwo);
  1158. }
  1159. }
  1160. class Zend_Amf_testException
  1161. {
  1162. public function __construct() {
  1163. throw new Exception("Oops, exception!");
  1164. }
  1165. public function hello() {
  1166. return "hello";
  1167. }
  1168. }
  1169. /**
  1170. * Class with private constructor
  1171. */
  1172. class Zend_Amf_testclassPrivate
  1173. {
  1174. private function __construct()
  1175. {
  1176. }
  1177. /**
  1178. * Test1
  1179. *
  1180. * Returns 'String: ' . $string
  1181. *
  1182. * @param string $string
  1183. * @return string
  1184. */
  1185. public function test1($string = '')
  1186. {
  1187. return 'String: '. (string) $string;
  1188. }
  1189. public function hello()
  1190. {
  1191. return "hello";
  1192. }
  1193. }
  1194. /**
  1195. * Example class for sending a session back to ActionScript.
  1196. */
  1197. class Zend_Amf_testSession
  1198. {
  1199. /** Check if the session is available or create it. */
  1200. public function __construct() {
  1201. if (!isset($_SESSION['count'])) {
  1202. $_SESSION['count'] = 0;
  1203. }
  1204. }
  1205. /** increment the current count session variable and return it's value */
  1206. public function getCount()
  1207. {
  1208. $_SESSION['count']++;
  1209. return $_SESSION['count'];
  1210. }
  1211. }