ServerTest.php 24 KB

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