PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Soap/ServerTest.php

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