WsdlDownloader fix: remote includes now work correctly with relative URLs & tests added
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapClient\Xml\Path;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class RelativePathResolverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var RelativePathResolver */
|
||||
private $relativePathResolver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->relativePathResolver = new RelativePathResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $base
|
||||
* @param string $relative
|
||||
* @param string $assertPath
|
||||
* @dataProvider providePathInfo
|
||||
*/
|
||||
public function testResolveRelativePathInUrl($base, $relative, $assertPath)
|
||||
{
|
||||
$path = $this->relativePathResolver->resolveRelativePathInUrl($base, $relative);
|
||||
|
||||
self::assertEquals($assertPath, $path);
|
||||
}
|
||||
|
||||
public function providePathInfo()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'http://endpoint-location.ltd/',
|
||||
'Document1.xsd',
|
||||
'http://endpoint-location.ltd/Document1.xsd',
|
||||
],
|
||||
[
|
||||
'http://endpoint-location.ltd:8080/endpoint/',
|
||||
'../Schemas/Common/Document2.xsd',
|
||||
'http://endpoint-location.ltd:8080/Schemas/Common/Document2.xsd',
|
||||
],
|
||||
[
|
||||
'http://endpoint-location.ltd/',
|
||||
'../Schemas/Common/Document3.xsd',
|
||||
'http://endpoint-location.ltd/Schemas/Common/Document3.xsd',
|
||||
],
|
||||
[
|
||||
'http://endpoint-location.ltd/',
|
||||
'/Document4.xsd',
|
||||
'http://endpoint-location.ltd/Document4.xsd',
|
||||
],
|
||||
[
|
||||
'http://endpoint-location.ltd',
|
||||
'/Document5.xsd',
|
||||
'http://endpoint-location.ltd/Document5.xsd',
|
||||
],
|
||||
[
|
||||
'http://endpoint-location.ltd',
|
||||
'Document6.xsd',
|
||||
'http://endpoint-location.ltd/Document6.xsd',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapClient\Xml;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class RemoteFileResolverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
const FILE_IS_REMOTE = true;
|
||||
const FILE_IS_NOT_REMOTE = false;
|
||||
|
||||
/** @var RemoteFileResolver */
|
||||
private $remoteFileResolver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->remoteFileResolver = new RemoteFileResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $wsdlPath
|
||||
* @param bool $assertIsRemoteFile
|
||||
* @dataProvider provideWsdlPaths
|
||||
*/
|
||||
public function testIsRemoteFile($wsdlPath, $assertIsRemoteFile)
|
||||
{
|
||||
$isRemoteFile = $this->remoteFileResolver->isRemoteFile($wsdlPath);
|
||||
|
||||
self::assertEquals($assertIsRemoteFile, $isRemoteFile);
|
||||
}
|
||||
|
||||
public function provideWsdlPaths()
|
||||
{
|
||||
return [
|
||||
['http://endpoint.tld/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||
['http://endpoint.tld:1944/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||
['path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||
['../../path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||
['/path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapClient\Xml;
|
||||
|
||||
use BeSimple\SoapClient\Curl\Curl;
|
||||
use BeSimple\SoapClient\Curl\CurlOptionsBuilder;
|
||||
use BeSimple\SoapCommon\Cache;
|
||||
use BeSimple\SoapCommon\Helper;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class XmlDomDocumentImportReplacerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
const NO_PARENT_FILE_PATH = null;
|
||||
|
||||
/** @var XmlDomDocumentImportReplacer */
|
||||
private $xmlDomDocumentImportReplacer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->xmlDomDocumentImportReplacer = new XmlDomDocumentImportReplacer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xmlSource
|
||||
* @param Curl $curl
|
||||
* @param string $schemaPrefix
|
||||
* @param string $schemaUrl
|
||||
* @param string $locationAttributeName
|
||||
* @param string|null $parentFilePath
|
||||
* @param string|null $assertImportXmlSource
|
||||
* @dataProvider provideXmlDocumentData
|
||||
*/
|
||||
public function testUpdateXmlDocument(
|
||||
$xmlSource,
|
||||
Curl $curl,
|
||||
$schemaPrefix,
|
||||
$schemaUrl,
|
||||
$locationAttributeName,
|
||||
$parentFilePath = null,
|
||||
$assertImportXmlSource = null
|
||||
) {
|
||||
$wsdl = new DOMDocument();
|
||||
$wsdl->loadXML($xmlSource);
|
||||
|
||||
$this->xmlDomDocumentImportReplacer->updateXmlDocument(
|
||||
$curl,
|
||||
Cache::TYPE_NONE,
|
||||
new DOMXPath($wsdl),
|
||||
$schemaPrefix,
|
||||
$schemaUrl,
|
||||
$locationAttributeName,
|
||||
$parentFilePath
|
||||
);
|
||||
$wsdlSource = $wsdl->saveHTML();
|
||||
|
||||
self::assertContains(
|
||||
$assertImportXmlSource,
|
||||
$wsdlSource
|
||||
);
|
||||
}
|
||||
|
||||
public function provideXmlDocumentData()
|
||||
{
|
||||
return [
|
||||
'wsdlWithoutParentPath' => [
|
||||
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||
Helper::PFX_WSDL,
|
||||
Helper::NS_WSDL,
|
||||
'location',
|
||||
self::NO_PARENT_FILE_PATH,
|
||||
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||
],
|
||||
'schemaWithoutParentPath' => [
|
||||
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||
Helper::PFX_XML_SCHEMA,
|
||||
Helper::NS_XML_SCHEMA,
|
||||
'schemaLocation',
|
||||
self::NO_PARENT_FILE_PATH,
|
||||
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||
],
|
||||
'wsdlWithParentPath' => [
|
||||
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||
Helper::PFX_WSDL,
|
||||
Helper::NS_WSDL,
|
||||
'location',
|
||||
'http://endpoint-location.ltd:8080/endpoint/',
|
||||
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||
],
|
||||
'schemaWithParentPath' => [
|
||||
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||
Helper::PFX_XML_SCHEMA,
|
||||
Helper::NS_XML_SCHEMA,
|
||||
'schemaLocation',
|
||||
'http://endpoint-location.ltd:8080/endpoint/',
|
||||
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/Schemas/Common/Document1.xsd"></xs:include>'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions
|
||||
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
|
||||
xmlns:ns="http://location.ltd/namespace1"
|
||||
xmlns:ns2="http://location.ltd/namespace2"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://endpoint-location.tld:7654/ws"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema" name="PushServerWSDL"
|
||||
targetNamespace="http://location.ltd/target-namespace">
|
||||
<wsdl:types>
|
||||
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace1">
|
||||
<xs:include schemaLocation="../Schemas/Common/Document1.xsd"/>
|
||||
</xs:schema>
|
||||
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace2">
|
||||
<xs:include schemaLocation="../Schemas/Common/Document2.xsd"/>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="ServerHeader">
|
||||
<wsdl:part element="ns:serverHeader" name="serverHeader"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:portType name="Server">
|
||||
<wsdl:operation name="SendPushMessage">
|
||||
<wsdl:documentation>TEST-OPERATION-1</wsdl:documentation>
|
||||
<wsdl:input message="tns:SendPushMessageRequest" name="SendPushMessageRequest"/>
|
||||
<wsdl:output message="tns:SendPushMessageResponse" name="SendPushMessageResponse"/>
|
||||
<wsdl:fault message="tns:SystemFault" name="systemFault"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="ServerBinding" type="tns:Server">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="DummyMethod">
|
||||
<soap:operation soapAction="http://endpoint-location.tld:7654/ep/v1" style="document"/>
|
||||
<wsdl:input name="DummyMethodRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="DummyMethodResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="soapServerFault">
|
||||
<soap:fault name="soapServerFault" use="literal"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="ServerServices">
|
||||
<wsdl:port binding="tns:ServerBinding" name="ServerServicesEndpoint">
|
||||
<soap:address location="http://endpoint-location.tld:7654/ws/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
Reference in New Issue
Block a user