ServerTest.php 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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-2009 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-2009 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. if (headers_sent()) {
  428. $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test');
  429. return;
  430. }
  431. $server = new Zend_Soap_Server();
  432. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  433. $server->setReturnResponse(true);
  434. $server->setClass('Zend_Soap_Server_TestClass');
  435. $request =
  436. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  437. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  438. . 'xmlns:ns1="http://framework.zend.com" '
  439. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  440. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  441. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  442. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  443. . '<SOAP-ENV:Body>'
  444. . '<ns1:testFunc2>'
  445. . '<param0 xsi:type="xsd:string">World</param0>'
  446. . '</ns1:testFunc2>'
  447. . '</SOAP-ENV:Body>'
  448. . '</SOAP-ENV:Envelope>' . "\n";
  449. $response = $server->handle($request);
  450. $this->assertEquals($request, $server->getLastRequest());
  451. }
  452. public function testSetReturnResponse()
  453. {
  454. $server = new Zend_Soap_Server();
  455. $this->assertFalse($server->getReturnResponse());
  456. $server->setReturnResponse(true);
  457. $this->assertTrue($server->getReturnResponse());
  458. $server->setReturnResponse(false);
  459. $this->assertFalse($server->getReturnResponse());
  460. }
  461. public function testGetReturnResponse()
  462. {
  463. $server = new Zend_Soap_Server();
  464. $this->assertFalse($server->getReturnResponse());
  465. $server->setReturnResponse(true);
  466. $this->assertTrue($server->getReturnResponse());
  467. }
  468. public function testGetLastResponse()
  469. {
  470. if (headers_sent()) {
  471. $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test');
  472. return;
  473. }
  474. $server = new Zend_Soap_Server();
  475. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  476. $server->setReturnResponse(true);
  477. $server->setClass('Zend_Soap_Server_TestClass');
  478. $request =
  479. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  480. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  481. . 'xmlns:ns1="http://framework.zend.com" '
  482. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  483. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  484. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  485. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  486. . '<SOAP-ENV:Body>'
  487. . '<ns1:testFunc2>'
  488. . '<param0 xsi:type="xsd:string">World</param0>'
  489. . '</ns1:testFunc2>'
  490. . '</SOAP-ENV:Body>'
  491. . '</SOAP-ENV:Envelope>' . "\n";
  492. $expectedResponse =
  493. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  494. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  495. . 'xmlns:ns1="http://framework.zend.com" '
  496. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  497. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  498. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  499. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  500. . '<SOAP-ENV:Body>'
  501. . '<ns1:testFunc2Response>'
  502. . '<return xsi:type="xsd:string">Hello World!</return>'
  503. . '</ns1:testFunc2Response>'
  504. . '</SOAP-ENV:Body>'
  505. . '</SOAP-ENV:Envelope>' . "\n";
  506. $server->handle($request);
  507. $this->assertEquals($expectedResponse, $server->getLastResponse());
  508. }
  509. public function testHandle()
  510. {
  511. if (headers_sent()) {
  512. $this->markTestSkipped('Cannot run testHandle() when headers have already been sent; enable output buffering to run this test');
  513. return;
  514. }
  515. $server = new Zend_Soap_Server();
  516. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  517. $server->setClass('Zend_Soap_Server_TestClass');
  518. $localClient = new Zend_Soap_Server_TestLocalSoapClient($server,
  519. null,
  520. array('location'=>'test://',
  521. 'uri'=>'http://framework.zend.com'));
  522. // Local SOAP client call automatically invokes handle method of the provided SOAP server
  523. $this->assertEquals('Hello World!', $localClient->testFunc2('World'));
  524. $request =
  525. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  526. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  527. . 'xmlns:ns1="http://framework.zend.com" '
  528. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  529. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  530. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  531. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  532. . '<SOAP-ENV:Body>'
  533. . '<ns1:testFunc2>'
  534. . '<param0 xsi:type="xsd:string">World</param0>'
  535. . '</ns1:testFunc2>'
  536. . '</SOAP-ENV:Body>'
  537. . '</SOAP-ENV:Envelope>' . "\n";
  538. $expectedResponse =
  539. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  540. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  541. . 'xmlns:ns1="http://framework.zend.com" '
  542. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  543. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  544. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  545. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  546. . '<SOAP-ENV:Body>'
  547. . '<ns1:testFunc2Response>'
  548. . '<return xsi:type="xsd:string">Hello World!</return>'
  549. . '</ns1:testFunc2Response>'
  550. . '</SOAP-ENV:Body>'
  551. . '</SOAP-ENV:Envelope>' . "\n";
  552. $server1 = new Zend_Soap_Server();
  553. $server1->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  554. $server1->setClass('Zend_Soap_Server_TestClass');
  555. $server1->setReturnResponse(true);
  556. $this->assertEquals($expectedResponse, $server1->handle($request));
  557. }
  558. /**
  559. * @todo Implement testRegisterFaultException().
  560. */
  561. public function testRegisterFaultException()
  562. {
  563. $server = new Zend_Soap_Server();
  564. $server->registerFaultException("Zend_Soap_Server_Exception");
  565. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  566. $this->assertEquals(array(
  567. 'Zend_Soap_Server_Exception',
  568. 'OutOfBoundsException',
  569. 'BogusException',
  570. ), $server->getFaultExceptions());
  571. }
  572. /**
  573. * @todo Implement testDeregisterFaultException().
  574. */
  575. public function testDeregisterFaultException()
  576. {
  577. $server = new Zend_Soap_Server();
  578. $server->registerFaultException(array("OutOfBoundsException", "BogusException"));
  579. $ret = $server->deregisterFaultException("BogusException");
  580. $this->assertTrue($ret);
  581. $this->assertEquals(array(
  582. 'OutOfBoundsException',
  583. ), $server->getFaultExceptions());
  584. $ret = $server->deregisterFaultException("NonRegisteredException");
  585. $this->assertFalse($ret);
  586. }
  587. /**
  588. * @todo Implement testGetFaultExceptions().
  589. */
  590. public function testGetFaultExceptions()
  591. {
  592. $server = new Zend_Soap_Server();
  593. $this->assertEquals(array(), $server->getFaultExceptions());
  594. $server->registerFaultException("Exception");
  595. $this->assertEquals(array("Exception"), $server->getFaultExceptions());
  596. }
  597. public function testFaultWithTextMessage()
  598. {
  599. $server = new Zend_Soap_Server();
  600. $fault = $server->fault("Faultmessage!");
  601. $this->assertTrue($fault instanceof SOAPFault);
  602. $this->assertContains("Faultmessage!", $fault->getMessage());
  603. }
  604. public function testFaultWithUnregisteredException()
  605. {
  606. $server = new Zend_Soap_Server();
  607. $fault = $server->fault(new Exception("MyException"));
  608. $this->assertTrue($fault instanceof SOAPFault);
  609. $this->assertContains("Unknown error", $fault->getMessage());
  610. $this->assertNotContains("MyException", $fault->getMessage());
  611. }
  612. public function testFaultWithRegisteredException()
  613. {
  614. $server = new Zend_Soap_Server();
  615. $server->registerFaultException("Exception");
  616. $fault = $server->fault(new Exception("MyException"));
  617. $this->assertTrue($fault instanceof SOAPFault);
  618. $this->assertNotContains("Unknown error", $fault->getMessage());
  619. $this->assertContains("MyException", $fault->getMessage());
  620. }
  621. public function testFautlWithBogusInput()
  622. {
  623. $server = new Zend_Soap_Server();
  624. $fault = $server->fault(array("Here", "There", "Bogus"));
  625. $this->assertContains("Unknown error", $fault->getMessage());
  626. }
  627. /**
  628. * @group ZF-3958
  629. */
  630. public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault()
  631. {
  632. $server = new Zend_Soap_Server();
  633. $fault = $server->fault("Faultmessage!", 5000);
  634. $this->assertTrue($fault instanceof SOAPFault);
  635. }
  636. /**
  637. * @todo Implement testHandlePhpErrors().
  638. */
  639. public function testHandlePhpErrors()
  640. {
  641. $server = new Zend_Soap_Server();
  642. // Remove the following line when you implement this test.
  643. $this->markTestIncomplete(
  644. "This test has not been implemented yet."
  645. );
  646. }
  647. public function testLoadFunctionsIsNotImplemented()
  648. {
  649. $server = new Zend_Soap_Server();
  650. try {
  651. $server->loadFunctions("bogus");
  652. $this->fail();
  653. } catch(Zend_Soap_Server_Exception $e) {
  654. }
  655. }
  656. public function testErrorHandlingOfSoapServerChangesToThrowingSoapFaultWhenInHandleMode()
  657. {
  658. if (headers_sent()) {
  659. $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test');
  660. return;
  661. }
  662. $server = new Zend_Soap_Server();
  663. $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
  664. $server->setReturnResponse(true);
  665. // Requesting Method with enforced parameter without it.
  666. $request =
  667. '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
  668. . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
  669. . 'xmlns:ns1="http://framework.zend.com" '
  670. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  671. . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  672. . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
  673. . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
  674. . '<SOAP-ENV:Body>'
  675. . '<ns1:testFunc5 />'
  676. . '</SOAP-ENV:Body>'
  677. . '</SOAP-ENV:Envelope>' . "\n";
  678. $server->setClass('Zend_Soap_Server_TestClass');
  679. $response = $server->handle($request);
  680. $this->assertContains(
  681. '<SOAP-ENV:Fault><faultcode>Receiver</faultcode><faultstring>Test Message</faultstring></SOAP-ENV:Fault>',
  682. $response
  683. );
  684. }
  685. /**
  686. * @group ZF-5597
  687. */
  688. public function testServerAcceptsZendConfigObject()
  689. {
  690. $options = array('soap_version' => SOAP_1_1,
  691. 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
  692. 'classmap' => array('TestData1' => 'Zend_Soap_Server_TestData1',
  693. 'TestData2' => 'Zend_Soap_Server_TestData2',),
  694. 'encoding' => 'ISO-8859-1',
  695. 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php'
  696. );
  697. $config = new Zend_Config($options);
  698. $server = new Zend_Soap_Server();
  699. $server->setOptions($config);
  700. $this->assertEquals($options, $server->getOptions());
  701. }
  702. /**
  703. * @group ZF-5300
  704. */
  705. public function testSetAndGetFeatures()
  706. {
  707. $server = new Zend_Soap_Server();
  708. $this->assertNull($server->getSoapFeatures());
  709. $server->setSoapFeatures(100);
  710. $this->assertEquals(100, $server->getSoapFeatures());
  711. $options = $server->getOptions();
  712. $this->assertTrue(isset($options['features']));
  713. $this->assertEquals(100, $options['features']);
  714. }
  715. /**
  716. * @group ZF-5300
  717. */
  718. public function testSetAndGetWsdlCache()
  719. {
  720. $server = new Zend_Soap_Server();
  721. $this->assertNull($server->getWsdlCache());
  722. $server->setWsdlCache(100);
  723. $this->assertEquals(100, $server->getWsdlCache());
  724. $options = $server->getOptions();
  725. $this->assertTrue(isset($options['cache_wsdl']));
  726. $this->assertEquals(100, $options['cache_wsdl']);
  727. }
  728. }
  729. if (extension_loaded('soap')) {
  730. /** Local SOAP client */
  731. class Zend_Soap_Server_TestLocalSoapClient extends SoapClient {
  732. /**
  733. * Server object
  734. *
  735. * @var Zend_Soap_Server
  736. */
  737. public $server;
  738. /**
  739. * Local client constructor
  740. *
  741. * @param Zend_Soap_Server $server
  742. * @param string $wsdl
  743. * @param array $options
  744. */
  745. function __construct(Zend_Soap_Server $server, $wsdl, $options) {
  746. $this->server = $server;
  747. parent::__construct($wsdl, $options);
  748. }
  749. function __doRequest($request, $location, $action, $version) {
  750. ob_start();
  751. $this->server->handle($request);
  752. $response = ob_get_contents();
  753. ob_end_clean();
  754. return $response;
  755. }
  756. }
  757. }
  758. /** Test Class */
  759. class Zend_Soap_Server_TestClass {
  760. /**
  761. * Test Function 1
  762. *
  763. * @return string
  764. */
  765. function testFunc1()
  766. {
  767. return "Hello World";
  768. }
  769. /**
  770. * Test Function 2
  771. *
  772. * @param string $who Some Arg
  773. * @return string
  774. */
  775. function testFunc2($who)
  776. {
  777. return "Hello $who!";
  778. }
  779. /**
  780. * Test Function 3
  781. *
  782. * @param string $who Some Arg
  783. * @param int $when Some
  784. * @return string
  785. */
  786. function testFunc3($who, $when)
  787. {
  788. return "Hello $who, How are you $when";
  789. }
  790. /**
  791. * Test Function 4
  792. *
  793. * @return string
  794. */
  795. static function testFunc4()
  796. {
  797. return "I'm Static!";
  798. }
  799. /**
  800. * Test Function 5 raises a user error
  801. *
  802. * @return void
  803. */
  804. function testFunc5()
  805. {
  806. trigger_error("Test Message", E_USER_ERROR);
  807. }
  808. }
  809. /** Test class 2 */
  810. class Zend_Soap_Server_TestData1 {
  811. /**
  812. * Property1
  813. *
  814. * @var string
  815. */
  816. public $property1;
  817. /**
  818. * Property2
  819. *
  820. * @var float
  821. */
  822. public $property2;
  823. }
  824. /** Test class 2 */
  825. class Zend_Soap_Server_TestData2 {
  826. /**
  827. * Property1
  828. *
  829. * @var integer
  830. */
  831. public $property1;
  832. /**
  833. * Property1
  834. *
  835. * @var float
  836. */
  837. public $property2;
  838. }
  839. /* Test Functions */
  840. /**
  841. * Test Function
  842. *
  843. * @param string $arg
  844. * @return string
  845. */
  846. function Zend_Soap_Server_TestFunc1($who)
  847. {
  848. return "Hello $who";
  849. }
  850. /**
  851. * Test Function 2
  852. */
  853. function Zend_Soap_Server_TestFunc2()
  854. {
  855. return "Hello World";
  856. }
  857. /**
  858. * Return false
  859. *
  860. * @return bool
  861. */
  862. function Zend_Soap_Server_TestFunc3()
  863. {
  864. return false;
  865. }
  866. /**
  867. * Return true
  868. *
  869. * @return bool
  870. */
  871. function Zend_Soap_Server_TestFunc4()
  872. {
  873. return true;
  874. }
  875. /**
  876. * Return integer
  877. *
  878. * @return int
  879. */
  880. function Zend_Soap_Server_TestFunc5()
  881. {
  882. return 123;
  883. }
  884. /**
  885. * Return string
  886. *
  887. * @return string
  888. */
  889. function Zend_Soap_Server_TestFunc6()
  890. {
  891. return "string";
  892. }