| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- <?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_XmlRpc
- * @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$
- */
- require_once 'Zend/XmlRpc/Client.php';
- require_once 'Zend/XmlRpc/Response.php';
- require_once 'Zend/Http/Client/Adapter/Test.php';
- require_once 'Zend/XmlRpc/Value/DateTime.php';
- require_once 'Zend/XmlRpc/Client/ServerIntrospection.php';
- require_once 'Zend/Http/Client.php';
- /**
- * Test case for Zend_XmlRpc_Value
- *
- * @category Zend
- * @package Zend_XmlRpc
- * @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_XmlRpc
- */
- class Zend_XmlRpc_ClientTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Zend_Http_Client_Adapter_Abstract
- */
- protected $httpAdapter;
- /**
- * @var Zend_Http_Client
- */
- protected $httpClient;
- /**
- * @var Zend_XmlRpc_Client
- */
- protected $xmlrpcClient;
- public function setUp()
- {
- $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
- $this->httpClient = new Zend_Http_Client('http://foo',
- array('adapter' => $this->httpAdapter));
- $this->xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
- $this->xmlrpcClient->setHttpClient($this->httpClient);
- }
- // HTTP Client
- public function testGettingDefaultHttpClient()
- {
- $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
- $httpClient = $xmlrpcClient->getHttpClient();
- $this->assertTrue($httpClient instanceof Zend_Http_Client);
- $this->assertSame($httpClient, $xmlrpcClient->getHttpClient());
- }
- public function testSettingAndGettingHttpClient()
- {
- $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
- $httpClient = new Zend_Http_Client('http://foo');
- $this->assertNotSame($httpClient, $xmlrpcClient->getHttpClient());
- $xmlrpcClient->setHttpClient($httpClient);
- $this->assertSame($httpClient, $xmlrpcClient->getHttpClient());
- }
- public function testSettingHttpClientViaContructor()
- {
- $xmlrpcClient = new Zend_XmlRpc_Client('http://foo', $this->httpClient);
- $httpClient = $xmlrpcClient->getHttpClient();
- $this->assertSame($this->httpClient, $httpClient);
- }
- // Request & Response
- public function testLastRequestAndResponseAreInitiallyNull()
- {
- $this->assertNull($this->xmlrpcClient->getLastRequest());
- $this->assertNull($this->xmlrpcClient->getLastResponse());
- }
- public function testLastRequestAndResponseAreSetAfterRpcMethodCall()
- {
- $this->setServerResponseTo(true);
- $this->xmlrpcClient->call('foo');
- $this->assertTrue($this->xmlrpcClient->getLastRequest() instanceof Zend_XmlRpc_Request);
- $this->assertTrue($this->xmlrpcClient->getLastResponse() instanceof Zend_XmlRpc_Response);
- }
- public function testSuccessfulRpcMethodCallWithNoParameters()
- {
- $expectedMethod = 'foo.bar';
- $expectedReturn = 7;
- $this->setServerResponseTo($expectedReturn);
- $this->assertSame($expectedReturn, $this->xmlrpcClient->call($expectedMethod));
- $request = $this->xmlrpcClient->getLastRequest();
- $response = $this->xmlrpcClient->getLastResponse();
- $this->assertSame($expectedMethod, $request->getMethod());
- $this->assertSame(array(), $request->getParams());
- $this->assertSame($expectedReturn, $response->getReturnValue());
- $this->assertFalse($response->isFault());
- }
- public function testSuccessfulRpcMethodCallWithParameters()
- {
- $expectedMethod = 'foo.bar';
- $expectedParams = array(1, 'foo' => 'bar', 1.1, true);
- $expectedReturn = array(7, false, 'foo' => 'bar');
- $this->setServerResponseTo($expectedReturn);
- $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
- $this->assertSame($expectedReturn, $actualReturn);
- $request = $this->xmlrpcClient->getLastRequest();
- $response = $this->xmlrpcClient->getLastResponse();
- $this->assertSame($expectedMethod, $request->getMethod());
- $params = $request->getParams();
- $this->assertSame(count($expectedParams), count($params));
- $this->assertSame($expectedParams[0], $params[0]->getValue());
- $this->assertSame($expectedParams[1], $params[1]->getValue());
- $this->assertSame($expectedParams[2], $params[2]->getValue());
- $this->assertSame($expectedParams['foo'], $params['foo']->getValue());
- $this->assertSame($expectedReturn, $response->getReturnValue());
- $this->assertFalse($response->isFault());
- }
- /**
- * @group ZF-2090
- */
- public function testSuccessfullyDetectsEmptyArrayParameterAsArray()
- {
- $expectedMethod = 'foo.bar';
- $expectedParams = array(array());
- $expectedReturn = array(true);
- $this->setServerResponseTo($expectedReturn);
- $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
- $this->assertSame($expectedReturn, $actualReturn);
- $request = $this->xmlrpcClient->getLastRequest();
- $params = $request->getParams();
- $this->assertSame(count($expectedParams), count($params));
- $this->assertSame($expectedParams[0], $params[0]->getValue());
- }
- /**
- * @group ZF-1412
- *
- * @return void
- */
- public function testSuccessfulRpcMethodCallWithMixedDateParameters()
- {
- $time = time();
- $expectedMethod = 'foo.bar';
- $expectedParams = array(
- 'username',
- new Zend_XmlRpc_Value_DateTime($time)
- );
- $expectedReturn = array('username', $time);
- $this->setServerResponseTo($expectedReturn);
- $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
- $this->assertSame($expectedReturn, $actualReturn);
- $request = $this->xmlrpcClient->getLastRequest();
- $response = $this->xmlrpcClient->getLastResponse();
- $this->assertSame($expectedMethod, $request->getMethod());
- $params = $request->getParams();
- $this->assertSame(count($expectedParams), count($params));
- $this->assertSame($expectedParams[0], $params[0]->getValue());
- $this->assertSame($expectedParams[1], $params[1]);
- $this->assertSame($expectedReturn, $response->getReturnValue());
- $this->assertFalse($response->isFault());
- }
- /**
- * @group ZF-1797
- */
- public function testSuccesfulRpcMethodCallWithXmlRpcValueParameters()
- {
- $time = time();
- $params = array(
- new Zend_XmlRpc_Value_Boolean(true),
- new Zend_XmlRpc_Value_Integer(4),
- new Zend_XmlRpc_Value_String('foo')
- );
- $expect = array(true, 4, 'foo');
- $this->setServerResponseTo($expect);
- $result = $this->xmlrpcClient->call('foo.bar', $params);
- $this->assertSame($expect, $result);
- $request = $this->xmlrpcClient->getLastRequest();
- $response = $this->xmlrpcClient->getLastResponse();
- $this->assertSame('foo.bar', $request->getMethod());
- $this->assertSame($params, $request->getParams());
- $this->assertSame($expect, $response->getReturnValue());
- $this->assertFalse($response->isFault());
- }
- /**
- * @group ZF-2978
- */
- public function testSkippingSystemCallDisabledByDefault()
- {
- $this->assertFalse($this->xmlrpcClient->skipSystemLookup());
- }
- /**
- * @group ZF-6993
- */
- public function testWhenPassingAStringAndAnIntegerIsExpectedParamIsConverted()
- {
- $this->mockIntrospector();
- $this->mockedIntrospector
- ->expects($this->exactly(2))
- ->method('getMethodSignature')
- ->with('test.method')
- ->will($this->returnValue(array(array('parameters' => array('int')))));
- $expect = 'test.method response';
- $this->setServerResponseTo($expect);
- $this->assertSame($expect, $this->xmlrpcClient->call('test.method', array('1')));
- $params = $this->xmlrpcClient->getLastRequest()->getParams();
- $this->assertSame(1, $params[0]->getValue());
- $this->setServerResponseTo($expect);
- $this->assertSame($expect, $this->xmlrpcClient->call('test.method', '1'));
- $params = $this->xmlrpcClient->getLastRequest()->getParams();
- $this->assertSame(1, $params[0]->getValue());
- }
- /**
- * @group ZF-8074
- */
- public function testXmlRpcObjectsAreNotConverted()
- {
- $this->mockIntrospector();
- $this->mockedIntrospector
- ->expects($this->exactly(1))
- ->method('getMethodSignature')
- ->with('date.method')
- ->will($this->returnValue(array(array('parameters' => array('dateTime.iso8601', 'string')))));
- $expects = 'date.method response';
- $this->setServerResponseTo($expects);
- $this->assertSame($expects, $this->xmlrpcClient->call('date.method', array(Zend_XmlRpc_Value::getXmlRpcValue(time(), Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME), 'foo')));
- }
- public function testAllowsSkippingSystemCallForArrayStructLookup()
- {
- $this->xmlrpcClient->setSkipSystemLookup(true);
- $this->assertTrue($this->xmlrpcClient->skipSystemLookup());
- }
- public function testSkipsSystemCallWhenDirected()
- {
- $this->mockHttpClient();
- $this->mockedHttpClient->expects($this->once())
- ->method('request')
- ->with('POST')
- ->will($this->returnValue($this->makeHttpResponseFor('foo')));
- $this->xmlrpcClient->setHttpClient($this->mockedHttpClient);
- $this->xmlrpcClient->setSkipSystemLookup(true);
- $this->assertSame('foo', $this->xmlrpcClient->call('test.method'));
- }
- /**#@-*/
- // Faults
- public function testRpcMethodCallThrowsOnHttpFailure()
- {
- $status = 404;
- $message = 'Not Found';
- $body = 'oops';
- $response = $this->makeHttpResponseFrom($body, $status, $message);
- $this->httpAdapter->setResponse($response);
- try {
- $this->xmlrpcClient->call('foo');
- $this->fail();
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_XmlRpc_Client_HttpException);
- $this->assertEquals($message, $e->getMessage());
- $this->assertEquals($status, $e->getCode());
- }
- }
- public function testRpcMethodCallThrowsOnXmlRpcFault()
- {
- $code = 9;
- $message = 'foo';
- $fault = new Zend_XmlRpc_Fault($code, $message);
- $xml = $fault->saveXml();
- $response = $this->makeHttpResponseFrom($xml);
- $this->httpAdapter->setResponse($response);
- try {
- $this->xmlrpcClient->call('foo');
- $this->fail();
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_XmlRpc_Client_FaultException);
- $this->assertEquals($message, $e->getMessage());
- $this->assertEquals($code, $e->getCode());
- }
- }
- // Server Proxy
- public function testGetProxyReturnsServerProxy()
- {
- $class = 'Zend_XmlRpc_Client_ServerProxy';
- $this->assertTrue($this->xmlrpcClient->getProxy() instanceof $class);
- }
- public function testRpcMethodCallsThroughServerProxy()
- {
- $expectedReturn = array(7, false, 'foo' => 'bar');
- $this->setServerResponseTo($expectedReturn);
- $server = $this->xmlrpcClient->getProxy();
- $this->assertSame($expectedReturn, $server->listMethods());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('listMethods', $request->getMethod());
- }
- public function testRpcMethodCallsThroughNestedServerProxies()
- {
- $expectedReturn = array(7, false, 'foo' => 'bar');
- $this->setServerResponseTo($expectedReturn);
- $server = $this->xmlrpcClient->getProxy('foo');
- $this->assertSame($expectedReturn, $server->bar->baz->boo());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('foo.bar.baz.boo', $request->getMethod());
- }
- public function testClientCachesServerProxies()
- {
- $proxy = $this->xmlrpcClient->getProxy();
- $this->assertSame($proxy, $this->xmlrpcClient->getProxy());
- $proxy = $this->xmlrpcClient->getProxy('foo');
- $this->assertSame($proxy, $this->xmlrpcClient->getProxy('foo'));
- }
- public function testServerProxyCachesNestedProxies()
- {
- $proxy = $this->xmlrpcClient->getProxy();
- $foo = $proxy->foo;
- $this->assertSame($foo, $proxy->foo);
- $bar = $proxy->foo->bar;
- $this->assertSame($bar, $proxy->foo->bar);
- }
- // Introspection
- public function testGettingDefaultIntrospector()
- {
- $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
- $introspector = $xmlrpcClient->getIntrospector();
- $this->assertTrue($introspector instanceof Zend_XmlRpc_Client_ServerIntrospection);
- $this->assertSame($introspector, $xmlrpcClient->getIntrospector());
- }
- public function testSettingAndGettingIntrospector()
- {
- $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
- $introspector = new Zend_XmlRpc_Client_ServerIntrospection($xmlrpcClient);
- $this->assertNotSame($introspector, $xmlrpcClient->getIntrospector());
- $xmlrpcClient->setIntrospector($introspector);
- $this->assertSame($introspector, $xmlrpcClient->getIntrospector());
- }
- public function testGettingMethodSignature()
- {
- $method = 'foo';
- $signatures = array(array('int', 'int', 'int'));
- $this->setServerResponseTo($signatures);
- $i = $this->xmlrpcClient->getIntrospector();
- $this->assertEquals($signatures, $i->getMethodSignature($method));
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.methodSignature', $request->getMethod());
- $this->assertEquals(array($method), $request->getParams());
- }
- public function testListingMethods()
- {
- $methods = array('foo', 'bar', 'baz');
- $this->setServerResponseTo($methods);
- $i = $this->xmlrpcClient->getIntrospector();
- $this->assertEquals($methods, $i->listMethods());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.listMethods', $request->getMethod());
- $this->assertEquals(array(), $request->getParams());
- }
- public function testGettingAllMethodSignaturesByLooping()
- {
- // system.listMethods() will return ['foo', 'bar']
- $methods = array('foo', 'bar');
- $response = $this->getServerResponseFor($methods);
- $this->httpAdapter->setResponse($response);
- // system.methodSignature('foo') will return [['int'], ['int', 'string']]
- $fooSignatures = array(array('int'), array('int', 'string'));
- $response = $this->getServerResponseFor($fooSignatures);
- $this->httpAdapter->addResponse($response);
- // system.methodSignature('bar') will return [['boolean']]
- $barSignatures = array(array('boolean'));
- $response = $this->getServerResponseFor($barSignatures);
- $this->httpAdapter->addResponse($response);
- $expected = array('foo' => $fooSignatures,
- 'bar' => $barSignatures);
- $i = $this->xmlrpcClient->getIntrospector();
- $this->assertEquals($expected, $i->getSignatureForEachMethodByLooping());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.methodSignature', $request->getMethod());
- $this->assertEquals(array('bar'), $request->getParams());
- }
- public function testGettingAllMethodSignaturesByMulticall()
- {
- // system.listMethods() will return ['foo', 'bar']
- $whatListMethodsReturns = array('foo', 'bar');
- $response = $this->getServerResponseFor($whatListMethodsReturns);
- $this->httpAdapter->setResponse($response);
- // after system.listMethods(), these system.multicall() params are expected
- $multicallParams = array(array('methodName' => 'system.methodSignature',
- 'params' => array('foo')),
- array('methodName' => 'system.methodSignature',
- 'params' => array('bar')));
- // system.multicall() will then return [fooSignatures, barSignatures]
- $fooSignatures = array(array('int'), array('int', 'string'));
- $barSignatures = array(array('boolean'));
- $whatMulticallReturns = array($fooSignatures, $barSignatures);
- $response = $this->getServerResponseFor($whatMulticallReturns);
- $this->httpAdapter->addResponse($response);
- $i = $this->xmlrpcClient->getIntrospector();
- $expected = array('foo' => $fooSignatures,
- 'bar' => $barSignatures);
- $this->assertEquals($expected, $i->getSignatureForEachMethodByMulticall());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.multicall', $request->getMethod());
- $this->assertEquals(array($multicallParams), $request->getParams());
- }
- public function testGettingAllMethodSignaturesByMulticallThrowsOnBadCount()
- {
- // system.listMethods() will return ['foo', 'bar']
- $whatListMethodsReturns = array('foo', 'bar');
- $response = $this->getServerResponseFor($whatListMethodsReturns);
- $this->httpAdapter->setResponse($response);
- // system.multicall() will then return only [fooSignatures]
- $fooSignatures = array(array('int'), array('int', 'string'));
- $whatMulticallReturns = array($fooSignatures); // error! no bar signatures!
- $response = $this->getServerResponseFor($whatMulticallReturns);
- $this->httpAdapter->addResponse($response);
- $i = $this->xmlrpcClient->getIntrospector();
- try {
- $i->getSignatureForEachMethodByMulticall();
- } catch (Zend_XmlRpc_Client_IntrospectException $e) {
- $this->assertRegexp('/bad number/i', $e->getMessage());
- }
- }
- public function testGettingAllMethodSignaturesByMulticallThrowsOnBadType()
- {
- // system.listMethods() will return ['foo', 'bar']
- $whatListMethodsReturns = array('foo', 'bar');
- $response = $this->getServerResponseFor($whatListMethodsReturns);
- $this->httpAdapter->setResponse($response);
- // system.multicall() will then return only an int
- $whatMulticallReturns = 1; // error! no signatures?
- $response = $this->getServerResponseFor($whatMulticallReturns);
- $this->httpAdapter->addResponse($response);
- $i = $this->xmlrpcClient->getIntrospector();
- try {
- $i->getSignatureForEachMethodByMulticall();
- } catch (Zend_XmlRpc_Client_IntrospectException $e) {
- $this->assertRegexp('/got integer/i', $e->getMessage());
- }
- }
- public function testGettingAllMethodSignaturesDefaultsToMulticall()
- {
- // system.listMethods() will return ['foo', 'bar']
- $whatListMethodsReturns = array('foo', 'bar');
- $response = $this->getServerResponseFor($whatListMethodsReturns);
- $this->httpAdapter->setResponse($response);
- // system.multicall() will then return [fooSignatures, barSignatures]
- $fooSignatures = array(array('int'), array('int', 'string'));
- $barSignatures = array(array('boolean'));
- $whatMulticallReturns = array($fooSignatures, $barSignatures);
- $response = $this->getServerResponseFor($whatMulticallReturns);
- $this->httpAdapter->addResponse($response);
- $i = $this->xmlrpcClient->getIntrospector();
- $expected = array('foo' => $fooSignatures,
- 'bar' => $barSignatures);
- $this->assertEquals($expected, $i->getSignatureForEachMethod());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.multicall', $request->getMethod());
- }
- public function testGettingAllMethodSignaturesDegradesToLooping()
- {
- // system.listMethods() will return ['foo', 'bar']
- $whatListMethodsReturns = array('foo', 'bar');
- $response = $this->getServerResponseFor($whatListMethodsReturns);
- $this->httpAdapter->setResponse($response);
- // system.multicall() will return a fault
- $fault = new Zend_XmlRpc_Fault(7, 'bad method');
- $xml = $fault->saveXml();
- $response = $this->makeHttpResponseFrom($xml);
- $this->httpAdapter->addResponse($response);
- // system.methodSignature('foo') will return [['int'], ['int', 'string']]
- $fooSignatures = array(array('int'), array('int', 'string'));
- $response = $this->getServerResponseFor($fooSignatures);
- $this->httpAdapter->addResponse($response);
- // system.methodSignature('bar') will return [['boolean']]
- $barSignatures = array(array('boolean'));
- $response = $this->getServerResponseFor($barSignatures);
- $this->httpAdapter->addResponse($response);
- $i = $this->xmlrpcClient->getIntrospector();
- $expected = array('foo' => $fooSignatures,
- 'bar' => $barSignatures);
- $this->assertEquals($expected, $i->getSignatureForEachMethod());
- $request = $this->xmlrpcClient->getLastRequest();
- $this->assertEquals('system.methodSignature', $request->getMethod());
- }
- /**
- * @group ZF-4372
- */
- public function testSettingUriOnHttpClientIsNotOverwrittenByXmlRpcClient()
- {
- $changedUri = "http://bar:80";
- // Overwrite: http://foo:80
- $this->setServerResponseTo(array());
- $this->xmlrpcClient->getHttpClient()->setUri($changedUri);
- $this->xmlrpcClient->call("foo");
- $uri = $this->xmlrpcClient->getHttpClient()->getUri(true);
- $this->assertEquals($changedUri, $uri);
- }
- /**
- * @group ZF-4372
- */
- public function testSettingNoHttpClientUriForcesClientToSetUri()
- {
- $baseUri = "http://foo:80";
- $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
- $this->httpClient = new Zend_Http_Client(null, array('adapter' => $this->httpAdapter));
- $this->xmlrpcClient = new Zend_XmlRpc_Client($baseUri);
- $this->xmlrpcClient->setHttpClient($this->httpClient);
- $this->setServerResponseTo(array());
- $this->assertNull($this->xmlrpcClient->getHttpClient()->getUri());
- $this->xmlrpcClient->call("foo");
- $uri = $this->xmlrpcClient->getHttpClient()->getUri(true);
- $this->assertEquals($baseUri, $uri);
- }
- /**
- * @group ZF-3288
- */
- public function testCustomHttpClientUserAgentIsNotOverridden()
- {
- $this->assertNull(
- $this->httpClient->getHeader('user-agent'),
- 'UA is null if no request was made'
- );
- $this->setServerResponseTo(true);
- $this->assertTrue($this->xmlrpcClient->call('method'));
- $this->assertSame(
- 'Zend_XmlRpc_Client',
- $this->httpClient->getHeader('user-agent'),
- 'If no custom UA is set, set Zend_XmlRpc_Client'
- );
- $expectedUserAgent = 'Zend_XmlRpc_Client (custom)';
- $this->httpClient->setHeaders(array('user-agent' => $expectedUserAgent));
- $this->setServerResponseTo(true);
- $this->assertTrue($this->xmlrpcClient->call('method'));
- $this->assertSame($expectedUserAgent, $this->httpClient->getHeader('user-agent'));
- }
- /**
- * @group ZF-8478
- */
- public function testPythonSimpleXMLRPCServerWithUnsupportedMethodSignatures()
- {
- try
- {
- $introspector = new Zend_XmlRpc_Client_ServerIntrospection(
- new Test_XmlRpc_Client('http://localhost/')
- );
- $signature = $introspector->getMethodSignature('add');
- if (!is_array($signature)) {
- $this->fail('Expected exception has not been thrown');
- }
- }
- catch (Zend_XmlRpc_Client_IntrospectException $e) {
- $this->assertEquals('Invalid signature for method "add"', $e->getMessage());
- }
- }
- /**
- * @group ZF-8580
- */
- public function testCallSelectsCorrectSignatureIfMoreThanOneIsAvailable()
- {
- $this->mockIntrospector();
- $this->mockedIntrospector
- ->expects($this->exactly(2))
- ->method('getMethodSignature')
- ->with('get')
- ->will($this->returnValue(array(
- array('parameters' => array('int')),
- array('parameters' => array('array'))
- )));
- $expectedResult = 'array';
- $this->setServerResponseTo($expectedResult);
- $this->assertSame(
- $expectedResult,
- $this->xmlrpcClient->call('get', array(array(1)))
- );
- $expectedResult = 'integer';
- $this->setServerResponseTo($expectedResult);
- $this->assertSame(
- $expectedResult,
- $this->xmlrpcClient->call('get', array(1))
- );
- }
-
- /**
- * @group ZF-1897
- */
- public function testHandlesLeadingOrTrailingWhitespaceInChunkedResponseProperly()
- {
- $baseUri = "http://foo:80";
- $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
- $this->httpClient = new Zend_Http_Client(null, array('adapter' => $this->httpAdapter));
-
- $respBody = file_get_contents(dirname(__FILE__) . "/_files/ZF1897-response-chunked.txt");
- $this->httpAdapter->setResponse($respBody);
- $this->xmlrpcClient = new Zend_XmlRpc_Client($baseUri);
- $this->xmlrpcClient->setHttpClient($this->httpClient);
-
- $this->assertEquals('FOO', $this->xmlrpcClient->call('foo'));
- }
- // Helpers
- public function setServerResponseTo($nativeVars)
- {
- $response = $this->getServerResponseFor($nativeVars);
- $this->httpAdapter->setResponse($response);
- }
- public function getServerResponseFor($nativeVars)
- {
- $response = new Zend_XmlRpc_Response();
- $response->setReturnValue($nativeVars);
- $xml = $response->saveXml();
- $response = $this->makeHttpResponseFrom($xml);
- return $response;
- }
- public function makeHttpResponseFrom($data, $status=200, $message='OK')
- {
- $headers = array("HTTP/1.1 $status $message",
- "Status: $status",
- 'Content_Type: text/xml; charset=utf-8',
- 'Content-Length: ' . strlen($data)
- );
- return implode("\r\n", $headers) . "\r\n\r\n$data\r\n\r\n";
- }
- public function makeHttpResponseFor($nativeVars)
- {
- $response = $this->getServerResponseFor($nativeVars);
- return Zend_Http_Response::fromString($response);
- }
- public function mockIntrospector()
- {
- $this->mockedIntrospector = $this->getMock(
- 'Zend_XmlRpc_Client_ServerIntrospection',
- array(),
- array(),
- '',
- false,
- false
- );
- $this->xmlrpcClient->setIntrospector($this->mockedIntrospector);
- }
- public function mockHttpClient()
- {
- $this->mockedHttpClient = $this->getMock('Zend_Http_Client');
- $this->xmlrpcClient->setHttpClient($this->mockedHttpClient);
- }
- }
- /** related to ZF-8478 */
- require_once 'Zend/XmlRpc/Client/ServerProxy.php';
- class Python_SimpleXMLRPCServerWithUnsupportedIntrospection extends Zend_XmlRpc_Client_ServerProxy {
- public function __call($method, $args) {
- if ($method == 'methodSignature') {
- return 'signatures not supported';
- }
- return parent::__call($method, $args);
- }
- }
- /** related to ZF-8478 */
- require_once 'Zend/XmlRpc/Client.php';
- class Test_XmlRpc_Client extends Zend_XmlRpc_Client {
- public function getProxy($namespace = '') {
- if (empty($this->_proxyCache[$namespace])) {
- $this->_proxyCache[$namespace] = new Python_SimpleXMLRPCServerWithUnsupportedIntrospection($this, $namespace);
- }
- return parent::getProxy($namespace);
- }
- }
- // Call Zend_XmlRpc_ClientTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ClientTest::main") {
- Zend_XmlRpc_ClientTest::main();
- }
|