PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Soap/ServerTest.php

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