PageRenderTime 74ms CodeModel.GetById 44ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Soap/ServerTest.php

https://bitbucket.org/ksekar/campus
PHP | 1111 lines | 816 code | 165 blank | 130 comment | 14 complexity | f1d557113cdcfbe8ff69164f6d8742dc MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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_Soap
  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: ServerTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /** Zend_Soap_Server */
  23. require_once 'Zend/Soap/Server.php';
  24. require_once 'Zend/Soap/Server/Exception.php';
  25. require_once "Zend/Config.php";
  26. /**
  27. * Zend_Soap_Server
  28. *
  29. * @category Zend
  30. * @package Zend_Soap
  31. * @subpackage UnitTests
  32. * @uses Zend_Server_Interface
  33. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Soap
  36. * @group Zend_Soap_Server
  37. */
  38. class Zend_Soap_ServerTest extends PHPUnit_Framework_TestCase
  39. {
  40. public function setUp()
  41. {
  42. if (!extension_loaded('soap')) {
  43. $this->markTestSkipped('SOAP Extension is not loaded');
  44. }
  45. }
  46. public function testSetOptions()
  47. {
  48. $server = new Zend_Soap_Server();
  49. $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2));
  50. $options = array('soap_version' => SOAP_1_1,
  51. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  52. 'classmap' => array('TestData1' => 'Zend_Soap_Server_TestData1',
  53. 'TestData2' => 'Zend_Soap_Server_TestData2',),
  54. 'encoding' => 'ISO-8859-1',
  55. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  56. );
  57. $server->setOptions($options);
  58. $this->assertTrue($server->getOptions() == $options);
  59. }
  60. public function testSetOptionsViaSecondConstructorArgument()
  61. {
  62. $options = array(
  63. 'soap_version' => SOAP_1_1,
  64. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  65. 'classmap' => array(
  66. 'TestData1' => 'Zend_Soap_Server_TestData1',
  67. 'TestData2' => 'Zend_Soap_Server_TestData2',
  68. ),
  69. 'encoding' => 'ISO-8859-1',
  70. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  71. );
  72. $server = new Zend_Soap_Server(null, $options);
  73. $this->assertTrue($server->getOptions() == $options);
  74. }
  75. /**
  76. * @group ZF-9816
  77. */
  78. public function testSetOptionsWithFeaturesOption()
  79. {
  80. $server = new Zend_Soap_Server(null, array(
  81. 'features' => SOAP_SINGLE_ELEMENT_ARRAYS
  82. ));
  83. $this->assertEquals(
  84. SOAP_SINGLE_ELEMENT_ARRAYS,
  85. $server->getSoapFeatures()
  86. );
  87. }
  88. public function testSetWsdlViaOptionsArrayIsPossible()
  89. {
  90. $server = new Zend_Soap_Server();
  91. $server->setOptions(array('wsdl' => 'http://www.example.com/test.wsdl'));
  92. $this->assertEquals('http://www.example.com/test.wsdl', $server->getWsdl());
  93. }
  94. public function testGetOptions()
  95. {
  96. $server = new Zend_Soap_Server();
  97. $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2));
  98. $options = array('soap_version' => SOAP_1_1,
  99. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  100. );
  101. $server->setOptions($options);
  102. $this->assertTrue($server->getOptions() == $options);
  103. }
  104. public function testEncoding()
  105. {
  106. $server = new Zend_Soap_Server();
  107. $this->assertNull($server->getEncoding());
  108. $server->setEncoding('ISO-8859-1');
  109. $this->assertEquals('ISO-8859-1', $server->getEncoding());
  110. try {
  111. $server->setEncoding(array('UTF-8'));
  112. $this->fail('Non-string encoding values should fail');
  113. } catch (Exception $e) {
  114. // success
  115. }
  116. }
  117. public function testSoapVersion()
  118. {
  119. $server = new Zend_Soap_Server();
  120. $this->assertEquals(SOAP_1_2, $server->getSoapVersion());
  121. $server->setSoapVersion(SOAP_1_1);
  122. $this->assertEquals(SOAP_1_1, $server->getSoapVersion());
  123. try {
  124. $server->setSoapVersion('bogus');
  125. $this->fail('Invalid soap versions should fail');
  126. } catch (Exception $e) {
  127. // success
  128. }
  129. }
  130. public function testValidateUrn()
  131. {
  132. $server = new Zend_Soap_Server();
  133. try {
  134. $server->validateUrn('bogosity');
  135. $this->fail('URNs without schemes should fail');
  136. } catch (Exception $e) {
  137. // success
  138. }
  139. $this->assertTrue($server->validateUrn('http://framework.zend.com/'));
  140. $this->assertTrue($server->validateUrn('urn:soapHandler/GetOpt'));
  141. }
  142. public function testSetActor()
  143. {
  144. $server = new Zend_Soap_Server();
  145. $this->assertNull($server->getActor());
  146. $server->setActor('http://framework.zend.com/');
  147. $this->assertEquals('http://framework.zend.com/', $server->getActor());
  148. try {
  149. $server->setActor('bogus');
  150. $this->fail('Invalid actor should fail');
  151. } catch (Exception $e) {
  152. // success
  153. }
  154. }
  155. public function testGetActor()
  156. {
  157. $server = new Zend_Soap_Server();
  158. $this->assertNull($server->getActor());
  159. $server->setActor('http://framework.zend.com/');
  160. $this->assertEquals('http://framework.zend.com/', $server->getActor());
  161. }
  162. public function testSetUri()
  163. {
  164. $server = new Zend_Soap_Server();
  165. $this->assertNull($server->getUri());
  166. $server->setUri('http://framework.zend.com/');
  167. $this->assertEquals('http://framework.zend.com/', $server->getUri());
  168. try {
  169. $server->setUri('bogus');
  170. $this->fail('Invalid URI should fail');
  171. } catch (Exception $e) {
  172. // success
  173. }
  174. }
  175. public function testGetUri()
  176. {
  177. $server = new Zend_Soap_Server();
  178. $this->assertNull($server->getUri());
  179. $server->setUri('http://framework.zend.com/');
  180. $this->assertEquals('http://framework.zend.com/', $server->getUri());
  181. }
  182. public function testSetClassmap()
  183. {
  184. $server = new Zend_Soap_Server();
  185. $classmap = array('TestData1' => 'Zend_Soap_Server_TestData1',
  186. 'TestData2' => 'Zend_Soap_Server_TestData2');
  187. $this->assertNull($server->getClassmap());
  188. $server->setClassmap($classmap);
  189. $this->assertTrue($classmap == $server->getClassmap());
  190. try {
  191. $server->setClassmap('bogus');
  192. $this->fail('Classmap which is not an array should fail');
  193. } catch (Exception $e) {
  194. // success
  195. }
  196. try {
  197. $server->setClassmap(array('soapTypeName', 'bogusClassName'));
  198. $this->fail('Invalid class within classmap should fail');
  199. } catch (Exception $e) {
  200. // success
  201. }
  202. }
  203. public function testGetClassmap()
  204. {
  205. $server = new Zend_Soap_Server();
  206. $classmap = array('TestData1' => 'Zend_Soap_Server_TestData1',
  207. 'TestData2' => 'Zend_Soap_Server_TestData2');
  208. $this->assertNull($server->getClassmap());
  209. $server->setClassmap($classmap);
  210. $this->assertTrue($classmap == $server->getClassmap());
  211. }
  212. public function testSetWsdl()
  213. {
  214. $server = new Zend_Soap_Server();
  215. $this->assertNull($server->getWsdl());
  216. $server->setWsdl(dirname(__FILE__).'/_files/wsdl_example.wsdl');
  217. $this->assertEquals(dirname(__FILE__).'/_files/wsdl_example.wsdl', $server->getWsdl());
  218. try {
  219. $server->setWsdl(dirname(__FILE__).'/_files/bogus.wsdl');
  220. $this->fail('Invalid WSDL URI or PATH should fail');
  221. } catch (Exception $e) {
  222. // success
  223. }
  224. }
  225. public function testGetWsdl()
  226. {
  227. $server = new Zend_Soap_Server();
  228. $this->assertNull($server->getWsdl());
  229. $server->setWsdl(dirname(__FILE__).'/_files/wsdl_example.wsdl');
  230. $this->assertEquals(dirname(__FILE__).'/_files/wsdl_example.wsdl', $server->getWsdl());
  231. }
  232. public function testAddFunction()
  233. {
  234. $server = new Zend_Soap_Server();
  235. // Correct function should pass
  236. $server->addFunction('Zend_Soap_Server_TestFunc1');
  237. // Array of correct functions should pass
  238. $functions = array('Zend_Soap_Server_TestFunc2',
  239. 'Zend_Soap_Server_TestFunc3',
  240. 'Zend_Soap_Server_TestFunc4');
  241. $server->addFunction($functions);
  242. $this->assertEquals(
  243. array_merge(array('Zend_Soap_Server_TestFunc1'), $functions),
  244. $server->getFunctions()
  245. );
  246. }
  247. public function testAddBogusFunctionAsInteger()
  248. {
  249. $server = new Zend_Soap_Server();
  250. try {
  251. $server->addFunction(126);
  252. $this->fail('Invalid value should fail');
  253. } catch (Zend_Soap_Server_Exception $e) {
  254. // success
  255. }
  256. }
  257. public function testAddBogusFunctionsAsString()
  258. {
  259. $server = new Zend_Soap_Server();
  260. try {
  261. $server->addFunction('bogus_function');
  262. $this->fail('Invalid function should fail.');
  263. } catch (Zend_Soap_Server_Exception $e) {
  264. // success
  265. }
  266. }
  267. public function testAddBogusFunctionsAsArray()
  268. {
  269. $server = new Zend_Soap_Server();
  270. try {
  271. $functions = array('Zend_Soap_Server_TestFunc5',
  272. 'bogus_function',
  273. 'Zend_Soap_Server_TestFunc6');
  274. $server->addFunction($functions);
  275. $this->fail('Invalid function within a set of functions should fail');
  276. } catch (Zend_Soap_Server_Exception $e) {
  277. // success
  278. }
  279. }
  280. public function testAddAllFunctionsSoapConstant()
  281. {
  282. $server = new Zend_Soap_Server();
  283. // SOAP_FUNCTIONS_ALL as a value should pass
  284. $server->addFunction(SOAP_FUNCTIONS_ALL);
  285. $server->addFunction('substr');
  286. $this->assertEquals(array(SOAP_FUNCTIONS_ALL), $server->getFunctions());
  287. }
  288. public function testSetClass()
  289. {
  290. $server = new Zend_Soap_Server();
  291. // Correct class name should pass
  292. try {
  293. $server->setClass('Zend_Soap_Server_TestClass');
  294. } catch(Exception $e) {
  295. $this->fail("Setting a correct class name should not fail setClass()");
  296. }
  297. }
  298. public function testSetClassTwiceThrowsException()
  299. {
  300. $server = new Zend_Soap_Server();
  301. // Correct class name should pass
  302. try {
  303. $server->setClass('Zend_Soap_Server_TestClass');
  304. $server->setClass('Zend_Soap_Server_TestClass');
  305. $this->fail();
  306. } catch(Zend_Soap_Server_Exception $e) {
  307. $this->assertEquals('A class has already been registered with this soap server instance', $e->getMessage());
  308. }
  309. }
  310. public function testSetClassWithArguments()
  311. {
  312. $server = new Zend_Soap_Server();
  313. // Correct class name should pass
  314. try {
  315. $server->setClass('Zend_Soap_Server_TestClass', 1, 2, 3, 4);
  316. } catch(Exception $e) {
  317. $this->fail("Setting a correct class name should not fail setClass()");
  318. }
  319. }
  320. public function testSetBogusClassWithIntegerName()
  321. {
  322. $server = new Zend_Soap_Server();
  323. try {
  324. $server->setClass(465);
  325. $this->fail('Non-string value should fail');
  326. } catch (Exception $e) {
  327. // success
  328. }
  329. }
  330. public function testSetBogusClassWithUnknownClassName()
  331. {
  332. $server = new Zend_Soap_Server();
  333. try {
  334. $server->setClass('Zend_Soap_Server_Test_BogusClass');
  335. $this->fail('Invalid class should fail');
  336. } catch (Exception $e) {
  337. // success
  338. }
  339. }
  340. /**
  341. * @group ZF-4366
  342. */
  343. public function testSetObject()
  344. {
  345. $server = new Zend_Soap_Server();
  346. try {
  347. $server->setObject(465);
  348. $this->fail('Non-object value should fail');
  349. } catch (Exception $e) {
  350. // success
  351. }
  352. try {
  353. $int = 1;
  354. $server->setObject($int);
  355. $this->fail('Invalid argument should fail');
  356. } catch (Exception $e) {
  357. // success
  358. }
  359. // Correct class name should pass
  360. $server->setObject(new Zend_Soap_Server_TestClass());
  361. try {
  362. $server->setObject(new Zend_Soap_Server_TestClass());
  363. $this->fail('setClass() should pass only once');
  364. } catch (Exception $e) {
  365. // success
  366. }
  367. }
  368. public function testGetFunctions()
  369. {
  370. $server = new Zend_Soap_Server();
  371. $server->addFunction('Zend_Soap_Server_TestFunc1');
  372. $functions = array('Zend_Soap_Server_TestFunc2',
  373. 'Zend_Soap_Server_TestFunc3',
  374. 'Zend_Soap_Server_TestFunc4');
  375. $server->addFunction($functions);
  376. $functions = array('Zend_Soap_Server_TestFunc3',
  377. 'Zend_Soap_Server_TestFunc5',
  378. 'Zend_Soap_Server_TestFunc6');
  379. $server->addFunction($functions);
  380. $allAddedFunctions = array(
  381. 'Zend_Soap_Server_TestFunc1',
  382. 'Zend_Soap_Server_TestFunc2',
  383. 'Zend_Soap_Server_TestFunc3',
  384. 'Zend_Soap_Server_TestFunc4',
  385. 'Zend_Soap_Server_TestFunc5',
  386. 'Zend_Soap_Server_TestFunc6'
  387. );
  388. $this->assertTrue($server->getFunctions() == $allAddedFunctions);
  389. }
  390. public function testGetFunctionsWithClassAttached()
  391. {
  392. $server = new Zend_Soap_Server();
  393. $server->setClass('Zend_Soap_Server_TestClass');
  394. $this->assertEquals(
  395. array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'),
  396. $server->getFunctions()
  397. );
  398. }
  399. public function testGetFunctionsWithObjectAttached()
  400. {
  401. $server = new Zend_Soap_Server();
  402. $server->setObject(new Zend_Soap_Server_TestClass());
  403. $this->assertEquals(
  404. array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'),
  405. $server->getFunctions()
  406. );
  407. }
  408. public function testSetPersistence()
  409. {
  410. $server = new Zend_Soap_Server();
  411. $this->assertNull($server->getPersistence());
  412. $server->setPersistence(SOAP_PERSISTENCE_SESSION);
  413. $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence());
  414. try {
  415. $server->setSoapVersion('bogus');
  416. $this->fail('Invalid soap versions should fail');
  417. } catch (Exception $e) {
  418. // success
  419. }
  420. $server->setPersistence(SOAP_PERSISTENCE_REQUEST);
  421. $this->assertEquals(SOAP_PERSISTENCE_REQUEST, $server->getPersistence());
  422. }
  423. public function testSetUnknownPersistenceStateThrowsException()
  424. {
  425. $server = new Zend_Soap_Server();
  426. try {
  427. $server->setPersistence('bogus');
  428. $this->fail();
  429. } catch(Zend_Soap_Server_Exception $e) {
  430. }
  431. }
  432. public function testGetPersistence()
  433. {
  434. $server = new Zend_Soap_Server();
  435. $this->assertNull($server->getPersistence());
  436. $server->setPersistence(SOAP_PERSISTENCE_SESSION);
  437. $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence());
  438. }
  439. public function testGetLastRequest()
  440. {
  441. if (headers_sent()) {
  442. $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test');
  443. return;
  444. }
  445. $server = new Zend_Soap_Server();
  446. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  447. $server->setReturnResponse(true);
  448. $server->setClass('Zend_Soap_Server_TestClass');
  449. $request =
  450. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  451. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  452. . 'xmlns:ns1="http://framework.zend.com" '
  453. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  454. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  455. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  456. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  457. . '<SOAP-ENV:Body>'
  458. . '<ns1:testFunc2>'
  459. . '<param0 xsi:type="xsd:string">World</param0>'
  460. . '</ns1:testFunc2>'
  461. . '</SOAP-ENV:Body>'
  462. . '</SOAP-ENV:Envelope>' . "\n";
  463. $response = $server->handle($request);
  464. $this->assertEquals($request, $server->getLastRequest());
  465. }
  466. public function testSetReturnResponse()
  467. {
  468. $server = new Zend_Soap_Server();
  469. $this->assertFalse($server->getReturnResponse());
  470. $server->setReturnResponse(true);
  471. $this->assertTrue($server->getReturnResponse());
  472. $server->setReturnResponse(false);
  473. $this->assertFalse($server->getReturnResponse());
  474. }
  475. public function testGetReturnResponse()
  476. {
  477. $server = new Zend_Soap_Server();
  478. $this->assertFalse($server->getReturnResponse());
  479. $server->setReturnResponse(true);
  480. $this->assertTrue($server->getReturnResponse());
  481. }
  482. public function testGetLastResponse()
  483. {
  484. if (headers_sent()) {
  485. $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test');
  486. return;
  487. }
  488. $server = new Zend_Soap_Server();
  489. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  490. $server->setReturnResponse(true);
  491. $server->setClass('Zend_Soap_Server_TestClass');
  492. $request =
  493. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  494. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  495. . 'xmlns:ns1="http://framework.zend.com" '
  496. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  497. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  498. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  499. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  500. . '<SOAP-ENV:Body>'
  501. . '<ns1:testFunc2>'
  502. . '<param0 xsi:type="xsd:string">World</param0>'
  503. . '</ns1:testFunc2>'
  504. . '</SOAP-ENV:Body>'
  505. . '</SOAP-ENV:Envelope>' . "\n";
  506. $expectedResponse =
  507. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  508. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  509. . 'xmlns:ns1="http://framework.zend.com" '
  510. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  511. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  512. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  513. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  514. . '<SOAP-ENV:Body>'
  515. . '<ns1:testFunc2Response>'
  516. . '<return xsi:type="xsd:string">Hello World!</return>'
  517. . '</ns1:testFunc2Response>'
  518. . '</SOAP-ENV:Body>'
  519. . '</SOAP-ENV:Envelope>' . "\n";
  520. $server->handle($request);
  521. $this->assertEquals($expectedResponse, $server->getLastResponse());
  522. }
  523. public function testHandle()
  524. {
  525. if (headers_sent()) {
  526. $this->markTestSkipped('Cannot run testHandle() when headers have already been sent; enable output buffering to run this test');
  527. return;
  528. }
  529. $server = new Zend_Soap_Server();
  530. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  531. $server->setClass('Zend_Soap_Server_TestClass');
  532. $localClient = new Zend_Soap_Server_TestLocalSoapClient($server,
  533. null,
  534. array('location'=>'test://',
  535. 'uri'=>'http://framework.zend.com'));
  536. // Local SOAP client call automatically invokes handle method of the provided SOAP server
  537. $this->assertEquals('Hello World!', $localClient->testFunc2('World'));
  538. $request =
  539. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  540. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  541. . 'xmlns:ns1="http://framework.zend.com" '
  542. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  543. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  544. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  545. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  546. . '<SOAP-ENV:Body>'
  547. . '<ns1:testFunc2>'
  548. . '<param0 xsi:type="xsd:string">World</param0>'
  549. . '</ns1:testFunc2>'
  550. . '</SOAP-ENV:Body>'
  551. . '</SOAP-ENV:Envelope>' . "\n";
  552. $expectedResponse =
  553. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  554. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  555. . 'xmlns:ns1="http://framework.zend.com" '
  556. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  557. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  558. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  559. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  560. . '<SOAP-ENV:Body>'
  561. . '<ns1:testFunc2Response>'
  562. . '<return xsi:type="xsd:string">Hello World!</return>'
  563. . '</ns1:testFunc2Response>'
  564. . '</SOAP-ENV:Body>'
  565. . '</SOAP-ENV:Envelope>' . "\n";
  566. $server1 = new Zend_Soap_Server();
  567. $server1->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  568. $server1->setClass('Zend_Soap_Server_TestClass');
  569. $server1->setReturnResponse(true);
  570. $this->assertEquals($expectedResponse, $server1->handle($request));
  571. }
  572. /**
  573. * @todo Implement testRegisterFaultException().
  574. */
  575. public function testRegisterFaultException()
  576. {
  577. $server = new Zend_Soap_Server();
  578. $server->registerFaultException("Zend_Soap_Server_Exception");
  579. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  580. $this->assertEquals(array(
  581. 'Zend_Soap_Server_Exception',
  582. 'OutOfBoundsException',
  583. 'BogusException',
  584. ), $server->getFaultExceptions());
  585. }
  586. /**
  587. * @todo Implement testDeregisterFaultException().
  588. */
  589. public function testDeregisterFaultException()
  590. {
  591. $server = new Zend_Soap_Server();
  592. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  593. $ret = $server->deregisterFaultException("BogusException");
  594. $this->assertTrue($ret);
  595. $this->assertEquals(array(
  596. 'OutOfBoundsException',
  597. ), $server->getFaultExceptions());
  598. $ret = $server->deregisterFaultException("NonRegisteredException");
  599. $this->assertFalse($ret);
  600. }
  601. /**
  602. * @todo Implement testGetFaultExceptions().
  603. */
  604. public function testGetFaultExceptions()
  605. {
  606. $server = new Zend_Soap_Server();
  607. $this->assertEquals(array(), $server->getFaultExceptions());
  608. $server->registerFaultException("Exception");
  609. $this->assertEquals(array("Exception"), $server->getFaultExceptions());
  610. }
  611. public function testFaultWithTextMessage()
  612. {
  613. $server = new Zend_Soap_Server();
  614. $fault = $server->fault("Faultmessage!");
  615. $this->assertTrue($fault instanceof SOAPFault);
  616. $this->assertContains("Faultmessage!", $fault->getMessage());
  617. }
  618. public function testFaultWithUnregisteredException()
  619. {
  620. $server = new Zend_Soap_Server();
  621. $fault = $server->fault(new Exception("MyException"));
  622. $this->assertTrue($fault instanceof SOAPFault);
  623. $this->assertContains("Unknown error", $fault->getMessage());
  624. $this->assertNotContains("MyException", $fault->getMessage());
  625. }
  626. public function testFaultWithRegisteredException()
  627. {
  628. $server = new Zend_Soap_Server();
  629. $server->registerFaultException("Exception");
  630. $fault = $server->fault(new Exception("MyException"));
  631. $this->assertTrue($fault instanceof SOAPFault);
  632. $this->assertNotContains("Unknown error", $fault->getMessage());
  633. $this->assertContains("MyException", $fault->getMessage());
  634. }
  635. public function testFautlWithBogusInput()
  636. {
  637. $server = new Zend_Soap_Server();
  638. $fault = $server->fault(array("Here", "There", "Bogus"));
  639. $this->assertContains("Unknown error", $fault->getMessage());
  640. }
  641. /**
  642. * @group ZF-3958
  643. */
  644. public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault()
  645. {
  646. $server = new Zend_Soap_Server();
  647. $fault = $server->fault("Faultmessage!", 5000);
  648. $this->assertTrue($fault instanceof SOAPFault);
  649. }
  650. /**
  651. * @todo Implement testHandlePhpErrors().
  652. */
  653. public function testHandlePhpErrors()
  654. {
  655. $server = new Zend_Soap_Server();
  656. // Remove the following line when you implement this test.
  657. $this->markTestIncomplete(
  658. "This test has not been implemented yet."
  659. );
  660. }
  661. public function testLoadFunctionsIsNotImplemented()
  662. {
  663. $server = new Zend_Soap_Server();
  664. try {
  665. $server->loadFunctions("bogus");
  666. $this->fail();
  667. } catch(Zend_Soap_Server_Exception $e) {
  668. }
  669. }
  670. public function testErrorHandlingOfSoapServerChangesToThrowingSoapFaultWhenInHandleMode()
  671. {
  672. if (headers_sent()) {
  673. $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test');
  674. return;
  675. }
  676. $server = new Zend_Soap_Server();
  677. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  678. $server->setReturnResponse(true);
  679. // Requesting Method with enforced parameter without it.
  680. $request =
  681. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  682. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  683. . 'xmlns:ns1="http://framework.zend.com" '
  684. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  685. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  686. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  687. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  688. . '<SOAP-ENV:Body>'
  689. . '<ns1:testFunc5 />'
  690. . '</SOAP-ENV:Body>'
  691. . '</SOAP-ENV:Envelope>' . "\n";
  692. $server->setClass('Zend_Soap_Server_TestClass');
  693. $response = $server->handle($request);
  694. $this->assertContains(
  695. '<SOAP-ENV:Fault><faultcode>Receiver</faultcode><faultstring>Test Message</faultstring></SOAP-ENV:Fault>',
  696. $response
  697. );
  698. }
  699. /**
  700. * @group ZF-5597
  701. */
  702. public function testServerAcceptsZendConfigObject()
  703. {
  704. $options = array('soap_version' => SOAP_1_1,
  705. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  706. 'classmap' => array('TestData1' => 'Zend_Soap_Server_TestData1',
  707. 'TestData2' => 'Zend_Soap_Server_TestData2',),
  708. 'encoding' => 'ISO-8859-1',
  709. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  710. );
  711. $config = new Zend_Config($options);
  712. $server = new Zend_Soap_Server();
  713. $server->setOptions($config);
  714. $this->assertEquals($options, $server->getOptions());
  715. }
  716. /**
  717. * @group ZF-5300
  718. */
  719. public function testSetAndGetFeatures()
  720. {
  721. $server = new Zend_Soap_Server();
  722. $this->assertNull($server->getSoapFeatures());
  723. $server->setSoapFeatures(100);
  724. $this->assertEquals(100, $server->getSoapFeatures());
  725. $options = $server->getOptions();
  726. $this->assertTrue(isset($options['features']));
  727. $this->assertEquals(100, $options['features']);
  728. }
  729. /**
  730. * @group ZF-5300
  731. */
  732. public function testSetAndGetWsdlCache()
  733. {
  734. $server = new Zend_Soap_Server();
  735. $this->assertNull($server->getWsdlCache());
  736. $server->setWsdlCache(100);
  737. $this->assertEquals(100, $server->getWsdlCache());
  738. $options = $server->getOptions();
  739. $this->assertTrue(isset($options['cache_wsdl']));
  740. $this->assertEquals(100, $options['cache_wsdl']);
  741. }
  742. /**
  743. * @group ZF-11411
  744. */
  745. public function testHandleUsesProperRequestParameter()
  746. {
  747. $server = new Zend_Soap_MockServer();
  748. $r = $server->handle(new DomDocument('1.0', 'UTF-8'));
  749. $this->assertTrue(is_string($server->mockSoapServer->handle[0]));
  750. }
  751. }
  752. if (extension_loaded('soap')) {
  753. /** Local SOAP client */
  754. class Zend_Soap_Server_TestLocalSoapClient extends SoapClient
  755. {
  756. /**
  757. * Server object
  758. *
  759. * @var Zend_Soap_Server
  760. */
  761. public $server;
  762. /**
  763. * Local client constructor
  764. *
  765. * @param Zend_Soap_Server $server
  766. * @param string $wsdl
  767. * @param array $options
  768. */
  769. function __construct(Zend_Soap_Server $server, $wsdl, $options)
  770. {
  771. $this->server = $server;
  772. parent::__construct($wsdl, $options);
  773. }
  774. function __doRequest($request, $location, $action, $version, $one_way = 0)
  775. {
  776. ob_start();
  777. $this->server->handle($request);
  778. $response = ob_get_clean();
  779. return $response;
  780. }
  781. }
  782. }
  783. class MockSoapServer {
  784. public $handle = null;
  785. public function handle()
  786. {
  787. $this->handle = func_get_args();
  788. }
  789. public function __call($name, $args) {}
  790. }
  791. class Zend_Soap_MockServer extends Zend_Soap_Server {
  792. public $mockSoapServer = null;
  793. protected function _getSoap() {
  794. $this->mockSoapServer = new MockSoapServer();
  795. return $this->mockSoapServer;
  796. }
  797. }
  798. /** Test Class */
  799. class Zend_Soap_Server_TestClass {
  800. /**
  801. * Test Function 1
  802. *
  803. * @return string
  804. */
  805. function testFunc1()
  806. {
  807. return "Hello World";
  808. }
  809. /**
  810. * Test Function 2
  811. *
  812. * @param string $who Some Arg
  813. * @return string
  814. */
  815. function testFunc2($who)
  816. {
  817. return "Hello $who!";
  818. }
  819. /**
  820. * Test Function 3
  821. *
  822. * @param string $who Some Arg
  823. * @param int $when Some
  824. * @return string
  825. */
  826. function testFunc3($who, $when)
  827. {
  828. return "Hello $who, How are you $when";
  829. }
  830. /**
  831. * Test Function 4
  832. *
  833. * @return string
  834. */
  835. static function testFunc4()
  836. {
  837. return "I'm Static!";
  838. }
  839. /**
  840. * Test Function 5 raises a user error
  841. *
  842. * @return void
  843. */
  844. function testFunc5()
  845. {
  846. trigger_error("Test Message", E_USER_ERROR);
  847. }
  848. }
  849. /** Test class 2 */
  850. class Zend_Soap_Server_TestData1 {
  851. /**
  852. * Property1
  853. *
  854. * @var string
  855. */
  856. public $property1;
  857. /**
  858. * Property2
  859. *
  860. * @var float
  861. */
  862. public $property2;
  863. }
  864. /** Test class 2 */
  865. class Zend_Soap_Server_TestData2 {
  866. /**
  867. * Property1
  868. *
  869. * @var integer
  870. */
  871. public $property1;
  872. /**
  873. * Property1
  874. *
  875. * @var float
  876. */
  877. public $property2;
  878. }
  879. /* Test Functions */
  880. /**
  881. * Test Function
  882. *
  883. * @param string $arg
  884. * @return string
  885. */
  886. function Zend_Soap_Server_TestFunc1($who)
  887. {
  888. return "Hello $who";
  889. }
  890. /**
  891. * Test Function 2
  892. */
  893. function Zend_Soap_Server_TestFunc2()
  894. {
  895. return "Hello World";
  896. }
  897. /**
  898. * Return false
  899. *
  900. * @return bool
  901. */
  902. function Zend_Soap_Server_TestFunc3()
  903. {
  904. return false;
  905. }
  906. /**
  907. * Return true
  908. *
  909. * @return bool
  910. */
  911. function Zend_Soap_Server_TestFunc4()
  912. {
  913. return true;
  914. }
  915. /**
  916. * Return integer
  917. *
  918. * @return int
  919. */
  920. function Zend_Soap_Server_TestFunc5()
  921. {
  922. return 123;
  923. }
  924. /**
  925. * Return string
  926. *
  927. * @return string
  928. */
  929. function Zend_Soap_Server_TestFunc6()
  930. {
  931. return "string";
  932. }