ServerTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_XmlRpc
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_XmlRpc_ServerTest::main() if this source file is executed directly.
  23. if (!defined('PHPUnit_MAIN_METHOD')) {
  24. define('PHPUnit_MAIN_METHOD', 'Zend_XmlRpc_ServerTest::main');
  25. }
  26. require_once dirname(__FILE__) . '/../../TestHelper.php';
  27. require_once 'Zend/XmlRpc/Server.php';
  28. require_once 'Zend/XmlRpc/Request.php';
  29. require_once 'Zend/XmlRpc/Response.php';
  30. /**
  31. * Test case for Zend_XmlRpc_Server
  32. *
  33. * @category Zend
  34. * @package Zend_XmlRpc
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_XmlRpc
  39. */
  40. class Zend_XmlRpc_ServerTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Zend_XmlRpc_Server object
  44. * @var Zend_XmlRpc_Server
  45. */
  46. protected $_server;
  47. /**
  48. * Runs the test methods of this class.
  49. *
  50. * @return void
  51. */
  52. public static function main()
  53. {
  54. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_ServerTest");
  55. $result = PHPUnit_TextUI_TestRunner::run($suite);
  56. }
  57. /**
  58. * Setup environment
  59. */
  60. public function setUp()
  61. {
  62. $this->_server = new Zend_XmlRpc_Server();
  63. }
  64. /**
  65. * Teardown environment
  66. */
  67. public function tearDown()
  68. {
  69. unset($this->_server);
  70. }
  71. /**
  72. * __construct() test
  73. *
  74. * Call as method call
  75. *
  76. * Returns: void
  77. */
  78. public function test__construct()
  79. {
  80. $this->assertTrue($this->_server instanceof Zend_XmlRpc_Server);
  81. }
  82. /**
  83. * addFunction() test
  84. *
  85. * Call as method call
  86. *
  87. * Expects:
  88. * - function:
  89. * - namespace: Optional; has default;
  90. *
  91. * Returns: void
  92. */
  93. public function testAddFunction()
  94. {
  95. try {
  96. $this->_server->addFunction('Zend_XmlRpc_Server_testFunction', 'zsr');
  97. } catch (Zend_XmlRpc_Exception $e) {
  98. $this->fail('Attachment should have worked');
  99. }
  100. $methods = $this->_server->listMethods();
  101. $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction', $methods));
  102. try {
  103. $this->_server->addFunction('nosuchfunction');
  104. $this->fail('nosuchfunction() should not exist and should throw an exception');
  105. } catch (Zend_XmlRpc_Exception $e) {
  106. // do nothing
  107. }
  108. $server = new Zend_XmlRpc_Server();
  109. try {
  110. $server->addFunction(
  111. array(
  112. 'Zend_XmlRpc_Server_testFunction',
  113. 'Zend_XmlRpc_Server_testFunction2',
  114. ),
  115. 'zsr'
  116. );
  117. } catch (Zend_XmlRpc_Exception $e) {
  118. $this->fail('Error attaching array of functions: ' . $e->getMessage());
  119. }
  120. $methods = $server->listMethods();
  121. $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction', $methods));
  122. $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction2', $methods));
  123. }
  124. /**
  125. * get/loadFunctions() test
  126. */
  127. public function testFunctions()
  128. {
  129. try {
  130. $this->_server->addFunction(
  131. array(
  132. 'Zend_XmlRpc_Server_testFunction',
  133. 'Zend_XmlRpc_Server_testFunction2',
  134. ),
  135. 'zsr'
  136. );
  137. } catch (Zend_XmlRpc_Exception $e) {
  138. $this->fail('Error attaching functions: ' . $e->getMessage());
  139. }
  140. $expected = $this->_server->listMethods();
  141. $functions = $this->_server->getFunctions();
  142. $server = new Zend_XmlRpc_Server();
  143. $server->loadFunctions($functions);
  144. $actual = $server->listMethods();
  145. $this->assertSame($expected, $actual);
  146. }
  147. /**
  148. * setClass() test
  149. */
  150. public function testSetClass()
  151. {
  152. $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test');
  153. $methods = $this->_server->listMethods();
  154. $this->assertTrue(in_array('test.test1', $methods));
  155. $this->assertTrue(in_array('test.test2', $methods));
  156. $this->assertFalse(in_array('test._test3', $methods));
  157. $this->assertFalse(in_array('test.__construct', $methods));
  158. }
  159. /**
  160. * @group ZF-6526
  161. */
  162. public function testSettingClassWithArguments()
  163. {
  164. $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'argv-argument');
  165. $this->assertTrue($this->_server->sendArgumentsToAllMethods());
  166. $request = new Zend_XmlRpc_Request();
  167. $request->setMethod('test.test4');
  168. $response = $this->_server->handle($request);
  169. $this->assertNotType('Zend_XmlRpc_Fault', $response);
  170. $this->assertSame(
  171. array('test1' => 'argv-argument',
  172. 'test2' => null,
  173. 'arg' => array('argv-argument')),
  174. $response->getReturnValue());
  175. }
  176. public function testSettingClassWithArgumentsOnlyPassingToConstructor()
  177. {
  178. $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'a1', 'a2');
  179. $this->_server->sendArgumentsToAllMethods(false);
  180. $this->assertFalse($this->_server->sendArgumentsToAllMethods());
  181. $request = new Zend_XmlRpc_Request();
  182. $request->setMethod('test.test4');
  183. $request->setParams(array('foo'));
  184. $response = $this->_server->handle($request);
  185. $this->assertNotType('Zend_XmlRpc_Fault', $response);
  186. $this->assertSame(array('test1' => 'a1', 'test2' => 'a2', 'arg' => array('foo')), $response->getReturnValue());
  187. }
  188. /**
  189. * fault() test
  190. */
  191. public function testFault()
  192. {
  193. $fault = $this->_server->fault('This is a fault', 411);
  194. $this->assertTrue($fault instanceof Zend_XmlRpc_Server_Fault);
  195. $this->assertEquals(411, $fault->getCode());
  196. $this->assertEquals('This is a fault', $fault->getMessage());
  197. $fault = $this->_server->fault(new Zend_XmlRpc_Server_Exception('Exception fault', 511));
  198. $this->assertTrue($fault instanceof Zend_XmlRpc_Server_Fault);
  199. $this->assertEquals(511, $fault->getCode());
  200. $this->assertEquals('Exception fault', $fault->getMessage());
  201. }
  202. /**
  203. * handle() test
  204. *
  205. * Call as method call
  206. *
  207. * Expects:
  208. * - request: Optional;
  209. *
  210. * Returns: Zend_XmlRpc_Response|Zend_XmlRpc_Fault
  211. */
  212. public function testHandle()
  213. {
  214. $request = new Zend_XmlRpc_Request();
  215. $request->setMethod('system.listMethods');
  216. $response = $this->_server->handle($request);
  217. $this->assertTrue($response instanceof Zend_XmlRpc_Response);
  218. $return = $response->getReturnValue();
  219. $this->assertTrue(is_array($return));
  220. $this->assertTrue(in_array('system.multicall', $return));
  221. }
  222. /**
  223. * Test that only calling methods using a valid parameter signature works
  224. */
  225. public function testHandle2()
  226. {
  227. $request = new Zend_XmlRpc_Request();
  228. $request->setMethod('system.methodHelp');
  229. $response = $this->_server->handle($request);
  230. $this->assertTrue($response instanceof Zend_XmlRpc_Fault);
  231. $this->assertEquals(623, $response->getCode());
  232. }
  233. public function testCallingInvalidMethod()
  234. {
  235. $request = new Zend_XmlRpc_Request();
  236. $request->setMethod('invalid');
  237. $response = $this->_server->handle($request);
  238. $this->assertType('Zend_XmlRpc_Fault', $response);
  239. $this->assertSame('Method "invalid" does not exist', $response->getMessage());
  240. $this->assertSame(620, $response->getCode());
  241. }
  242. /**
  243. * setResponseClass() test
  244. *
  245. * Call as method call
  246. *
  247. * Expects:
  248. * - class:
  249. *
  250. * Returns: boolean
  251. */
  252. public function testSetResponseClass()
  253. {
  254. $this->assertTrue($this->_server->setResponseClass('Zend_XmlRpc_Server_testResponse'));
  255. $request = new Zend_XmlRpc_Request();
  256. $request->setMethod('system.listMethods');
  257. $response = $this->_server->handle($request);
  258. $this->assertTrue($response instanceof Zend_XmlRpc_Response);
  259. $this->assertTrue($response instanceof Zend_XmlRpc_Server_testResponse);
  260. }
  261. /**
  262. * listMethods() test
  263. *
  264. * Call as method call
  265. *
  266. * Returns: array
  267. */
  268. public function testListMethods()
  269. {
  270. $methods = $this->_server->listMethods();
  271. $this->assertTrue(is_array($methods));
  272. $this->assertTrue(in_array('system.listMethods', $methods));
  273. $this->assertTrue(in_array('system.methodHelp', $methods));
  274. $this->assertTrue(in_array('system.methodSignature', $methods));
  275. $this->assertTrue(in_array('system.multicall', $methods));
  276. }
  277. /**
  278. * methodHelp() test
  279. *
  280. * Call as method call
  281. *
  282. * Expects:
  283. * - method:
  284. *
  285. * Returns: string
  286. */
  287. public function testMethodHelp()
  288. {
  289. $help = $this->_server->methodHelp('system.methodHelp', 'system.listMethods');
  290. $this->assertContains('Display help message for an XMLRPC method', $help);
  291. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Method "foo" does not exist');
  292. $this->_server->methodHelp('foo');
  293. }
  294. /**
  295. * methodSignature() test
  296. *
  297. * Call as method call
  298. *
  299. * Expects:
  300. * - method:
  301. *
  302. * Returns: array
  303. */
  304. public function testMethodSignature()
  305. {
  306. $sig = $this->_server->methodSignature('system.methodSignature');
  307. $this->assertTrue(is_array($sig));
  308. $this->assertEquals(1, count($sig), var_export($sig, 1));
  309. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Method "foo" does not exist');
  310. $this->_server->methodSignature('foo');
  311. }
  312. /**
  313. * multicall() test
  314. *
  315. * Call as method call
  316. *
  317. * Expects:
  318. * - methods:
  319. *
  320. * Returns: array
  321. */
  322. public function testMulticall()
  323. {
  324. $struct = array(
  325. array(
  326. 'methodName' => 'system.listMethods',
  327. 'params' => array()
  328. ),
  329. array(
  330. 'methodName' => 'system.methodHelp',
  331. 'params' => array('system.multicall')
  332. )
  333. );
  334. $request = new Zend_XmlRpc_Request();
  335. $request->setMethod('system.multicall');
  336. $request->addParam($struct);
  337. $response = $this->_server->handle($request);
  338. $this->assertTrue($response instanceof Zend_XmlRpc_Response, $response->__toString() . "\n\n" . $request->__toString());
  339. $returns = $response->getReturnValue();
  340. $this->assertTrue(is_array($returns));
  341. $this->assertEquals(2, count($returns), var_export($returns, 1));
  342. $this->assertTrue(is_array($returns[0]), var_export($returns[0], 1));
  343. $this->assertTrue(is_string($returns[1]), var_export($returns[1], 1));
  344. }
  345. /**
  346. * Test get/setEncoding()
  347. */
  348. public function testGetSetEncoding()
  349. {
  350. $this->assertEquals('UTF-8', $this->_server->getEncoding());
  351. $this->_server->setEncoding('ISO-8859-1');
  352. $this->assertEquals('ISO-8859-1', $this->_server->getEncoding());
  353. }
  354. /**
  355. * Test request/response encoding
  356. */
  357. public function testRequestResponseEncoding()
  358. {
  359. $response = $this->_server->handle();
  360. $request = $this->_server->getRequest();
  361. $this->assertEquals('UTF-8', $request->getEncoding());
  362. $this->assertEquals('UTF-8', $response->getEncoding());
  363. }
  364. /**
  365. * Test request/response encoding (alternate encoding)
  366. */
  367. public function testRequestResponseEncoding2()
  368. {
  369. $this->_server->setEncoding('ISO-8859-1');
  370. $response = $this->_server->handle();
  371. $request = $this->_server->getRequest();
  372. $this->assertEquals('ISO-8859-1', $request->getEncoding());
  373. $this->assertEquals('ISO-8859-1', $response->getEncoding());
  374. }
  375. public function testAddFunctionWithExtraArgs()
  376. {
  377. $this->_server->addFunction('Zend_XmlRpc_Server_testFunction', 'test', 'arg1');
  378. $methods = $this->_server->listMethods();
  379. $this->assertContains('test.Zend_XmlRpc_Server_testFunction', $methods);
  380. }
  381. public function testAddFunctionThrowsExceptionWithBadData()
  382. {
  383. $o = new stdClass();
  384. try {
  385. $this->_server->addFunction($o);
  386. $this->fail('addFunction() should not accept objects');
  387. } catch (Zend_XmlRpc_Exception $e) {
  388. // success
  389. }
  390. }
  391. public function testLoadFunctionsThrowsExceptionWithBadData()
  392. {
  393. $o = new stdClass();
  394. try {
  395. $this->_server->loadFunctions($o);
  396. $this->fail('loadFunctions() should not accept objects');
  397. } catch (Zend_XmlRpc_Exception $e) {
  398. // success
  399. }
  400. try {
  401. $this->_server->loadFunctions('foo');
  402. $this->fail('loadFunctions() should not accept primitive values');
  403. } catch (Zend_XmlRpc_Server_Exception $e) {
  404. // success
  405. }
  406. $o = array($o);
  407. try {
  408. $this->_server->loadFunctions($o);
  409. $this->fail('loadFunctions() should not allow non-reflection objects in an array');
  410. } catch (Zend_Server_Exception $e) {
  411. $this->assertSame('Invalid method provided', $e->getMessage());
  412. }
  413. }
  414. public function testLoadFunctionsReadsMethodsFromServerDefinitionObjects()
  415. {
  416. $mockedMethod = $this->getMock('Zend_Server_Method_Definition', array(), array(), '', false,
  417. false);
  418. $mockedDefinition = $this->getMock('Zend_Server_Definition', array(), array(), '', false, false);
  419. $mockedDefinition->expects($this->once())
  420. ->method('getMethods')
  421. ->will($this->returnValue(array('bar' => $mockedMethod)));
  422. $this->_server->loadFunctions($mockedDefinition);
  423. }
  424. public function testSetClassThrowsExceptionWithInvalidClass()
  425. {
  426. try {
  427. $this->_server->setClass('mybogusclass');
  428. $this->fail('setClass() should not allow invalid classes');
  429. } catch (Zend_XmlRpc_Exception $e) {
  430. }
  431. }
  432. public function testSetRequestUsingString()
  433. {
  434. $this->_server->setRequest('Zend_XmlRpc_Server_testRequest');
  435. $req = $this->_server->getRequest();
  436. $this->assertTrue($req instanceof Zend_XmlRpc_Server_testRequest);
  437. }
  438. public function testSetRequestThrowsExceptionOnBadClass()
  439. {
  440. try {
  441. $this->_server->setRequest('Zend_XmlRpc_Server_testRequest2');
  442. $this->fail('Invalid request class should throw exception');
  443. } catch (Zend_XmlRpc_Exception $e) {
  444. // success
  445. }
  446. try {
  447. $this->_server->setRequest($this);
  448. $this->fail('Invalid request object should throw exception');
  449. } catch (Zend_XmlRpc_Exception $e) {
  450. // success
  451. }
  452. }
  453. public function testHandleObjectMethod()
  454. {
  455. $this->_server->setClass('Zend_XmlRpc_Server_testClass');
  456. $request = new Zend_XmlRpc_Request();
  457. $request->setMethod('test1');
  458. $request->addParam('value');
  459. $response = $this->_server->handle($request);
  460. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  461. $this->assertEquals('String: value', $response->getReturnValue());
  462. }
  463. public function testHandleClassStaticMethod()
  464. {
  465. $this->_server->setClass('Zend_XmlRpc_Server_testClass');
  466. $request = new Zend_XmlRpc_Request();
  467. $request->setMethod('test2');
  468. $request->addParam(array('value1', 'value2'));
  469. $response = $this->_server->handle($request);
  470. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  471. $this->assertEquals('value1; value2', $response->getReturnValue());
  472. }
  473. public function testHandleFunction()
  474. {
  475. $this->_server->addFunction('Zend_XmlRpc_Server_testFunction');
  476. $request = new Zend_XmlRpc_Request();
  477. $request->setMethod('Zend_XmlRpc_Server_testFunction');
  478. $request->setParams(array(array('value1'), 'key'));
  479. $response = $this->_server->handle($request);
  480. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  481. $this->assertEquals('key: value1', $response->getReturnValue());
  482. }
  483. public function testMulticallReturnsFaultsWithBadData()
  484. {
  485. // bad method array
  486. $try = array(
  487. 'system.listMethods',
  488. array(
  489. 'name' => 'system.listMethods'
  490. ),
  491. array(
  492. 'methodName' => 'system.listMethods'
  493. ),
  494. array(
  495. 'methodName' => 'system.listMethods',
  496. 'params' => ''
  497. ),
  498. array(
  499. 'methodName' => 'system.multicall',
  500. 'params' => array()
  501. )
  502. );
  503. $returned = $this->_server->multicall($try);
  504. $this->assertTrue(is_array($returned));
  505. $this->assertEquals(5, count($returned));
  506. $response = $returned[0];
  507. $this->assertTrue(is_array($response));
  508. $this->assertTrue(isset($response['faultCode']));
  509. $this->assertEquals(601, $response['faultCode']);
  510. $response = $returned[1];
  511. $this->assertTrue(is_array($response));
  512. $this->assertTrue(isset($response['faultCode']));
  513. $this->assertEquals(602, $response['faultCode']);
  514. $response = $returned[2];
  515. $this->assertTrue(is_array($response));
  516. $this->assertTrue(isset($response['faultCode']));
  517. $this->assertEquals(603, $response['faultCode']);
  518. $response = $returned[3];
  519. $this->assertTrue(is_array($response));
  520. $this->assertTrue(isset($response['faultCode']));
  521. $this->assertEquals(604, $response['faultCode']);
  522. $response = $returned[4];
  523. $this->assertTrue(is_array($response));
  524. $this->assertTrue(isset($response['faultCode']));
  525. $this->assertEquals(605, $response['faultCode']);
  526. }
  527. /**
  528. * @see ZF-2872
  529. */
  530. public function testCanMarshalBase64Requests()
  531. {
  532. $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test');
  533. $data = base64_encode('this is the payload');
  534. $param = array('type' => 'base64', 'value' => $data);
  535. $request = new Zend_XmlRpc_Request('test.base64', array($param));
  536. $response = $this->_server->handle($request);
  537. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  538. $this->assertEquals($data, $response->getReturnValue());
  539. }
  540. /**
  541. * @group ZF-6034
  542. */
  543. public function testPrototypeReturnValueMustReflectDocBlock()
  544. {
  545. $server = new Zend_XmlRpc_Server();
  546. $server->setClass('Zend_XmlRpc_Server_testClass');
  547. $table = $server->getDispatchTable();
  548. $method = $table->getMethod('test1');
  549. foreach ($method->getPrototypes() as $prototype) {
  550. $this->assertNotEquals('void', $prototype->getReturnType(), var_export($prototype, 1));
  551. }
  552. }
  553. public function testCallingUnregisteredMethod()
  554. {
  555. $this->setExpectedException('Zend_XmlRpc_Server_Exception',
  556. 'Unknown instance method called on server: foobarbaz');
  557. $this->_server->foobarbaz();
  558. }
  559. public function testSetPersistenceDoesNothing()
  560. {
  561. $this->assertNull($this->_server->setPersistence('foo'));
  562. $this->assertNull($this->_server->setPersistence('whatever'));
  563. }
  564. public function testPassingInvalidRequestClassThrowsException()
  565. {
  566. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid request class');
  567. $this->_server->setRequest('stdClass');
  568. }
  569. public function testPassingInvalidResponseClassThrowsException()
  570. {
  571. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid response class');
  572. $this->_server->setResponseClass('stdClass');
  573. }
  574. public function testCreatingFaultWithEmptyMessageResultsInUnknownError()
  575. {
  576. $fault = $this->_server->fault('', 123);
  577. $this->assertSame('Unknown Error', $fault->getMessage());
  578. $this->assertSame(123, $fault->getCode());
  579. }
  580. }
  581. /**
  582. * Zend_XmlRpc_Server_testFunction
  583. *
  584. * Function for use with xmlrpc server unit tests
  585. *
  586. * @param array $var1
  587. * @param string $var2
  588. * @return string
  589. */
  590. function Zend_XmlRpc_Server_testFunction($var1, $var2 = 'optional')
  591. {
  592. return $var2 . ': ' . implode(',', (array) $var1);
  593. }
  594. /**
  595. * Zend_XmlRpc_Server_testFunction2
  596. *
  597. * Function for use with xmlrpc server unit tests
  598. *
  599. * @return string
  600. */
  601. function Zend_XmlRpc_Server_testFunction2()
  602. {
  603. return 'function2';
  604. }
  605. class Zend_XmlRpc_Server_testClass
  606. {
  607. private $_value1;
  608. private $_value2;
  609. /**
  610. * Constructor
  611. *
  612. * @return void
  613. */
  614. public function __construct($value1 = null, $value2 = null)
  615. {
  616. $this->_value1 = $value1;
  617. $this->_value2 = $value2;
  618. }
  619. /**
  620. * Test1
  621. *
  622. * Returns 'String: ' . $string
  623. *
  624. * @param string $string
  625. * @return string
  626. */
  627. public function test1($string)
  628. {
  629. return 'String: ' . (string) $string;
  630. }
  631. /**
  632. * Test2
  633. *
  634. * Returns imploded array
  635. *
  636. * @param array $array
  637. * @return string
  638. */
  639. public static function test2($array)
  640. {
  641. return implode('; ', (array) $array);
  642. }
  643. /**
  644. * Test3
  645. *
  646. * Should not be available...
  647. *
  648. * @return void
  649. */
  650. protected function _test3()
  651. {
  652. }
  653. /**
  654. * @param string $arg
  655. * @return struct
  656. */
  657. public function test4($arg)
  658. {
  659. return array('test1' => $this->_value1, 'test2' => $this->_value2, 'arg' => func_get_args());
  660. }
  661. /**
  662. * Test base64 encoding in request and response
  663. *
  664. * @param base64 $data
  665. * @return base64
  666. */
  667. public function base64($data)
  668. {
  669. return $data;
  670. }
  671. }
  672. class Zend_XmlRpc_Server_testResponse extends Zend_XmlRpc_Response
  673. {
  674. }
  675. class Zend_XmlRpc_Server_testRequest extends Zend_XmlRpc_Request
  676. {
  677. }
  678. // Call Zend_XmlRpc_ServerTest::main() if this source file is executed directly.
  679. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ServerTest::main") {
  680. Zend_XmlRpc_ServerTest::main();
  681. }