ServerTest.php 31 KB

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