| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 |
- <?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-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Soap_ClientTest::main');
- }
- /** Zend_Soap_Server */
- require_once 'Zend/Soap/Server.php';
- /** Zend_Soap_Client */
- require_once 'Zend/Soap/Client.php';
- require_once 'Zend/Config.php';
- /**
- * @category Zend
- * @package Zend_Soap
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Soap
- */
- class Zend_Soap_ClientTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs this test suite
- *
- * @return void
- */
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- public function setUp()
- {
- if (!extension_loaded('soap')) {
- $this->markTestSkipped('SOAP Extension is not loaded');
- }
- }
- public function testSetOptions()
- {
- /*************************************************************
- * ------ Test WSDL mode options -----------------------------
- *************************************************************/
- $client = new Zend_Soap_Client();
- $this->assertTrue($client->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2));
- $ctx = stream_context_create();
- $nonWsdlOptions = array('soap_version' => SOAP_1_1,
- 'classmap' => array('TestData1' => 'Zend_Soap_Client_TestData1',
- 'TestData2' => 'Zend_Soap_Client_TestData2',),
- 'encoding' => 'ISO-8859-1',
- 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'use' => SOAP_ENCODED,
- 'style' => SOAP_RPC,
- 'login' => 'http_login',
- 'password' => 'http_password',
- 'proxy_host' => 'proxy.somehost.com',
- 'proxy_port' => 8080,
- 'proxy_login' => 'proxy_login',
- 'proxy_password' => 'proxy_password',
- 'local_cert' => dirname(__FILE__).'/_files/cert_file',
- 'passphrase' => 'some pass phrase',
- 'stream_context' => $ctx,
- 'cache_wsdl' => 8,
- 'features' => 4,
- 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5);
- $client->setOptions($nonWsdlOptions);
- $this->assertTrue($client->getOptions() == $nonWsdlOptions);
- /*************************************************************
- * ------ Test non-WSDL mode options -----------------------------
- *************************************************************/
- $client1 = new Zend_Soap_Client();
- $this->assertTrue($client1->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2));
- $wsdlOptions = array('soap_version' => SOAP_1_1,
- 'wsdl' => dirname(__FILE__).'/_files/wsdl_example.wsdl',
- 'classmap' => array('TestData1' => 'Zend_Soap_Client_TestData1',
- 'TestData2' => 'Zend_Soap_Client_TestData2',),
- 'encoding' => 'ISO-8859-1',
- 'login' => 'http_login',
- 'password' => 'http_password',
- 'proxy_host' => 'proxy.somehost.com',
- 'proxy_port' => 8080,
- 'proxy_login' => 'proxy_login',
- 'proxy_password' => 'proxy_password',
- 'local_cert' => dirname(__FILE__).'/_files/cert_file',
- 'passphrase' => 'some pass phrase',
- 'stream_context' => $ctx,
- 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5);
- $client1->setOptions($wsdlOptions);
- $this->assertTrue($client1->getOptions() == $wsdlOptions);
- }
- public function testGetOptions()
- {
- $client = new Zend_Soap_Client();
- $this->assertTrue($client->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2));
- $options = array('soap_version' => SOAP_1_1,
- 'wsdl' => dirname(__FILE__).'/_files/wsdl_example.wsdl',
- 'classmap' => array('TestData1' => 'Zend_Soap_Client_TestData1',
- 'TestData2' => 'Zend_Soap_Client_TestData2',),
- 'encoding' => 'ISO-8859-1',
- 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'use' => SOAP_ENCODED,
- 'style' => SOAP_RPC,
- 'login' => 'http_login',
- 'password' => 'http_password',
- 'proxy_host' => 'proxy.somehost.com',
- 'proxy_port' => 8080,
- 'proxy_login' => 'proxy_login',
- 'proxy_password' => 'proxy_password',
- 'local_cert' => dirname(__FILE__).'/_files/cert_file',
- 'passphrase' => 'some pass phrase',
- 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5);
- $client->setOptions($options);
- $this->assertTrue($client->getOptions() == $options);
- }
- /**
- * @group ZF-8053
- */
- public function testGetAndSetUserAgentOption()
- {
- $client = new Zend_Soap_Client();
- $this->assertNull($client->getUserAgent());
- $client->setUserAgent('agent1');
- $this->assertEquals('agent1', $client->getUserAgent());
- $client->setOptions(array(
- 'user_agent' => 'agent2'
- ));
- $this->assertEquals('agent2', $client->getUserAgent());
- $client->setOptions(array(
- 'useragent' => 'agent3'
- ));
- $this->assertEquals('agent3', $client->getUserAgent());
- $client->setOptions(array(
- 'userAgent' => 'agent4'
- ));
- $this->assertEquals('agent4', $client->getUserAgent());
- $options = $client->getOptions();
- $this->assertEquals('agent4', $options['user_agent']);
- }
- /**
- * @group ZF-6954
- */
- public function testUserAgentAllowsEmptyString()
- {
- $client = new Zend_Soap_Client();
- $this->assertNull($client->getUserAgent());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('user_agent', $options);
- $client->setUserAgent('');
- $this->assertEquals('', $client->getUserAgent());
- $options = $client->getOptions();
- $this->assertEquals('', $options['user_agent']);
- $client->setUserAgent(null);
- $this->assertNull($client->getUserAgent());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('user_agent', $options);
- }
- /**
- * @group ZF-10542
- */
- public function testAllowNumericZeroAsValueForCacheWsdlOption()
- {
- $client = new Zend_Soap_Client();
- $this->assertNull($client->getWsdlCache());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('cache_wsdl', $options);
- $client->setWsdlCache(WSDL_CACHE_NONE);
- $this->assertSame(WSDL_CACHE_NONE, $client->getWsdlCache());
- $options = $client->getOptions();
- $this->assertSame(WSDL_CACHE_NONE, $options['cache_wsdl']);
- $client->setWsdlCache(null);
- $this->assertNull($client->getWsdlCache());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('cache_wsdl', $options);
- }
- /**
- * @group ZF-10542
- */
- public function testAllowNumericZeroAsValueForCompressionOptions()
- {
- $client = new Zend_Soap_Client();
- $this->assertNull($client->getCompressionOptions());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('compression', $options);
- $client->setCompressionOptions(SOAP_COMPRESSION_GZIP);
- $this->assertSame(SOAP_COMPRESSION_GZIP, $client->getCompressionOptions());
- $options = $client->getOptions();
- $this->assertSame(SOAP_COMPRESSION_GZIP, $options['compression']);
- $client->setCompressionOptions(null);
- $this->assertNull($client->getCompressionOptions());
- $options = $client->getOptions();
- $this->assertArrayNotHasKey('compression', $options);
- }
- /**
- * @group GH-32
- */
- public function testGetAndSetExceptionsOption()
- {
- $client = new Zend_Soap_Client();
- $this->assertNull($client->getExceptions());
- $this->assertEquals(
- array(
- 'encoding' => 'UTF-8',
- 'soap_version' => 2,
- ),
- $client->getOptions()
- );
- $client->setExceptions(true);
- $this->assertTrue($client->getExceptions());
- $client->setExceptions(false);
- $this->assertFalse($client->getExceptions());
- $client->setOptions(array('exceptions' => true));
- $this->assertTrue($client->getExceptions());
- $client = new Zend_Soap_Client(null, array('exceptions' => false));
- $this->assertFalse($client->getExceptions());
- $this->assertEquals(
- array(
- 'encoding' => 'UTF-8',
- 'soap_version' => 2,
- 'exceptions' => false,
- ),
- $client->getOptions()
- );
- }
- public function testGetFunctions()
- {
- $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $server->setClass('Zend_Soap_Client_TestClass');
- $client = new Zend_Soap_Client_Local($server, dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $this->assertTrue($client->getFunctions() == array('string testFunc1()',
- 'string testFunc2(string $who)',
- 'string testFunc3(string $who, int $when)',
- 'string testFunc4()'));
- }
- /**
- * @todo Implement testGetTypes().
- */
- public function testGetTypes()
- {
- // Remove the following line when you implement this test.
- $this->markTestIncomplete(
- "This test has not been implemented yet."
- );
- }
- public function testGetLastRequest()
- {
- if (headers_sent()) {
- $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test');
- return;
- }
- $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $server->setClass('Zend_Soap_Client_TestClass');
- $client = new Zend_Soap_Client_Local($server, dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- // Perform request
- $client->testFunc2('World');
- $expectedRequest = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
- . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" '
- . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
- . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
- . 'xmlns:enc="http://www.w3.org/2003/05/soap-encoding">'
- . '<env:Body>'
- . '<env:testFunc2 env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">'
- . '<who xsi:type="xsd:string">World</who>'
- . '</env:testFunc2>'
- . '</env:Body>'
- . '</env:Envelope>' . "\n";
- $this->assertEquals($client->getLastRequest(), $expectedRequest);
- }
- public function testGetLastResponse()
- {
- if (headers_sent()) {
- $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test');
- return;
- }
- $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $server->setClass('Zend_Soap_Client_TestClass');
- $client = new Zend_Soap_Client_Local($server, dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- // Perform request
- $client->testFunc2('World');
- $expectedResponse = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
- . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" '
- . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
- . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
- . 'xmlns:enc="http://www.w3.org/2003/05/soap-encoding">'
- . '<env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">'
- . '<env:testFunc2Response env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">'
- . '<rpc:result>testFunc2Return</rpc:result>'
- . '<testFunc2Return xsi:type="xsd:string">Hello World!</testFunc2Return>'
- . '</env:testFunc2Response>'
- . '</env:Body>'
- . '</env:Envelope>' . "\n";
- $this->assertEquals($client->getLastResponse(), $expectedResponse);
- }
- public function testCallInvoke()
- {
- if (headers_sent()) {
- $this->markTestSkipped('Cannot run testCallInvoke() when headers have already been sent; enable output buffering to run this test');
- return;
- }
- $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $server->setClass('Zend_Soap_Client_TestClass');
- $client = new Zend_Soap_Client_Local($server, dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $this->assertEquals($client->testFunc2('World'), 'Hello World!');
- }
- public function testSetOptionsWithZendConfig()
- {
- $ctx = stream_context_create();
- $nonWsdlOptions = array('soap_version' => SOAP_1_1,
- 'classmap' => array('TestData1' => 'Zend_Soap_Client_TestData1',
- 'TestData2' => 'Zend_Soap_Client_TestData2',),
- 'encoding' => 'ISO-8859-1',
- 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php',
- 'use' => SOAP_ENCODED,
- 'style' => SOAP_RPC,
- 'login' => 'http_login',
- 'password' => 'http_password',
- 'proxy_host' => 'proxy.somehost.com',
- 'proxy_port' => 8080,
- 'proxy_login' => 'proxy_login',
- 'proxy_password' => 'proxy_password',
- 'local_cert' => dirname(__FILE__).'/_files/cert_file',
- 'passphrase' => 'some pass phrase',
- 'stream_context' => $ctx,
- 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
- );
- $config = new Zend_Config($nonWsdlOptions);
- $client = new Zend_Soap_Client(null, $config);
- $this->assertEquals($nonWsdlOptions, $client->getOptions());
- }
- public function testSetInputHeaders()
- {
- if (headers_sent()) {
- $this->markTestSkipped('Cannot run testSetInputHeaders() when headers have already been sent; enable output buffering to run this test');
- return;
- }
- $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- $server->setClass('Zend_Soap_Client_TestClass');
- $client = new Zend_Soap_Client_Local($server, dirname(__FILE__) . '/_files/wsdl_example.wsdl');
- // Add request header
- $client->addSoapInputHeader(new SoapHeader('http://www.example.com/namespace', 'MyHeader1', 'SOAP header content 1'));
- // Add permanent request header
- $client->addSoapInputHeader(new SoapHeader('http://www.example.com/namespace', 'MyHeader2', 'SOAP header content 2'), true);
- // Perform request
- $client->testFunc2('World');
- $expectedRequest = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
- . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" '
- . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
- . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
- . 'xmlns:ns1="http://www.example.com/namespace" '
- . 'xmlns:enc="http://www.w3.org/2003/05/soap-encoding">'
- . '<env:Header>'
- . '<ns1:MyHeader2>SOAP header content 2</ns1:MyHeader2>'
- . '<ns1:MyHeader1>SOAP header content 1</ns1:MyHeader1>'
- . '</env:Header>'
- . '<env:Body>'
- . '<env:testFunc2 env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">'
- . '<who xsi:type="xsd:string">World</who>'
- . '</env:testFunc2>'
- . '</env:Body>'
- . '</env:Envelope>' . "\n";
- $this->assertEquals($client->getLastRequest(), $expectedRequest);
- // Add request header
- $client->addSoapInputHeader(new SoapHeader('http://www.example.com/namespace', 'MyHeader3', 'SOAP header content 3'));
- // Perform request
- $client->testFunc2('World');
- $expectedRequest = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
- . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" '
- . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
- . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
- . 'xmlns:ns1="http://www.example.com/namespace" '
- . 'xmlns:enc="http://www.w3.org/2003/05/soap-encoding">'
- . '<env:Header>'
- . '<ns1:MyHeader2>SOAP header content 2</ns1:MyHeader2>'
- . '<ns1:MyHeader3>SOAP header content 3</ns1:MyHeader3>'
- . '</env:Header>'
- . '<env:Body>'
- . '<env:testFunc2 env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">'
- . '<who xsi:type="xsd:string">World</who>'
- . '</env:testFunc2>'
- . '</env:Body>'
- . '</env:Envelope>' . "\n";
- $this->assertEquals($client->getLastRequest(), $expectedRequest);
- $client->resetSoapInputHeaders();
- // Add request header
- $client->addSoapInputHeader(new SoapHeader('http://www.example.com/namespace', 'MyHeader4', 'SOAP header content 4'));
- // Perform request
- $client->testFunc2('World');
- $expectedRequest = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
- . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" '
- . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
- . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
- . 'xmlns:ns1="http://www.example.com/namespace" '
- . 'xmlns:enc="http://www.w3.org/2003/05/soap-encoding">'
- . '<env:Header>'
- . '<ns1:MyHeader4>SOAP header content 4</ns1:MyHeader4>'
- . '</env:Header>'
- . '<env:Body>'
- . '<env:testFunc2 env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">'
- . '<who xsi:type="xsd:string">World</who>'
- . '</env:testFunc2>'
- . '</env:Body>'
- . '</env:Envelope>' . "\n";
- $this->assertEquals($client->getLastRequest(), $expectedRequest);
- }
- /**
- * @group ZF-6955
- */
- public function testSetCookieIsDelegatedToSoapClient()
- {
- $fixtureCookieKey = "foo";
- $fixtureCookieValue = "bar";
- $clientMock = $this->getMock('SoapClient', array('__setCookie'), array(null, array('uri' => 'http://www.zend.com', 'location' => 'http://www.zend.com')));
- $clientMock->expects($this->once())
- ->method('__setCookie')
- ->with($fixtureCookieKey, $fixtureCookieValue);
- $soap = new Zend_Soap_Client();
- $soap->setSoapClient($clientMock);
- $soap->setCookie($fixtureCookieKey, $fixtureCookieValue);
- }
- public function testSetSoapClient()
- {
- $clientMock = $this->getMock('SoapClient', array('__setCookie'), array(null, array('uri' => 'http://www.zend.com', 'location' => 'http://www.zend.com')));
- $soap = new Zend_Soap_Client();
- $soap->setSoapClient($clientMock);
- $this->assertSame($clientMock, $soap->getSoapClient());
- }
- }
- /** Test Class */
- class Zend_Soap_Client_TestClass {
- /**
- * Test Function 1
- *
- * @return string
- */
- function testFunc1()
- {
- return "Hello World";
- }
- /**
- * Test Function 2
- *
- * @param string $who Some Arg
- * @return string
- */
- function testFunc2($who)
- {
- return "Hello $who!";
- }
- /**
- * Test Function 3
- *
- * @param string $who Some Arg
- * @param int $when Some
- * @return string
- */
- function testFunc3($who, $when)
- {
- return "Hello $who, How are you $when";
- }
- /**
- * Test Function 4
- *
- * @return string
- */
- static function testFunc4()
- {
- return "I'm Static!";
- }
- }
- /** Test class 2 */
- class Zend_Soap_Client_TestData1 {
- /**
- * Property1
- *
- * @var string
- */
- public $property1;
- /**
- * Property2
- *
- * @var float
- */
- public $property2;
- }
- /** Test class 2 */
- class Zend_Soap_Client_TestData2 {
- /**
- * Property1
- *
- * @var integer
- */
- public $property1;
- /**
- * Property1
- *
- * @var float
- */
- public $property2;
- }
- /* Test Functions */
- /**
- * Test Function
- *
- * @param string $arg
- * @return string
- */
- function Zend_Soap_Client_TestFunc1($who)
- {
- return "Hello $who";
- }
- /**
- * Test Function 2
- */
- function Zend_Soap_Client_TestFunc2()
- {
- return "Hello World";
- }
- /**
- * Return false
- *
- * @return bool
- */
- function Zend_Soap_Client_TestFunc3()
- {
- return false;
- }
- /**
- * Return true
- *
- * @return bool
- */
- function Zend_Soap_Client_TestFunc4()
- {
- return true;
- }
- /**
- * Return integer
- *
- * @return int
- */
- function Zend_Soap_Client_TestFunc5()
- {
- return 123;
- }
- /**
- * Return string
- *
- * @return string
- */
- function Zend_Soap_Client_TestFunc6()
- {
- return "string";
- }
- if (PHPUnit_MAIN_METHOD == 'Zend_Soap_ClientTest::main') {
- Zend_Soap_ClientTest::main();
- }
|