ServerTest.php 24 KB

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