2
0

ServerTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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. * @group ZF-5635
  347. */
  348. public function testMulticallHandlesFaults()
  349. {
  350. $struct = array(
  351. array(
  352. 'methodName' => 'system.listMethods',
  353. 'params' => array()
  354. ),
  355. array(
  356. 'methodName' => 'undefined',
  357. 'params' => array()
  358. )
  359. );
  360. $request = new Zend_XmlRpc_Request();
  361. $request->setMethod('system.multicall');
  362. $request->addParam($struct);
  363. $response = $this->_server->handle($request);
  364. $this->assertTrue($response instanceof Zend_XmlRpc_Response, $response->__toString() . "\n\n" . $request->__toString());
  365. $returns = $response->getReturnValue();
  366. $this->assertTrue(is_array($returns));
  367. $this->assertEquals(2, count($returns), var_export($returns, 1));
  368. $this->assertTrue(is_array($returns[0]), var_export($returns[0], 1));
  369. $this->assertSame(array(
  370. 'faultCode' => 620, 'faultString' => 'Method "undefined" does not exist'),
  371. $returns[1], var_export($returns[1], 1));
  372. }
  373. /**
  374. * Test get/setEncoding()
  375. */
  376. public function testGetSetEncoding()
  377. {
  378. $this->assertEquals('UTF-8', $this->_server->getEncoding());
  379. $this->_server->setEncoding('ISO-8859-1');
  380. $this->assertEquals('ISO-8859-1', $this->_server->getEncoding());
  381. }
  382. /**
  383. * Test request/response encoding
  384. */
  385. public function testRequestResponseEncoding()
  386. {
  387. $response = $this->_server->handle();
  388. $request = $this->_server->getRequest();
  389. $this->assertEquals('UTF-8', $request->getEncoding());
  390. $this->assertEquals('UTF-8', $response->getEncoding());
  391. }
  392. /**
  393. * Test request/response encoding (alternate encoding)
  394. */
  395. public function testRequestResponseEncoding2()
  396. {
  397. $this->_server->setEncoding('ISO-8859-1');
  398. $response = $this->_server->handle();
  399. $request = $this->_server->getRequest();
  400. $this->assertEquals('ISO-8859-1', $request->getEncoding());
  401. $this->assertEquals('ISO-8859-1', $response->getEncoding());
  402. }
  403. public function testAddFunctionWithExtraArgs()
  404. {
  405. $this->_server->addFunction('Zend_XmlRpc_Server_testFunction', 'test', 'arg1');
  406. $methods = $this->_server->listMethods();
  407. $this->assertContains('test.Zend_XmlRpc_Server_testFunction', $methods);
  408. }
  409. public function testAddFunctionThrowsExceptionWithBadData()
  410. {
  411. $o = new stdClass();
  412. try {
  413. $this->_server->addFunction($o);
  414. $this->fail('addFunction() should not accept objects');
  415. } catch (Zend_XmlRpc_Exception $e) {
  416. // success
  417. }
  418. }
  419. public function testLoadFunctionsThrowsExceptionWithBadData()
  420. {
  421. $o = new stdClass();
  422. try {
  423. $this->_server->loadFunctions($o);
  424. $this->fail('loadFunctions() should not accept objects');
  425. } catch (Zend_XmlRpc_Exception $e) {
  426. // success
  427. }
  428. try {
  429. $this->_server->loadFunctions('foo');
  430. $this->fail('loadFunctions() should not accept primitive values');
  431. } catch (Zend_XmlRpc_Server_Exception $e) {
  432. // success
  433. }
  434. $o = array($o);
  435. try {
  436. $this->_server->loadFunctions($o);
  437. $this->fail('loadFunctions() should not allow non-reflection objects in an array');
  438. } catch (Zend_Server_Exception $e) {
  439. $this->assertSame('Invalid method provided', $e->getMessage());
  440. }
  441. }
  442. public function testLoadFunctionsReadsMethodsFromServerDefinitionObjects()
  443. {
  444. $mockedMethod = $this->getMock('Zend_Server_Method_Definition', array(), array(), '', false,
  445. false);
  446. $mockedDefinition = $this->getMock('Zend_Server_Definition', array(), array(), '', false, false);
  447. $mockedDefinition->expects($this->once())
  448. ->method('getMethods')
  449. ->will($this->returnValue(array('bar' => $mockedMethod)));
  450. $this->_server->loadFunctions($mockedDefinition);
  451. }
  452. public function testSetClassThrowsExceptionWithInvalidClass()
  453. {
  454. try {
  455. $this->_server->setClass('mybogusclass');
  456. $this->fail('setClass() should not allow invalid classes');
  457. } catch (Zend_XmlRpc_Exception $e) {
  458. }
  459. }
  460. public function testSetRequestUsingString()
  461. {
  462. $this->_server->setRequest('Zend_XmlRpc_Server_testRequest');
  463. $req = $this->_server->getRequest();
  464. $this->assertTrue($req instanceof Zend_XmlRpc_Server_testRequest);
  465. }
  466. public function testSetRequestThrowsExceptionOnBadClass()
  467. {
  468. try {
  469. $this->_server->setRequest('Zend_XmlRpc_Server_testRequest2');
  470. $this->fail('Invalid request class should throw exception');
  471. } catch (Zend_XmlRpc_Exception $e) {
  472. // success
  473. }
  474. try {
  475. $this->_server->setRequest($this);
  476. $this->fail('Invalid request object should throw exception');
  477. } catch (Zend_XmlRpc_Exception $e) {
  478. // success
  479. }
  480. }
  481. public function testHandleObjectMethod()
  482. {
  483. $this->_server->setClass('Zend_XmlRpc_Server_testClass');
  484. $request = new Zend_XmlRpc_Request();
  485. $request->setMethod('test1');
  486. $request->addParam('value');
  487. $response = $this->_server->handle($request);
  488. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  489. $this->assertEquals('String: value', $response->getReturnValue());
  490. }
  491. public function testHandleClassStaticMethod()
  492. {
  493. $this->_server->setClass('Zend_XmlRpc_Server_testClass');
  494. $request = new Zend_XmlRpc_Request();
  495. $request->setMethod('test2');
  496. $request->addParam(array('value1', 'value2'));
  497. $response = $this->_server->handle($request);
  498. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  499. $this->assertEquals('value1; value2', $response->getReturnValue());
  500. }
  501. public function testHandleFunction()
  502. {
  503. $this->_server->addFunction('Zend_XmlRpc_Server_testFunction');
  504. $request = new Zend_XmlRpc_Request();
  505. $request->setMethod('Zend_XmlRpc_Server_testFunction');
  506. $request->setParams(array(array('value1'), 'key'));
  507. $response = $this->_server->handle($request);
  508. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  509. $this->assertEquals('key: value1', $response->getReturnValue());
  510. }
  511. public function testMulticallReturnsFaultsWithBadData()
  512. {
  513. // bad method array
  514. $try = array(
  515. 'system.listMethods',
  516. array(
  517. 'name' => 'system.listMethods'
  518. ),
  519. array(
  520. 'methodName' => 'system.listMethods'
  521. ),
  522. array(
  523. 'methodName' => 'system.listMethods',
  524. 'params' => ''
  525. ),
  526. array(
  527. 'methodName' => 'system.multicall',
  528. 'params' => array()
  529. )
  530. );
  531. $returned = $this->_server->multicall($try);
  532. $this->assertTrue(is_array($returned));
  533. $this->assertEquals(5, count($returned));
  534. $response = $returned[0];
  535. $this->assertTrue(is_array($response));
  536. $this->assertTrue(isset($response['faultCode']));
  537. $this->assertEquals(601, $response['faultCode']);
  538. $response = $returned[1];
  539. $this->assertTrue(is_array($response));
  540. $this->assertTrue(isset($response['faultCode']));
  541. $this->assertEquals(602, $response['faultCode']);
  542. $response = $returned[2];
  543. $this->assertTrue(is_array($response));
  544. $this->assertTrue(isset($response['faultCode']));
  545. $this->assertEquals(603, $response['faultCode']);
  546. $response = $returned[3];
  547. $this->assertTrue(is_array($response));
  548. $this->assertTrue(isset($response['faultCode']));
  549. $this->assertEquals(604, $response['faultCode']);
  550. $response = $returned[4];
  551. $this->assertTrue(is_array($response));
  552. $this->assertTrue(isset($response['faultCode']));
  553. $this->assertEquals(605, $response['faultCode']);
  554. }
  555. /**
  556. * @see ZF-2872
  557. */
  558. public function testCanMarshalBase64Requests()
  559. {
  560. $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test');
  561. $data = base64_encode('this is the payload');
  562. $param = array('type' => 'base64', 'value' => $data);
  563. $request = new Zend_XmlRpc_Request('test.base64', array($param));
  564. $response = $this->_server->handle($request);
  565. $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
  566. $this->assertEquals($data, $response->getReturnValue());
  567. }
  568. /**
  569. * @group ZF-6034
  570. */
  571. public function testPrototypeReturnValueMustReflectDocBlock()
  572. {
  573. $server = new Zend_XmlRpc_Server();
  574. $server->setClass('Zend_XmlRpc_Server_testClass');
  575. $table = $server->getDispatchTable();
  576. $method = $table->getMethod('test1');
  577. foreach ($method->getPrototypes() as $prototype) {
  578. $this->assertNotEquals('void', $prototype->getReturnType(), var_export($prototype, 1));
  579. }
  580. }
  581. public function testCallingUnregisteredMethod()
  582. {
  583. $this->setExpectedException('Zend_XmlRpc_Server_Exception',
  584. 'Unknown instance method called on server: foobarbaz');
  585. $this->_server->foobarbaz();
  586. }
  587. public function testSetPersistenceDoesNothing()
  588. {
  589. $this->assertNull($this->_server->setPersistence('foo'));
  590. $this->assertNull($this->_server->setPersistence('whatever'));
  591. }
  592. public function testPassingInvalidRequestClassThrowsException()
  593. {
  594. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid request class');
  595. $this->_server->setRequest('stdClass');
  596. }
  597. public function testPassingInvalidResponseClassThrowsException()
  598. {
  599. $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid response class');
  600. $this->_server->setResponseClass('stdClass');
  601. }
  602. public function testCreatingFaultWithEmptyMessageResultsInUnknownError()
  603. {
  604. $fault = $this->_server->fault('', 123);
  605. $this->assertSame('Unknown Error', $fault->getMessage());
  606. $this->assertSame(123, $fault->getCode());
  607. }
  608. }
  609. /**
  610. * Zend_XmlRpc_Server_testFunction
  611. *
  612. * Function for use with xmlrpc server unit tests
  613. *
  614. * @param array $var1
  615. * @param string $var2
  616. * @return string
  617. */
  618. function Zend_XmlRpc_Server_testFunction($var1, $var2 = 'optional')
  619. {
  620. return $var2 . ': ' . implode(',', (array) $var1);
  621. }
  622. /**
  623. * Zend_XmlRpc_Server_testFunction2
  624. *
  625. * Function for use with xmlrpc server unit tests
  626. *
  627. * @return string
  628. */
  629. function Zend_XmlRpc_Server_testFunction2()
  630. {
  631. return 'function2';
  632. }
  633. class Zend_XmlRpc_Server_testClass
  634. {
  635. private $_value1;
  636. private $_value2;
  637. /**
  638. * Constructor
  639. *
  640. * @return void
  641. */
  642. public function __construct($value1 = null, $value2 = null)
  643. {
  644. $this->_value1 = $value1;
  645. $this->_value2 = $value2;
  646. }
  647. /**
  648. * Test1
  649. *
  650. * Returns 'String: ' . $string
  651. *
  652. * @param string $string
  653. * @return string
  654. */
  655. public function test1($string)
  656. {
  657. return 'String: ' . (string) $string;
  658. }
  659. /**
  660. * Test2
  661. *
  662. * Returns imploded array
  663. *
  664. * @param array $array
  665. * @return string
  666. */
  667. public static function test2($array)
  668. {
  669. return implode('; ', (array) $array);
  670. }
  671. /**
  672. * Test3
  673. *
  674. * Should not be available...
  675. *
  676. * @return void
  677. */
  678. protected function _test3()
  679. {
  680. }
  681. /**
  682. * @param string $arg
  683. * @return struct
  684. */
  685. public function test4($arg)
  686. {
  687. return array('test1' => $this->_value1, 'test2' => $this->_value2, 'arg' => func_get_args());
  688. }
  689. /**
  690. * Test base64 encoding in request and response
  691. *
  692. * @param base64 $data
  693. * @return base64
  694. */
  695. public function base64($data)
  696. {
  697. return $data;
  698. }
  699. }
  700. class Zend_XmlRpc_Server_testResponse extends Zend_XmlRpc_Response
  701. {
  702. }
  703. class Zend_XmlRpc_Server_testRequest extends Zend_XmlRpc_Request
  704. {
  705. }
  706. // Call Zend_XmlRpc_ServerTest::main() if this source file is executed directly.
  707. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ServerTest::main") {
  708. Zend_XmlRpc_ServerTest::main();
  709. }