Przeglądaj źródła

ZF-8948, ZF-5766 - Allow recursive object graph in complex types

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21858 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 15 lat temu
rodzic
commit
88e14546bb

+ 2 - 3
library/Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php

@@ -46,9 +46,8 @@ class Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex extends Zend_Soap_Wsdl_Strategy
      */
     public function addComplexType($type)
     {
-        if(in_array($type, $this->_inProcess)) {
-            require_once "Zend/Soap/Wsdl/Exception.php";
-            throw new Zend_Soap_Wsdl_Exception("Infinite recursion, cannot nest '".$type."' into itself.");
+        if (in_array($type, $this->_inProcess)) {
+            return "tns:" . $type;
         }
         $this->_inProcess[$type] = $type;
 

+ 34 - 0
tests/Zend/Soap/AutoDiscoverTest.php

@@ -904,4 +904,38 @@ class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
             $wsdl
         );
     }
+
+    /**
+     * @group ZF-8948
+     * @group ZF-5766
+     */
+    public function testRecursiveWsdlDependencies()
+    {
+        $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
+        $autodiscover->setClass('Zend_Soap_AutoDiscover_Recursion');
+        $wsdl = $autodiscover->toXml();
+
+        //  <types>
+        //      <xsd:schema targetNamespace="http://localhost/my_script.php">
+        //          <xsd:complexType name="Zend_Soap_AutoDiscover_Recursion">
+        //              <xsd:all>
+        //                  <xsd:element name="recursion" type="tns:Zend_Soap_AutoDiscover_Recursion"/>
+
+
+        $path = '//wsdl:types/xsd:schema/xsd:complexType[@name="Zend_Soap_AutoDiscover_Recursion"]/xsd:all/xsd:element[@name="recursion" and @type="tns:Zend_Soap_AutoDiscover_Recursion"]';
+        $this->assertWsdlPathExists($wsdl, $path);
+    }
+
+    public function assertWsdlPathExists($xml, $path)
+    {
+        $doc = new DOMDocument('UTF-8');
+        $doc->loadXML($xml);
+
+        $xpath = new DOMXPath($doc);
+        $xpath->registerNamespace('wsdl', 'http://schemas.xmlsoap.org/wsdl/');
+
+        $nodes = $xpath->query($path);
+
+        $this->assertTrue($nodes->length >= 1, "Could not assert that XML Document contains a node that matches the XPath Expression: " . $path);
+    }
 }

+ 2 - 6
tests/Zend/Soap/Wsdl/ArrayOfTypeComplexStrategyTest.php

@@ -220,14 +220,10 @@ class Zend_Soap_Wsdl_ArrayOfTypeComplexStrategyTest extends PHPUnit_Framework_Te
 
     /**
      * @group ZF-5754
+     * @group ZF-8948
      */
     public function testNestingOfSameTypesDoesNotLeadToInfiniteRecursionButWillThrowException()
     {
-        try {
-            $return = $this->wsdl->addComplexType("Zend_Soap_AutoDiscover_Recursion");
-        } catch(Exception $e) {
-            $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
-            $this->assertEquals("Infinite recursion, cannot nest 'Zend_Soap_AutoDiscover_Recursion' into itself.", $e->getMessage());
-        }
+        $return = $this->wsdl->addComplexType("Zend_Soap_AutoDiscover_Recursion");
     }
 }

+ 0 - 246
tests/Zend/Soap/Wsdl/ElementTest.php

@@ -1,246 +0,0 @@
-<?php
-/**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category   Zend
- * @package    Zend_Soap
- * @subpackage UnitTests
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id$
- */
-
-require_once dirname(__FILE__)."/../../../TestHelper.php";
-require_once "Zend/Soap/Wsdl/Element/Binding.php";
-require_once "Zend/Soap/Wsdl/Element/Type.php";
-require_once "Zend/Soap/Wsdl/Element/Message.php";
-require_once "Zend/Soap/Wsdl/Element/Operation.php";
-require_once "Zend/Soap/Wsdl/Element/Port.php";
-require_once "Zend/Soap/Wsdl/Element/Service.php";
-require_once "Zend/Soap/Wsdl/Element/Collection.php";
-
-/**
- * @category   Zend
- * @package    Zend_Soap
- * @subpackage UnitTests
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @group      Zend_Soap
- * @group      Zend_Soap_Wsdl
- */
-class Zend_Soap_Wsdl_ElementTest extends PHPUnit_Framework_TestCase
-{
-    public function testBindingElementApi()
-    {
-        $operations = new Zend_Soap_Wsdl_Element_Collection("test");
-        $binding = new Zend_Soap_Wsdl_Element_Binding("name1", "port1", $operations, "test");
-
-        $this->assertEquals("name1", $binding->getName());
-        $this->assertEquals("port1", $binding->portName);
-        $this->assertEquals($operations, $binding->operations);
-        $this->assertEquals("test", $binding->getDocumentation());
-
-        try {
-            $binding = new Zend_Soap_Wsdl_Element_Binding(array(), "portName", $operations, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testTypeElementApi()
-    {
-        $types = new Zend_Soap_Wsdl_Element_Collection("test");
-        $type = new Zend_Soap_Wsdl_Element_Type("name1", $types, "test");
-
-        $this->assertEquals("name1", $type->getName());
-        $this->assertEquals($types, $type->types);
-        $this->assertEquals("test", $type->getDocumentation());
-
-        try {
-            $type = new Zend_Soap_Wsdl_Element_Type(array(), $types, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testMessageElementApi()
-    {
-        $parts = new Zend_Soap_Wsdl_Element_Collection("test");
-        $message = new Zend_Soap_Wsdl_Element_Message("name1", $parts, "test");
-
-        $this->assertEquals("name1", $message->getName());
-        $this->assertEquals($parts, $message->parts);
-        $this->assertEquals("test", $message->getDocumentation());
-
-        try {
-            $message = new Zend_Soap_Wsdl_Element_Message(array(), $parts, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testPortElementApi()
-    {
-        $operations = new Zend_Soap_Wsdl_Element_Collection("test");
-        $port = new Zend_Soap_Wsdl_Element_Port("name1", $operations, "test");
-
-        $this->assertEquals("name1", $port->getName());
-        $this->assertEquals($operations, $port->operations);
-        $this->assertEquals("test", $port->getDocumentation());
-
-        try {
-            $port = new Zend_Soap_Wsdl_Element_Port(array(), $operations, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testOperationElementApi()
-    {
-        $collection = new Zend_Soap_Wsdl_Element_Collection("test");
-        $input = new Zend_Soap_Wsdl_Element_Message("name", $collection, "test");
-        $output = new Zend_Soap_Wsdl_Element_Message("name", $collection, "test");
-
-        $operation = new Zend_Soap_Wsdl_Element_Operation("name1", $input, $output, "test");
-
-        $this->assertEquals("name1",    $operation->getName());
-        $this->assertEquals($input,     $operation->inputMessage);
-        $this->assertEquals($output,    $operation->outputMessage);
-        $this->assertEquals("test", $operation->getDocumentation());
-
-        try {
-            $operation = new Zend_Soap_Wsdl_Element_Operation(array(), $input, $output, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testServiceElementApi()
-    {
-        $collection = new Zend_Soap_Wsdl_Element_Collection("test");
-        $port = new Zend_Soap_Wsdl_Element_Port("name", $collection, "test");
-        $binding = new Zend_Soap_Wsdl_Element_Binding("name", "port", $collection, "test");
-
-        $service = new Zend_Soap_Wsdl_Element_Service("service", "address", $port, $binding, "test");
-
-        $this->assertEquals("service", $service->getName());
-        $this->assertEquals("address", $service->soapAddress);
-        $this->assertEquals($port,     $service->port);
-        $this->assertEquals($binding,  $service->binding);
-        $this->assertEquals("test", $service->getDocumentation());
-
-        try {
-            $service = new Zend_Soap_Wsdl_Element_Service(array(), "address", $port, $binding, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-
-        try {
-            $service = new Zend_Soap_Wsdl_Element_Service("name", array(), $port, $binding, "test");
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testCollectionElementApiConstruct()
-    {
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Operation");
-
-        $this->assertTrue($collection instanceof Countable);
-        $this->assertTrue($collection instanceof Iterator);
-
-        try {
-            $type = new Zend_Soap_Wsdl_Element_Type("type", new Zend_Soap_Wsdl_Element_Collection("Type"), "test");
-            $collection->addElement($type);
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-
-        try {
-            $collection = new Zend_Soap_Wsdl_Element_Collection(false);
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testCollectionElementApiType()
-    {
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Operation");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Operation", $collection->getType());
-
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Type");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Type", $collection->getType());
-
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Binding");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Binding", $collection->getType());
-
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Service");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Service", $collection->getType());
-
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Port");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Port", $collection->getType());
-
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Message");
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Message", $collection->getType());
-    }
-
-    public function testCollectionElementApiElementAccess()
-    {
-        $collection = new Zend_Soap_Wsdl_Element_Collection("Message");
-        $message1 = new Zend_Soap_Wsdl_Element_Message("message1", new Zend_Soap_Wsdl_Element_Collection("Type"), "test");
-        $message2 = new Zend_Soap_Wsdl_Element_Message("message2", new Zend_Soap_Wsdl_Element_Collection("Type"), "test");
-        $messageDuplicate = new Zend_Soap_Wsdl_Element_Message("message2", new Zend_Soap_Wsdl_Element_Collection("Type"), "test");
-
-        $collection->addElement($message1);
-        $this->assertEquals(array("message1"), $collection->getElementNames());
-        $this->assertEquals($message1, $collection->getElement("message1"));
-        $this->assertEquals(1, count($collection));
-
-        $collection->addElement($message2);
-        $this->assertEquals(array("message1", "message2"), $collection->getElementNames());
-        $this->assertEquals($message2, $collection->getElement("message2"));
-        $this->assertEquals(2, count($collection));
-
-        try {
-            // Adding duplicate message leads to exception
-            $collection->addElement($messageDuplicate);
-            $this->fail("Adding a duplicate named element to a collection should throw an exception.");
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-            $this->assertEquals(array("message1", "message2"), $collection->getElementNames());
-            $this->assertEquals($message2, $collection->getElement("message2"));
-            $this->assertEquals(2, count($collection));
-        }
-
-        try {
-            // Accessing unkown message leads to exception
-            $collection->getElement("messageUnknown");
-            $this->fail("Accessing unknown element should throw an exception.");
-        }  catch(Zend_Soap_Wsdl_Exception $e) {
-            $this->assertEquals(2, count($collection));
-        }
-
-        foreach($collection AS $name => $message) {
-            $this->assertTrue($message instanceof Zend_Soap_Wsdl_Element_Message);
-            $this->assertTrue( in_array($name, $collection->getElementNames()) );
-        }
-    }
-}

+ 0 - 188
tests/Zend/Soap/Wsdl/ParserTest.php

@@ -1,188 +0,0 @@
-<?php
-/**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category   Zend
- * @package    Zend_Soap
- * @subpackage UnitTests
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id$
- */
-
-require_once dirname(__FILE__)."/../../../TestHelper.php";
-require_once "Zend/Soap/Wsdl.php";
-require_once "Zend/Soap/Wsdl/Parser.php";
-require_once "Zend/Soap/Wsdl/Parser/Result.php";
-
-/**
- * @category   Zend
- * @package    Zend_Soap
- * @subpackage UnitTests
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @group      Zend_Soap
- * @group      Zend_Soap_Wsdl
- */
-class Zend_Soap_Wsdl_ParserTest extends PHPUnit_Framework_TestCase
-{
-    protected function getWsdlExampleDom()
-    {
-        $dom = new DOMDocument();
-        $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl"));
-        return $dom;
-    }
-
-    public function testFactoryWithDomDocument()
-    {
-        $dom = $this->getWsdlExampleDom();
-        $parser = Zend_Soap_Wsdl_Parser::factory($dom);
-        $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
-    }
-
-    public function testFactoryWithString()
-    {
-        $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
-        $parser = Zend_Soap_Wsdl_Parser::factory($xmlString);
-        $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
-    }
-
-    public function testFactoryWithSimpleXml()
-    {
-        $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
-        $simpleXml = simplexml_load_string($xmlString);
-        $parser = Zend_Soap_Wsdl_Parser::factory($simpleXml);
-        $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
-    }
-
-    public function testFactoryWithZendSoapWsdl()
-    {
-        $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
-        $parser = Zend_Soap_Wsdl_Parser::factory($wsdl);
-        $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
-    }
-
-    public function testFactoryWithInvalidParser()
-    {
-        $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
-        try {
-            $parser = Zend_Soap_Wsdl_Parser::factory($wsdl, "stdClass");
-            $this->fail();
-        } catch(Exception $e) {
-            $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
-        }
-    }
-
-    public function testFactoryWithInvalidData()
-    {
-        try {
-            $parser = Zend_Soap_Wsdl_Parser::factory(null);
-            $this->fail();
-        } catch(Zend_Soap_Wsdl_Exception $e) {
-
-        }
-    }
-
-    public function testParserApiInterface()
-    {
-        // Constructor expects DOMDocument instance
-        $dom = $this->getWsdlExampleDom();
-        $parser = new Zend_Soap_Wsdl_Parser($dom);
-
-        // SetWsdl is a fluent function
-        $this->assertTrue( ($parser->setDomDocumentContainingWsdl($dom)) instanceof Zend_Soap_Wsdl_Parser );
-
-        // Parse returns Result
-        $result = $parser->parse();
-        $this->assertTrue($result instanceof Zend_Soap_Wsdl_Parser_Result);
-    }
-
-    public function testParserResultApiInterface()
-    {
-        $result = new Zend_Soap_Wsdl_Parser_Result(
-            "name",
-            Zend_Soap_Wsdl_Parser::WSDL_11,
-            new Zend_Soap_Wsdl_Element_Collection("Operation"),
-            new Zend_Soap_Wsdl_Element_Collection("Port"),
-            new Zend_Soap_Wsdl_Element_Collection("Binding"),
-            new Zend_Soap_Wsdl_Element_Collection("Service"),
-            new Zend_Soap_Wsdl_Element_Collection("Type"),
-            array("docs")
-        );
-
-        $this->assertEquals("name",         $result->getName());
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Operation",    $result->operations->getType());
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Port",         $result->ports->getType());
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Binding",      $result->bindings->getType());
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Service",      $result->services->getType());
-        $this->assertEquals("Zend_Soap_Wsdl_Element_Type",         $result->types->getType());
-        $this->assertEquals(array("docs"),  $result->documentation);
-
-        try {
-            $key = $result->invalidKeyThrowsException;
-            $this->fail();
-        } catch(Exception $e) {
-            $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
-        }
-    }
-
-    public function testParseExampleWsdlAndCountResultElements()
-    {
-        // Constructor expects DOMDocument instance
-        $dom = $this->getWsdlExampleDom();
-        $parser = new Zend_Soap_Wsdl_Parser($dom);
-
-        $result = $parser->parse();
-
-        $this->assertEquals("Zend_Soap_Server_TestClass", $result->getName());
-        $this->assertEquals(Zend_Soap_Wsdl_Parser::WSDL_11, $result->getVersion());
-        $this->assertEquals(4, count($result->operations), "Number of operations does not match.");
-        $this->assertEquals(1, count($result->bindings), "Number of bindings does not match.");
-        $this->assertEquals(1, count($result->ports), "Number of ports does not match.");
-        $this->assertEquals(1, count($result->services), "Number of services does not match.");
-        $this->assertEquals(0, count($result->types), "Number of types does not match.");
-        $this->assertEquals(4, count($result->bindings->current()->operations), "Number of operations in the bindings collection does not match.");
-        $this->assertEquals(4, count($result->ports->current()->operations), "Number of operations in the ports collection does not match.");
-    }
-
-    public function testParseExampleWsdlAndCheckMatchingNames()
-    {
-        // Constructor expects DOMDocument instance
-        $dom = $this->getWsdlExampleDom();
-        $parser = new Zend_Soap_Wsdl_Parser($dom);
-
-        $result = $parser->parse();
-
-        foreach($result->operations AS $operation) {
-            $this->assertContains($operation->getName(), array("testFunc1", "testFunc2", "testFunc3", "testFunc4"));
-        }
-        foreach($result->bindings AS $binding) {
-            $this->assertEquals("Zend_Soap_Server_TestClassBinding", $binding->getName());
-        }
-        foreach($result->ports AS $port) {
-            $this->assertEquals("Zend_Soap_Server_TestClassPort", $port->getName());
-        }
-        foreach($result->services AS $service) {
-            $this->assertEquals("Zend_Soap_Server_TestClassService", $service->getName());
-        }
-    }
-
-    public function testParseExampleWsdlWithDocumentationBlocks()
-    {
-        $dom = new DOMDocument();
-        $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_documentation.wsdl"));
-
-        $parser = new Zend_Soap_Wsdl_Parser($dom);
-        $result = $parser->parse();
-    }
-}

+ 5 - 0
tests/Zend/Soap/_files/commontypes.php

@@ -430,6 +430,11 @@ class Zend_Soap_AutoDiscover_Recursion
      * @var Zend_Soap_AutoDiscover_Recursion
      */
     public $recursion;
+
+    /**
+     * @return Zend_Soap_AutoDiscover_Recursion
+     */
+    public function create() {}
 }
 
 /**