PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/Zend/Soap/ServerTest.php

http://github.com/zendframework/zf2
PHP | 877 lines | 622 code | 164 blank | 91 comment | 14 complexity | ea1b9406dac96b1c35f03ff7a172cb15 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. */
  21. /**
  22. * @namespace
  23. */
  24. namespace ZendTest\Soap;
  25. require_once __DIR__ . '/TestAsset/commontypes.php';
  26. use Zend\Soap\Server,
  27. Zend\Soap\ServerException;
  28. /**
  29. * Zend_Soap_Server
  30. *
  31. * @category Zend
  32. * @package Zend_Soap
  33. * @subpackage UnitTests
  34. * @uses Zend_Server_Interface
  35. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Soap
  38. * @group Zend_Soap_Server
  39. */
  40. class ServerTest extends \PHPUnit_Framework_TestCase
  41. {
  42. public function setUp()
  43. {
  44. if (!extension_loaded('soap')) {
  45. $this->markTestSkipped('SOAP Extension is not loaded');
  46. }
  47. }
  48. public function testSetOptions()
  49. {
  50. $server = new Server();
  51. $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2));
  52. $options = array('soap_version' => SOAP_1_1,
  53. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  54. 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1',
  55. 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',),
  56. 'encoding' => 'ISO-8859-1',
  57. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  58. );
  59. $server->setOptions($options);
  60. $this->assertTrue($server->getOptions() == $options);
  61. }
  62. public function testSetOptionsViaSecondConstructorArgument()
  63. {
  64. $options = array(
  65. 'soap_version' => SOAP_1_1,
  66. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  67. 'classmap' => array(
  68. 'TestData1' => '\ZendTest\Soap\TestAsset\TestData1',
  69. 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',
  70. ),
  71. 'encoding' => 'ISO-8859-1',
  72. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  73. );
  74. $server = new Server(null, $options);
  75. $this->assertTrue($server->getOptions() == $options);
  76. }
  77. /**
  78. * @group ZF-9816
  79. */
  80. public function testSetOptionsWithFeaturesOption()
  81. {
  82. $server = new Server(null, array(
  83. 'features' => SOAP_SINGLE_ELEMENT_ARRAYS
  84. ));
  85. $this->assertEquals(
  86. SOAP_SINGLE_ELEMENT_ARRAYS,
  87. $server->getSoapFeatures()
  88. );
  89. }
  90. public function testSetWsdlViaOptionsArrayIsPossible()
  91. {
  92. $server = new Server();
  93. $server->setOptions(array('wsdl' => 'http://www.example.com/test.wsdl'));
  94. $this->assertEquals('http://www.example.com/test.wsdl', $server->getWSDL());
  95. }
  96. public function testGetOptions()
  97. {
  98. $server = new Server();
  99. $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2));
  100. $options = array('soap_version' => SOAP_1_1,
  101. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  102. );
  103. $server->setOptions($options);
  104. $this->assertTrue($server->getOptions() == $options);
  105. }
  106. public function testEncoding()
  107. {
  108. $server = new Server();
  109. $this->assertNull($server->getEncoding());
  110. $server->setEncoding('ISO-8859-1');
  111. $this->assertEquals('ISO-8859-1', $server->getEncoding());
  112. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid encoding specified');
  113. $server->setEncoding(array('UTF-8'));
  114. }
  115. public function testSoapVersion()
  116. {
  117. $server = new Server();
  118. $this->assertEquals(SOAP_1_2, $server->getSoapVersion());
  119. $server->setSoapVersion(SOAP_1_1);
  120. $this->assertEquals(SOAP_1_1, $server->getSoapVersion());
  121. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid soap version specified');
  122. $server->setSoapVersion('bogus');
  123. }
  124. public function testValidateUrn()
  125. {
  126. $server = new Server();
  127. $this->assertTrue($server->validateUrn('http://framework.zend.com/'));
  128. $this->assertTrue($server->validateUrn('urn:soapHandler/GetOpt'));
  129. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN');
  130. $server->validateUrn('bogosity');
  131. }
  132. public function testSetActor()
  133. {
  134. $server = new Server();
  135. $this->assertNull($server->getActor());
  136. $server->setActor('http://framework.zend.com/');
  137. $this->assertEquals('http://framework.zend.com/', $server->getActor());
  138. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN');
  139. $server->setActor('bogus');
  140. }
  141. public function testGetActor()
  142. {
  143. $server = new Server();
  144. $this->assertNull($server->getActor());
  145. $server->setActor('http://framework.zend.com/');
  146. $this->assertEquals('http://framework.zend.com/', $server->getActor());
  147. }
  148. public function testSetUri()
  149. {
  150. $server = new Server();
  151. $this->assertNull($server->getUri());
  152. $server->setUri('http://framework.zend.com/');
  153. $this->assertEquals('http://framework.zend.com/', $server->getUri());
  154. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN');
  155. $server->setUri('bogus');
  156. }
  157. public function testGetUri()
  158. {
  159. $server = new Server();
  160. $this->assertNull($server->getUri());
  161. $server->setUri('http://framework.zend.com/');
  162. $this->assertEquals('http://framework.zend.com/', $server->getUri());
  163. }
  164. public function testSetClassmap()
  165. {
  166. $server = new Server();
  167. $classmap = array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1',
  168. 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2');
  169. $this->assertNull($server->getClassmap());
  170. $server->setClassmap($classmap);
  171. $this->assertTrue($classmap == $server->getClassmap());
  172. }
  173. public function testSetClassmapThrowsExceptionOnBogusStringParameter()
  174. {
  175. $server = new Server();
  176. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Classmap must be an array');
  177. $server->setClassmap('bogus');
  178. }
  179. public function testSetClassmapThrowsExceptionOnBogusArrayParameter()
  180. {
  181. $server = new Server();
  182. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid class in class map');
  183. $server->setClassmap(array('soapTypeName', 'bogusClassName'));
  184. }
  185. public function testGetClassmap()
  186. {
  187. $server = new Server();
  188. $classmap = array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1',
  189. 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2');
  190. $this->assertNull($server->getClassmap());
  191. $server->setClassmap($classmap);
  192. $this->assertTrue($classmap == $server->getClassmap());
  193. }
  194. public function testSetWsdl()
  195. {
  196. $server = new Server();
  197. $this->assertNull($server->getWSDL());
  198. $server->setWSDL(__DIR__.'/_files/wsdl_example.wsdl');
  199. $this->assertEquals(__DIR__.'/_files/wsdl_example.wsdl', $server->getWSDL());
  200. //$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'foo');
  201. $server->setWSDL(__DIR__.'/_files/bogus.wsdl');
  202. }
  203. public function testGetWsdl()
  204. {
  205. $server = new Server();
  206. $this->assertNull($server->getWSDL());
  207. $server->setWSDL(__DIR__.'/_files/wsdl_example.wsdl');
  208. $this->assertEquals(__DIR__.'/_files/wsdl_example.wsdl', $server->getWSDL());
  209. }
  210. public function testAddFunction()
  211. {
  212. $server = new Server();
  213. // Correct function should pass
  214. $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc');
  215. // Array of correct functions should pass
  216. $functions = array('\ZendTest\Soap\TestAsset\TestFunc2',
  217. '\ZendTest\Soap\TestAsset\TestFunc3',
  218. '\ZendTest\Soap\TestAsset\TestFunc4');
  219. $server->addFunction($functions);
  220. $this->assertEquals(
  221. array_merge(array('\ZendTest\Soap\TestAsset\TestFunc'), $functions),
  222. $server->getFunctions()
  223. );
  224. }
  225. public function testAddBogusFunctionAsInteger()
  226. {
  227. $server = new Server();
  228. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid function specified');
  229. $server->addFunction(126);
  230. }
  231. public function testAddBogusFunctionsAsString()
  232. {
  233. $server = new Server();
  234. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid function specified');
  235. $server->addFunction('bogus_function');
  236. }
  237. public function testAddBogusFunctionsAsArray()
  238. {
  239. $server = new Server();
  240. $functions = array('\ZendTest\Soap\TestAsset\TestFunc5',
  241. 'bogus_function',
  242. '\ZendTest\Soap\TestAsset\TestFunc6');
  243. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'One or more invalid functions specified in array');
  244. $server->addFunction($functions);
  245. }
  246. public function testAddAllFunctionsSoapConstant()
  247. {
  248. $server = new Server();
  249. // SOAP_FUNCTIONS_ALL as a value should pass
  250. $server->addFunction(SOAP_FUNCTIONS_ALL);
  251. $server->addFunction('substr');
  252. $this->assertEquals(array(SOAP_FUNCTIONS_ALL), $server->getFunctions());
  253. }
  254. public function testSetClass()
  255. {
  256. $server = new Server();
  257. // Correct class name should pass
  258. $r = $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  259. $this->assertSame($server, $r);
  260. }
  261. /**
  262. * @group PR-706
  263. */
  264. public function testSetClassWithObject()
  265. {
  266. $server = new Server();
  267. // Correct class name should pass
  268. $object = new \ZendTest\Soap\TestAsset\ServerTestClass();
  269. $r = $server->setClass($object);
  270. $this->assertSame($server, $r);
  271. }
  272. public function testSetClassTwiceThrowsException()
  273. {
  274. $server = new Server();
  275. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  276. $this->setExpectedException(
  277. 'Zend\Soap\Exception\InvalidArgumentException',
  278. 'A class has already been registered with this soap server instance'
  279. );
  280. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  281. }
  282. public function testSetClassWithArguments()
  283. {
  284. $server = new Server();
  285. // Correct class name should pass
  286. $r = $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass', null, 1, 2, 3, 4);
  287. $this->assertSame($server, $r);
  288. }
  289. public function testSetBogusClassWithIntegerName()
  290. {
  291. $server = new Server();
  292. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid class argument (integer)');
  293. $server->setClass(465);
  294. }
  295. public function testSetBogusClassWithUnknownClassName()
  296. {
  297. $server = new Server();
  298. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Class "Zend_Soap_Server_Test_BogusClass" does not exist');
  299. $server->setClass('Zend_Soap_Server_Test_BogusClass');
  300. }
  301. /**
  302. * @group ZF-4366
  303. */
  304. public function testSetObject()
  305. {
  306. $server = new Server();
  307. // Correct class name should pass
  308. $r = $server->setObject(new TestAsset\ServerTestClass());
  309. $this->assertSame($server, $r);
  310. }
  311. /**
  312. * @group ZF-4366
  313. */
  314. public function testSetObjectThrowsExceptionWithBadInput1()
  315. {
  316. $server = new Server();
  317. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid object argument (integer)');
  318. $server->setObject(465);
  319. }
  320. /**
  321. * @group ZF-4366
  322. */
  323. public function testSetObjectThrowsExceptionWithBadInput2()
  324. {
  325. $server = new Server();
  326. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid object argument (integer)');
  327. $int = 1;
  328. $server->setObject($int);
  329. }
  330. /**
  331. * @group ZF-4366
  332. */
  333. public function testSetObjectThrowsExceptionWithBadInput3()
  334. {
  335. $server = new Server();
  336. //$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'foo');
  337. $server->setObject(new TestAsset\ServerTestClass());
  338. }
  339. public function testGetFunctions()
  340. {
  341. $server = new Server();
  342. $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc');
  343. $functions = array('\ZendTest\Soap\TestAsset\TestFunc2',
  344. '\ZendTest\Soap\TestAsset\TestFunc3',
  345. '\ZendTest\Soap\TestAsset\TestFunc4');
  346. $server->addFunction($functions);
  347. $functions = array('\ZendTest\Soap\TestAsset\TestFunc3',
  348. '\ZendTest\Soap\TestAsset\TestFunc5',
  349. '\ZendTest\Soap\TestAsset\TestFunc6');
  350. $server->addFunction($functions);
  351. $allAddedFunctions = array(
  352. '\ZendTest\Soap\TestAsset\TestFunc',
  353. '\ZendTest\Soap\TestAsset\TestFunc2',
  354. '\ZendTest\Soap\TestAsset\TestFunc3',
  355. '\ZendTest\Soap\TestAsset\TestFunc4',
  356. '\ZendTest\Soap\TestAsset\TestFunc5',
  357. '\ZendTest\Soap\TestAsset\TestFunc6'
  358. );
  359. $this->assertTrue($server->getFunctions() == $allAddedFunctions);
  360. }
  361. public function testGetFunctionsWithClassAttached()
  362. {
  363. $server = new Server();
  364. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  365. $this->assertEquals(
  366. array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'),
  367. $server->getFunctions()
  368. );
  369. }
  370. public function testGetFunctionsWithObjectAttached()
  371. {
  372. $server = new Server();
  373. $server->setObject(new TestAsset\ServerTestClass());
  374. $this->assertEquals(
  375. array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'),
  376. $server->getFunctions()
  377. );
  378. }
  379. public function testSetPersistence()
  380. {
  381. $server = new Server();
  382. $this->assertNull($server->getPersistence());
  383. $server->setPersistence(SOAP_PERSISTENCE_SESSION);
  384. $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence());
  385. $server->setPersistence(SOAP_PERSISTENCE_REQUEST);
  386. $this->assertEquals(SOAP_PERSISTENCE_REQUEST, $server->getPersistence());
  387. }
  388. public function testSetUnknownPersistenceStateThrowsException()
  389. {
  390. $server = new Server();
  391. $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid persistence mode specified');
  392. $server->setPersistence('bogus');
  393. }
  394. public function testGetPersistence()
  395. {
  396. $server = new Server();
  397. $this->assertNull($server->getPersistence());
  398. $server->setPersistence(SOAP_PERSISTENCE_SESSION);
  399. $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence());
  400. }
  401. public function testGetLastRequest()
  402. {
  403. if (headers_sent()) {
  404. $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test');
  405. return;
  406. }
  407. $server = new Server();
  408. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  409. $server->setReturnResponse(true);
  410. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  411. $request =
  412. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  413. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  414. . 'xmlns:ns1="http://framework.zend.com" '
  415. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  416. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  417. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  418. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  419. . '<SOAP-ENV:Body>'
  420. . '<ns1:testFunc2>'
  421. . '<param0 xsi:type="xsd:string">World</param0>'
  422. . '</ns1:testFunc2>'
  423. . '</SOAP-ENV:Body>'
  424. . '</SOAP-ENV:Envelope>' . "\n";
  425. $response = $server->handle($request);
  426. $this->assertEquals($request, $server->getLastRequest());
  427. }
  428. public function testSetReturnResponse()
  429. {
  430. $server = new Server();
  431. $this->assertFalse($server->getReturnResponse());
  432. $server->setReturnResponse(true);
  433. $this->assertTrue($server->getReturnResponse());
  434. $server->setReturnResponse(false);
  435. $this->assertFalse($server->getReturnResponse());
  436. }
  437. public function testGetReturnResponse()
  438. {
  439. $server = new Server();
  440. $this->assertFalse($server->getReturnResponse());
  441. $server->setReturnResponse(true);
  442. $this->assertTrue($server->getReturnResponse());
  443. }
  444. public function testGetLastResponse()
  445. {
  446. if (headers_sent()) {
  447. $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test');
  448. return;
  449. }
  450. $server = new Server();
  451. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  452. $server->setReturnResponse(true);
  453. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  454. $request =
  455. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  456. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  457. . 'xmlns:ns1="http://framework.zend.com" '
  458. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  459. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  460. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  461. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  462. . '<SOAP-ENV:Body>'
  463. . '<ns1:testFunc2>'
  464. . '<param0 xsi:type="xsd:string">World</param0>'
  465. . '</ns1:testFunc2>'
  466. . '</SOAP-ENV:Body>'
  467. . '</SOAP-ENV:Envelope>' . "\n";
  468. $expectedResponse =
  469. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  470. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  471. . 'xmlns:ns1="http://framework.zend.com" '
  472. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  473. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  474. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  475. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  476. . '<SOAP-ENV:Body>'
  477. . '<ns1:testFunc2Response>'
  478. . '<return xsi:type="xsd:string">Hello World!</return>'
  479. . '</ns1:testFunc2Response>'
  480. . '</SOAP-ENV:Body>'
  481. . '</SOAP-ENV:Envelope>' . "\n";
  482. $server->handle($request);
  483. $this->assertEquals($expectedResponse, $server->getResponse());
  484. }
  485. public function testHandle()
  486. {
  487. if (!extension_loaded('soap')) {
  488. $this->markTestSkipped('Soap extension not loaded');
  489. }
  490. if (headers_sent()) {
  491. $this->markTestSkipped('Cannot run testHandle() when headers have already been sent; enable output buffering to run this test');
  492. return;
  493. }
  494. $server = new Server();
  495. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  496. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  497. $localClient = new TestAsset\TestLocalSoapClient($server,
  498. null,
  499. array('location'=>'test://',
  500. 'uri'=>'http://framework.zend.com'));
  501. // Local SOAP client call automatically invokes handle method of the provided SOAP server
  502. $this->assertEquals('Hello World!', $localClient->testFunc2('World'));
  503. $request =
  504. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  505. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  506. . 'xmlns:ns1="http://framework.zend.com" '
  507. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  508. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  509. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  510. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  511. . '<SOAP-ENV:Body>'
  512. . '<ns1:testFunc2>'
  513. . '<param0 xsi:type="xsd:string">World</param0>'
  514. . '</ns1:testFunc2>'
  515. . '</SOAP-ENV:Body>'
  516. . '</SOAP-ENV:Envelope>' . "\n";
  517. $expectedResponse =
  518. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  519. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  520. . 'xmlns:ns1="http://framework.zend.com" '
  521. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  522. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  523. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  524. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  525. . '<SOAP-ENV:Body>'
  526. . '<ns1:testFunc2Response>'
  527. . '<return xsi:type="xsd:string">Hello World!</return>'
  528. . '</ns1:testFunc2Response>'
  529. . '</SOAP-ENV:Body>'
  530. . '</SOAP-ENV:Envelope>' . "\n";
  531. $server1 = new Server();
  532. $server1->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  533. $server1->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  534. $server1->setReturnResponse(true);
  535. $this->assertEquals($expectedResponse, $server1->handle($request));
  536. }
  537. /**
  538. * @todo Implement testRegisterFaultException().
  539. */
  540. public function testRegisterFaultException()
  541. {
  542. $server = new Server();
  543. $server->registerFaultException("Zend_Soap_Server_Exception");
  544. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  545. $this->assertEquals(array(
  546. 'Zend_Soap_Server_Exception',
  547. 'OutOfBoundsException',
  548. 'BogusException',
  549. ), $server->getFaultExceptions());
  550. }
  551. /**
  552. * @todo Implement testDeregisterFaultException().
  553. */
  554. public function testDeregisterFaultException()
  555. {
  556. $server = new Server();
  557. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  558. $ret = $server->deregisterFaultException("BogusException");
  559. $this->assertTrue($ret);
  560. $this->assertEquals(array(
  561. 'OutOfBoundsException',
  562. ), $server->getFaultExceptions());
  563. $ret = $server->deregisterFaultException("NonRegisteredException");
  564. $this->assertFalse($ret);
  565. }
  566. /**
  567. * @todo Implement testGetFaultExceptions().
  568. */
  569. public function testGetFaultExceptions()
  570. {
  571. $server = new Server();
  572. $this->assertEquals(array(), $server->getFaultExceptions());
  573. $server->registerFaultException("Exception");
  574. $this->assertEquals(array("Exception"), $server->getFaultExceptions());
  575. }
  576. public function testFaultWithTextMessage()
  577. {
  578. $server = new Server();
  579. $fault = $server->fault("Faultmessage!");
  580. $this->assertTrue($fault instanceof \SOAPFault);
  581. $this->assertContains("Faultmessage!", $fault->getMessage());
  582. }
  583. public function testFaultWithUnregisteredException()
  584. {
  585. $server = new Server();
  586. $fault = $server->fault(new \Exception("MyException"));
  587. $this->assertTrue($fault instanceof \SOAPFault);
  588. $this->assertContains("Unknown error", $fault->getMessage());
  589. $this->assertNotContains("MyException", $fault->getMessage());
  590. }
  591. public function testFaultWithRegisteredException()
  592. {
  593. $server = new Server();
  594. $server->registerFaultException("Exception");
  595. $fault = $server->fault(new \Exception("MyException"));
  596. $this->assertTrue($fault instanceof \SOAPFault);
  597. $this->assertNotContains("Unknown error", $fault->getMessage());
  598. $this->assertContains("MyException", $fault->getMessage());
  599. }
  600. public function testFautlWithBogusInput()
  601. {
  602. $server = new Server();
  603. $fault = $server->fault(array("Here", "There", "Bogus"));
  604. $this->assertContains("Unknown error", $fault->getMessage());
  605. }
  606. /**
  607. * @group ZF-3958
  608. */
  609. public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault()
  610. {
  611. $server = new Server();
  612. $fault = $server->fault("Faultmessage!", 5000);
  613. $this->assertTrue($fault instanceof \SOAPFault);
  614. }
  615. /**
  616. * @todo Implement testHandlePhpErrors().
  617. */
  618. public function testHandlePhpErrors()
  619. {
  620. $server = new Server();
  621. // Remove the following line when you implement this test.
  622. $this->markTestIncomplete(
  623. "This test has not been implemented yet."
  624. );
  625. }
  626. public function testLoadFunctionsIsNotImplemented()
  627. {
  628. $server = new Server();
  629. $this->setExpectedException('Zend\Soap\Exception\RuntimeException', 'Unimplemented method');
  630. $server->loadFunctions("bogus");
  631. }
  632. public function testErrorHandlingOfSoapServerChangesToThrowingSoapFaultWhenInHandleMode()
  633. {
  634. if (headers_sent()) {
  635. $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test');
  636. return;
  637. }
  638. $server = new Server();
  639. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  640. $server->setReturnResponse(true);
  641. // Requesting Method with enforced parameter without it.
  642. $request =
  643. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  644. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  645. . 'xmlns:ns1="http://framework.zend.com" '
  646. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  647. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  648. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  649. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  650. . '<SOAP-ENV:Body>'
  651. . '<ns1:testFunc5 />'
  652. . '</SOAP-ENV:Body>'
  653. . '</SOAP-ENV:Envelope>' . "\n";
  654. $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');
  655. $response = $server->handle($request);
  656. $this->assertContains(
  657. '<SOAP-ENV:Fault><faultcode>Receiver</faultcode><faultstring>Test Message</faultstring></SOAP-ENV:Fault>',
  658. $response
  659. );
  660. }
  661. /**
  662. * @group ZF-5597
  663. */
  664. public function testServerAcceptsZendConfigObject()
  665. {
  666. $options = array('soap_version' => SOAP_1_1,
  667. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  668. 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1',
  669. 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',),
  670. 'encoding' => 'ISO-8859-1',
  671. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  672. );
  673. $config = new \Zend\Config\Config($options);
  674. $server = new Server();
  675. $server->setOptions($config);
  676. $this->assertEquals($options, $server->getOptions());
  677. }
  678. /**
  679. * @group ZF-5300
  680. */
  681. public function testSetAndGetFeatures()
  682. {
  683. $server = new Server();
  684. $this->assertNull($server->getSoapFeatures());
  685. $server->setSoapFeatures(100);
  686. $this->assertEquals(100, $server->getSoapFeatures());
  687. $options = $server->getOptions();
  688. $this->assertTrue(isset($options['features']));
  689. $this->assertEquals(100, $options['features']);
  690. }
  691. /**
  692. * @group ZF-5300
  693. */
  694. public function testSetAndGetWSDLCache()
  695. {
  696. $server = new Server();
  697. $this->assertNull($server->getWSDLCache());
  698. $server->setWSDLCache(100);
  699. $this->assertEquals(100, $server->getWSDLCache());
  700. $options = $server->getOptions();
  701. $this->assertTrue(isset($options['cache_wsdl']));
  702. $this->assertEquals(100, $options['cache_wsdl']);
  703. }
  704. /**
  705. * @group ZF-11411
  706. */
  707. public function testHandleUsesProperRequestParameter()
  708. {
  709. $server = new \ZendTest\Soap\TestAsset\MockServer();
  710. $r = $server->handle(new \DOMDocument('1.0', 'UTF-8'));
  711. $this->assertTrue(is_string($server->mockSoapServer->handle[0]));
  712. }
  713. }