[\s]{1,}<)/', '', $xmlstring);
return $xmlstring;
}
function testSetClass()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->setClass('Zend_Soap_AutoDiscover_Test');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$wsdl = ''
. ''
. ''
. ''
. ''
. ''
. ''
. 'Test Function 1'
. ''
. ''
. ''
. ''
. 'Test Function 2'
. ''
. ''
. ''
. ''
. 'Test Function 3'
. ''
. ''
. ''
. 'Test Function 4'
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. '';
$dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
$this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
$this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/setclass.wsdl');
}
function testSetClassWithDifferentStyles()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com'));
$server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com'));
$server->setClass('Zend_Soap_AutoDiscover_Test');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$wsdl = ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. 'Test Function 1'
. ''
. ''
. ''
. ''
. 'Test Function 2'
. ''
. ''
. ''
. ''
. 'Test Function 3'
. ''
. ''
. ''
. 'Test Function 4'
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. ''
. '';
$dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
$this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
$this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/setclass.wsdl');
}
/**
* @group ZF-5072
*/
function testSetClassWithResponseReturnPartCompabilityMode()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->setClass('Zend_Soap_AutoDiscover_Test');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
$this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
$this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
$this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
$this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
unlink(dirname(__FILE__).'/_files/setclass.wsdl');
}
function testAddFunctionSimple()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
$parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
$name = $parts[0];
$wsdl = ''.
''.
''.
''.
'Test Function'.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
'';
$this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
$this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
}
function testAddFunctionSimpleWithDifferentStyle()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com'));
$server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com'));
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
$parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
$name = $parts[0];
$wsdl = ''.
''.
''.
''.
''.
''.
''.
''.
''.
'Test Function'.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
'';
$this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
$this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
}
/**
* @group ZF-5072
*/
function testAddFunctionSimpleInReturnNameCompabilityMode()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
$parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
$name = $parts[0];
$wsdl = $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML());
$this->assertContains('', $wsdl);
$this->assertNotContains('assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
}
function testAddFunctionMultiple()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc2');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc3');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc4');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc5');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc6');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc7');
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc9');
$dom = new DOMDocument();
ob_start();
$server->handle();
$dom->loadXML(ob_get_clean());
$dom->save(dirname(__FILE__).'/_files/addfunction2.wsdl');
$parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
$name = $parts[0];
$wsdl = ''.
''.
''.
''.
'Test Function'.
'Test Function 2'.
'Return false'.
'Return true'.
'Return integer'.
'Return string'.
'Return array'.
'Multiple Args'.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
'';
$this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML");
$this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
unlink(dirname(__FILE__).'/_files/addfunction2.wsdl');
}
/**
* @group ZF-4117
*/
public function testUseHttpsSchemaIfAccessedThroughHttps()
{
$_SERVER['HTTPS'] = "on";
$httpsScriptUri = 'https://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertContains($httpsScriptUri, $wsdlOutput);
}
/**
* @group ZF-4117
*/
public function testChangeWsdlUriInConstructor()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover(true, "http://example.com/service.php");
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertNotContains($scriptUri, $wsdlOutput);
$this->assertContains("http://example.com/service.php", $wsdlOutput);
}
/**
* @group ZF-4117
*/
public function testChangeWsdlUriViaSetUri()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover(true);
$server->setUri("http://example.com/service.php");
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertNotContains($scriptUri, $wsdlOutput);
$this->assertContains("http://example.com/service.php", $wsdlOutput);
}
public function testSetNonStringNonZendUriUriThrowsException()
{
$server = new Zend_Soap_AutoDiscover();
try {
$server->setUri(array("bogus"));
$this->fail();
} catch(Zend_Soap_AutoDiscover_Exception $e) {
}
}
/**
* @group ZF-4117
*/
public function testChangingWsdlUriAfterGenerationIsPossible()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover(true);
$server->setUri("http://example.com/service.php");
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertNotContains($scriptUri, $wsdlOutput);
$this->assertContains("http://example.com/service.php", $wsdlOutput);
$server->setUri("http://example2.com/service2.php");
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertNotContains($scriptUri, $wsdlOutput);
$this->assertNotContains("http://example.com/service.php", $wsdlOutput);
$this->assertContains("http://example2.com/service2.php", $wsdlOutput);
}
/**
* @group ZF-4688
* @group ZF-4125
*
*/
public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl()
{
$scriptUri = 'http://localhost/my_script.php';
$server = new Zend_Soap_AutoDiscover();
$server->setClass('Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertEquals(1, substr_count($wsdlOutput, ''));
$this->assertEquals(1, substr_count($wsdlOutput, ''));
}
public function testUnusedFunctionsOfAutoDiscoverThrowException()
{
$server = new Zend_Soap_AutoDiscover();
try {
$server->setPersistence("bogus");
$this->fail();
} catch(Zend_Soap_AutoDiscover_Exception $e) {
}
try {
$server->fault();
$this->fail();
} catch(Zend_Soap_AutoDiscover_Exception $e) {
}
try {
$server->loadFunctions("bogus");
$this->fail();
} catch(Zend_Soap_AutoDiscover_Exception $e) {
}
}
public function testGetFunctions()
{
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
$server->setClass('Zend_Soap_AutoDiscover_Test');
$functions = $server->getFunctions();
$this->assertEquals(
array('Zend_Soap_AutoDiscover_TestFunc', 'testFunc1', 'testFunc2', 'testFunc3', 'testFunc4'),
$functions
);
}
/**
* @group ZF-4835
*/
public function testUsingRequestUriWithoutParametersAsDefault()
{
// Apache
$_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost');
$server = new Zend_Soap_AutoDiscover();
$uri = $server->getUri()->getUri();
$this->assertNotContains("?wsdl", $uri);
$this->assertEquals("http://localhost/my_script.php", $uri);
// Apache plus SSL
$_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost', 'HTTPS' => 'on');
$server = new Zend_Soap_AutoDiscover();
$uri = $server->getUri()->getUri();
$this->assertNotContains("?wsdl", $uri);
$this->assertEquals("https://localhost/my_script.php", $uri);
// IIS 5 + PHP as FastCGI
$_SERVER = array('ORIG_PATH_INFO' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
$server = new Zend_Soap_AutoDiscover();
$uri = $server->getUri()->getUri();
$this->assertNotContains("?wsdl", $uri);
$this->assertEquals("http://localhost/my_script.php", $uri);
// IIS
$_SERVER = array('HTTP_X_REWRITE_URL' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
$server = new Zend_Soap_AutoDiscover();
$uri = $server->getUri()->getUri();
$this->assertNotContains("?wsdl", $uri);
$this->assertEquals("http://localhost/my_script.php", $uri);
}
/**
* @group ZF-4937
*/
public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce()
{
$server = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
$server->setClass('Zend_Soap_AutoDiscoverTestClass2');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertEquals(1,
substr_count($wsdlOutput, 'wsdl:arrayType="tns:Zend_Soap_AutoDiscoverTestClass1[]"'),
'wsdl:arrayType definition of TestClass1 has to occour once.'
);
$this->assertEquals(1,
substr_count($wsdlOutput, ''),
'Zend_Soap_AutoDiscoverTestClass1 has to be defined once.'
);
$this->assertEquals(1,
substr_count($wsdlOutput, ''),
'ArrayOfZend_Soap_AutoDiscoverTestClass1 should be defined once.'
);
$this->assertTrue(
substr_count($wsdlOutput, '') >= 1,
'Zend_Soap_AutoDiscoverTestClass1 appears once or more than once in the message parts section.'
);
}
/**
* @group ZF-5330
*/
public function testDumpOrXmlOfAutoDiscover()
{
$server = new Zend_Soap_AutoDiscover();
$server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
ob_start();
$server->handle();
$wsdlOutput = ob_get_clean();
$this->assertEquals(
$this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
$this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
);
ob_start();
$server->dump(false);
$wsdlOutput = ob_get_clean();
$this->assertEquals(
$this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
$this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
);
}
/**
* @group ZF-5330
*/
public function testDumpOrXmlOnlyAfterGeneratedAutoDiscoverWsdl()
{
$server = new Zend_Soap_AutoDiscover();
try {
$server->dump(false);
$this->fail();
} catch(Exception $e) {
$this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
}
try {
$server->toXml();
$this->fail();
} catch(Exception $e) {
$this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
}
}
/**
* @group ZF-5604
*/
public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex()
{
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
$autodiscover->setClass('Zend_Soap_AutoDiscover_MyService');
$wsdl = $autodiscover->toXml();
$this->assertEquals(1, substr_count($wsdl, ''));
$this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]'));
}
/**
* @group ZF-5430
*/
public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence()
{
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover->setClass('Zend_Soap_AutoDiscover_MyServiceSequence');
$wsdl = $autodiscover->toXml();
$this->assertEquals(1, substr_count($wsdl, ''));
$this->assertEquals(1, substr_count($wsdl, ''));
$this->assertEquals(1, substr_count($wsdl, ''));
$this->assertEquals(0, substr_count($wsdl, 'tns:string[]'));
}
/**
* @group ZF-5736
*/
public function testAmpersandInUrlIsCorrectlyEncoded()
{
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setUri("http://example.com/?a=b&b=c");
$autodiscover->setClass("Zend_Soap_AutoDiscover_Test");
$wsdl = $autodiscover->toXml();
$this->assertContains("http://example.com/?a=b&b=c", $wsdl);
}
/**
* @group ZF-6689
*/
public function testNoReturnIsOneWayCallInSetClass()
{
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Zend_Soap_AutoDiscover_NoReturnType');
$wsdl = $autodiscover->toXml();
$this->assertContains(
'@param string $message',
$wsdl
);
}
/**
* @group ZF-6689
*/
public function testNoReturnIsOneWayCallInAddFunction()
{
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->addFunction('Zend_Soap_AutoDiscover_OneWay');
$wsdl = $autodiscover->toXml();
$this->assertContains(
'@param string $message',
$wsdl
);
}
}