PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Amf/ServerTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 1380 lines | 894 code | 130 blank | 356 comment | 30 complexity | 9387f4724243b29dd6904fdc45065506 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file