ParserTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Soap
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once dirname(__FILE__)."/../../../TestHelper.php";
  23. require_once "Zend/Soap/Wsdl.php";
  24. require_once "Zend/Soap/Wsdl/Parser.php";
  25. require_once "Zend/Soap/Wsdl/Parser/Result.php";
  26. /**
  27. * @category Zend
  28. * @package Zend_Soap
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Soap
  33. * @group Zend_Soap_Wsdl
  34. */
  35. class Zend_Soap_Wsdl_ParserTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected function getWsdlExampleDom()
  38. {
  39. $dom = new DOMDocument();
  40. $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl"));
  41. return $dom;
  42. }
  43. public function testFactoryWithDomDocument()
  44. {
  45. $dom = $this->getWsdlExampleDom();
  46. $parser = Zend_Soap_Wsdl_Parser::factory($dom);
  47. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  48. }
  49. public function testFactoryWithString()
  50. {
  51. $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
  52. $parser = Zend_Soap_Wsdl_Parser::factory($xmlString);
  53. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  54. }
  55. public function testFactoryWithSimpleXml()
  56. {
  57. $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
  58. $simpleXml = simplexml_load_string($xmlString);
  59. $parser = Zend_Soap_Wsdl_Parser::factory($simpleXml);
  60. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  61. }
  62. public function testFactoryWithZendSoapWsdl()
  63. {
  64. $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
  65. $parser = Zend_Soap_Wsdl_Parser::factory($wsdl);
  66. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  67. }
  68. public function testFactoryWithInvalidParser()
  69. {
  70. $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
  71. try {
  72. $parser = Zend_Soap_Wsdl_Parser::factory($wsdl, "stdClass");
  73. $this->fail();
  74. } catch(Exception $e) {
  75. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
  76. }
  77. }
  78. public function testFactoryWithInvalidData()
  79. {
  80. try {
  81. $parser = Zend_Soap_Wsdl_Parser::factory(null);
  82. $this->fail();
  83. } catch(Zend_Soap_Wsdl_Exception $e) {
  84. }
  85. }
  86. public function testParserApiInterface()
  87. {
  88. // Constructor expects DOMDocument instance
  89. $dom = $this->getWsdlExampleDom();
  90. $parser = new Zend_Soap_Wsdl_Parser($dom);
  91. // SetWsdl is a fluent function
  92. $this->assertTrue( ($parser->setDomDocumentContainingWsdl($dom)) instanceof Zend_Soap_Wsdl_Parser );
  93. // Parse returns Result
  94. $result = $parser->parse();
  95. $this->assertTrue($result instanceof Zend_Soap_Wsdl_Parser_Result);
  96. }
  97. public function testParserResultApiInterface()
  98. {
  99. $result = new Zend_Soap_Wsdl_Parser_Result(
  100. "name",
  101. Zend_Soap_Wsdl_Parser::WSDL_11,
  102. new Zend_Soap_Wsdl_Element_Collection("Operation"),
  103. new Zend_Soap_Wsdl_Element_Collection("Port"),
  104. new Zend_Soap_Wsdl_Element_Collection("Binding"),
  105. new Zend_Soap_Wsdl_Element_Collection("Service"),
  106. new Zend_Soap_Wsdl_Element_Collection("Type"),
  107. array("docs")
  108. );
  109. $this->assertEquals("name", $result->getName());
  110. $this->assertEquals("Zend_Soap_Wsdl_Element_Operation", $result->operations->getType());
  111. $this->assertEquals("Zend_Soap_Wsdl_Element_Port", $result->ports->getType());
  112. $this->assertEquals("Zend_Soap_Wsdl_Element_Binding", $result->bindings->getType());
  113. $this->assertEquals("Zend_Soap_Wsdl_Element_Service", $result->services->getType());
  114. $this->assertEquals("Zend_Soap_Wsdl_Element_Type", $result->types->getType());
  115. $this->assertEquals(array("docs"), $result->documentation);
  116. try {
  117. $key = $result->invalidKeyThrowsException;
  118. $this->fail();
  119. } catch(Exception $e) {
  120. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
  121. }
  122. }
  123. public function testParseExampleWsdlAndCountResultElements()
  124. {
  125. // Constructor expects DOMDocument instance
  126. $dom = $this->getWsdlExampleDom();
  127. $parser = new Zend_Soap_Wsdl_Parser($dom);
  128. $result = $parser->parse();
  129. $this->assertEquals("Zend_Soap_Server_TestClass", $result->getName());
  130. $this->assertEquals(Zend_Soap_Wsdl_Parser::WSDL_11, $result->getVersion());
  131. $this->assertEquals(4, count($result->operations), "Number of operations does not match.");
  132. $this->assertEquals(1, count($result->bindings), "Number of bindings does not match.");
  133. $this->assertEquals(1, count($result->ports), "Number of ports does not match.");
  134. $this->assertEquals(1, count($result->services), "Number of services does not match.");
  135. $this->assertEquals(0, count($result->types), "Number of types does not match.");
  136. $this->assertEquals(4, count($result->bindings->current()->operations), "Number of operations in the bindings collection does not match.");
  137. $this->assertEquals(4, count($result->ports->current()->operations), "Number of operations in the ports collection does not match.");
  138. }
  139. public function testParseExampleWsdlAndCheckMatchingNames()
  140. {
  141. // Constructor expects DOMDocument instance
  142. $dom = $this->getWsdlExampleDom();
  143. $parser = new Zend_Soap_Wsdl_Parser($dom);
  144. $result = $parser->parse();
  145. foreach($result->operations AS $operation) {
  146. $this->assertContains($operation->getName(), array("testFunc1", "testFunc2", "testFunc3", "testFunc4"));
  147. }
  148. foreach($result->bindings AS $binding) {
  149. $this->assertEquals("Zend_Soap_Server_TestClassBinding", $binding->getName());
  150. }
  151. foreach($result->ports AS $port) {
  152. $this->assertEquals("Zend_Soap_Server_TestClassPort", $port->getName());
  153. }
  154. foreach($result->services AS $service) {
  155. $this->assertEquals("Zend_Soap_Server_TestClassService", $service->getName());
  156. }
  157. }
  158. public function testParseExampleWsdlWithDocumentationBlocks()
  159. {
  160. $dom = new DOMDocument();
  161. $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_documentation.wsdl"));
  162. $parser = new Zend_Soap_Wsdl_Parser($dom);
  163. $result = $parser->parse();
  164. }
  165. }