PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zendframework/tests/ZendTest/Soap/ServerTest.php

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