ServerTest.php 24 KB

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