From e6487d5d7f7a2e7d1b7e71669011a39ebd1fe1f9 Mon Sep 17 00:00:00 2001 From: Ben Batschelet Date: Fri, 9 Mar 2018 14:34:10 -0600 Subject: [PATCH] Remove calls to deprecated each() in Library & tests XmlRpc is not used by Magento, Marketplace, or other Zend modules, and removing it was much easier than trying to refactor the recursive function where each() was used --- library/Zend/Cache/Backend.php | 2 +- library/Zend/Config/Yaml.php | 2 +- .../UserAgent/Features/Adapter/TeraWurfl.php | 2 +- library/Zend/XmlRpc/Client.php | 403 -------- library/Zend/XmlRpc/Client/Exception.php | 40 - library/Zend/XmlRpc/Client/FaultException.php | 38 - library/Zend/XmlRpc/Client/HttpException.php | 41 - .../XmlRpc/Client/IntrospectException.php | 40 - .../XmlRpc/Client/ServerIntrospection.php | 166 --- library/Zend/XmlRpc/Client/ServerProxy.php | 95 -- library/Zend/XmlRpc/Exception.php | 37 - library/Zend/XmlRpc/Fault.php | 307 ------ library/Zend/XmlRpc/Generator/DomDocument.php | 101 -- .../XmlRpc/Generator/GeneratorAbstract.php | 150 --- library/Zend/XmlRpc/Generator/XmlWriter.php | 93 -- library/Zend/XmlRpc/Request.php | 445 -------- library/Zend/XmlRpc/Request/Http.php | 124 --- library/Zend/XmlRpc/Request/Stdin.php | 84 -- library/Zend/XmlRpc/Response.php | 255 ----- library/Zend/XmlRpc/Response/Http.php | 51 - library/Zend/XmlRpc/Server.php | 615 ----------- library/Zend/XmlRpc/Server/Cache.php | 46 - library/Zend/XmlRpc/Server/Exception.php | 42 - library/Zend/XmlRpc/Server/Fault.php | 201 ---- library/Zend/XmlRpc/Server/System.php | 162 --- library/Zend/XmlRpc/Value.php | 525 ---------- library/Zend/XmlRpc/Value/Array.php | 73 -- library/Zend/XmlRpc/Value/Base64.php | 68 -- library/Zend/XmlRpc/Value/BigInteger.php | 58 -- library/Zend/XmlRpc/Value/Boolean.php | 63 -- library/Zend/XmlRpc/Value/Collection.php | 73 -- library/Zend/XmlRpc/Value/DateTime.php | 91 -- library/Zend/XmlRpc/Value/Double.php | 62 -- library/Zend/XmlRpc/Value/Exception.php | 39 - library/Zend/XmlRpc/Value/Integer.php | 65 -- library/Zend/XmlRpc/Value/Nil.php | 60 -- library/Zend/XmlRpc/Value/Scalar.php | 53 - library/Zend/XmlRpc/Value/String.php | 60 -- library/Zend/XmlRpc/Value/Struct.php | 75 -- tests/Zend/AllTests.php | 2 - tests/Zend/XmlRpc/AllTests.php | 76 -- tests/Zend/XmlRpc/BigIntegerValueTest.php | 184 ---- tests/Zend/XmlRpc/ClientTest.php | 821 --------------- tests/Zend/XmlRpc/FaultTest.php | 299 ------ tests/Zend/XmlRpc/GeneratorTest.php | 125 --- tests/Zend/XmlRpc/Request/HttpTest.php | 197 ---- tests/Zend/XmlRpc/RequestTest.php | 377 ------- tests/Zend/XmlRpc/ResponseTest.php | 277 ----- tests/Zend/XmlRpc/Server/CacheTest.php | 133 --- tests/Zend/XmlRpc/Server/FaultTest.php | 294 ------ tests/Zend/XmlRpc/ServerTest.php | 780 -------------- tests/Zend/XmlRpc/TestProvider.php | 43 - tests/Zend/XmlRpc/ValueTest.php | 959 ------------------ tests/Zend/XmlRpc/_files/ZF12293-payload.txt | 1 - tests/Zend/XmlRpc/_files/ZF12293-request.xml | 8 - tests/Zend/XmlRpc/_files/ZF12293-response.xml | 10 - .../XmlRpc/_files/ZF1897-response-chunked.txt | 22 - tests/runalltests.php | 4 +- 58 files changed, 5 insertions(+), 9514 deletions(-) delete mode 100644 library/Zend/XmlRpc/Client.php delete mode 100644 library/Zend/XmlRpc/Client/Exception.php delete mode 100644 library/Zend/XmlRpc/Client/FaultException.php delete mode 100644 library/Zend/XmlRpc/Client/HttpException.php delete mode 100644 library/Zend/XmlRpc/Client/IntrospectException.php delete mode 100644 library/Zend/XmlRpc/Client/ServerIntrospection.php delete mode 100644 library/Zend/XmlRpc/Client/ServerProxy.php delete mode 100644 library/Zend/XmlRpc/Exception.php delete mode 100644 library/Zend/XmlRpc/Fault.php delete mode 100644 library/Zend/XmlRpc/Generator/DomDocument.php delete mode 100644 library/Zend/XmlRpc/Generator/GeneratorAbstract.php delete mode 100644 library/Zend/XmlRpc/Generator/XmlWriter.php delete mode 100644 library/Zend/XmlRpc/Request.php delete mode 100644 library/Zend/XmlRpc/Request/Http.php delete mode 100644 library/Zend/XmlRpc/Request/Stdin.php delete mode 100644 library/Zend/XmlRpc/Response.php delete mode 100644 library/Zend/XmlRpc/Response/Http.php delete mode 100644 library/Zend/XmlRpc/Server.php delete mode 100644 library/Zend/XmlRpc/Server/Cache.php delete mode 100644 library/Zend/XmlRpc/Server/Exception.php delete mode 100644 library/Zend/XmlRpc/Server/Fault.php delete mode 100644 library/Zend/XmlRpc/Server/System.php delete mode 100644 library/Zend/XmlRpc/Value.php delete mode 100644 library/Zend/XmlRpc/Value/Array.php delete mode 100644 library/Zend/XmlRpc/Value/Base64.php delete mode 100644 library/Zend/XmlRpc/Value/BigInteger.php delete mode 100644 library/Zend/XmlRpc/Value/Boolean.php delete mode 100644 library/Zend/XmlRpc/Value/Collection.php delete mode 100644 library/Zend/XmlRpc/Value/DateTime.php delete mode 100644 library/Zend/XmlRpc/Value/Double.php delete mode 100644 library/Zend/XmlRpc/Value/Exception.php delete mode 100644 library/Zend/XmlRpc/Value/Integer.php delete mode 100644 library/Zend/XmlRpc/Value/Nil.php delete mode 100644 library/Zend/XmlRpc/Value/Scalar.php delete mode 100644 library/Zend/XmlRpc/Value/String.php delete mode 100644 library/Zend/XmlRpc/Value/Struct.php delete mode 100644 tests/Zend/XmlRpc/AllTests.php delete mode 100644 tests/Zend/XmlRpc/BigIntegerValueTest.php delete mode 100644 tests/Zend/XmlRpc/ClientTest.php delete mode 100644 tests/Zend/XmlRpc/FaultTest.php delete mode 100644 tests/Zend/XmlRpc/GeneratorTest.php delete mode 100644 tests/Zend/XmlRpc/Request/HttpTest.php delete mode 100644 tests/Zend/XmlRpc/RequestTest.php delete mode 100644 tests/Zend/XmlRpc/ResponseTest.php delete mode 100644 tests/Zend/XmlRpc/Server/CacheTest.php delete mode 100644 tests/Zend/XmlRpc/Server/FaultTest.php delete mode 100644 tests/Zend/XmlRpc/ServerTest.php delete mode 100644 tests/Zend/XmlRpc/TestProvider.php delete mode 100644 tests/Zend/XmlRpc/ValueTest.php delete mode 100644 tests/Zend/XmlRpc/_files/ZF12293-payload.txt delete mode 100644 tests/Zend/XmlRpc/_files/ZF12293-request.xml delete mode 100644 tests/Zend/XmlRpc/_files/ZF12293-response.xml delete mode 100644 tests/Zend/XmlRpc/_files/ZF1897-response-chunked.txt diff --git a/library/Zend/Cache/Backend.php b/library/Zend/Cache/Backend.php index 8164a32f23..994a1fb160 100644 --- a/library/Zend/Cache/Backend.php +++ b/library/Zend/Cache/Backend.php @@ -76,7 +76,7 @@ public function __construct(array $options = array()) public function setDirectives($directives) { if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); - while (list($name, $value) = each($directives)) { + foreach ($directives as $name => $value) { if (!is_string($name)) { Zend_Cache::throwException("Incorrect option name : $name"); } diff --git a/library/Zend/Config/Yaml.php b/library/Zend/Config/Yaml.php index b41fbc9e2b..e9f937259d 100755 --- a/library/Zend/Config/Yaml.php +++ b/library/Zend/Config/Yaml.php @@ -289,7 +289,7 @@ protected static function _decodeYaml($currentIndent, &$lines) { $config = array(); $inIndent = false; - while (list($n, $line) = each($lines)) { + foreach ($line as $n => $line) { $lineno = $n + 1; $line = rtrim(preg_replace("/#.*$/", "", $line)); diff --git a/library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php b/library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php index 08ea3ec48a..2a42a900c7 100644 --- a/library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php +++ b/library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php @@ -88,7 +88,7 @@ public static function getAllCapabilities(TeraWurfl $wurflObj) if (!is_array($group)) { continue; } - while (list ($key, $value) = each($group)) { + foreach ($group as $key => $value) { if (is_bool($value)) { // to have the same type than the official WURFL API $features[$key] = ($value ? 'true' : 'false'); diff --git a/library/Zend/XmlRpc/Client.php b/library/Zend/XmlRpc/Client.php deleted file mode 100644 index a731e268ff..0000000000 --- a/library/Zend/XmlRpc/Client.php +++ /dev/null @@ -1,403 +0,0 @@ -_httpClient = new Zend_Http_Client(); - } else { - $this->_httpClient = $httpClient; - } - - $this->_introspector = new Zend_XmlRpc_Client_ServerIntrospection($this); - $this->_serverAddress = $server; - } - - - /** - * Sets the HTTP client object to use for connecting the XML-RPC server. - * - * @param Zend_Http_Client $httpClient - * @return Zend_Http_Client - */ - public function setHttpClient(Zend_Http_Client $httpClient) - { - return $this->_httpClient = $httpClient; - } - - - /** - * Gets the HTTP client object. - * - * @return Zend_Http_Client - */ - public function getHttpClient() - { - return $this->_httpClient; - } - - - /** - * Sets the object used to introspect remote servers - * - * @param Zend_XmlRpc_Client_ServerIntrospection - * @return Zend_XmlRpc_Client_ServerIntrospection - */ - public function setIntrospector(Zend_XmlRpc_Client_ServerIntrospection $introspector) - { - return $this->_introspector = $introspector; - } - - - /** - * Gets the introspection object. - * - * @return Zend_XmlRpc_Client_ServerIntrospection - */ - public function getIntrospector() - { - return $this->_introspector; - } - - - /** - * The request of the last method call - * - * @return Zend_XmlRpc_Request - */ - public function getLastRequest() - { - return $this->_lastRequest; - } - - - /** - * The response received from the last method call - * - * @return Zend_XmlRpc_Response - */ - public function getLastResponse() - { - return $this->_lastResponse; - } - - - /** - * Returns a proxy object for more convenient method calls - * - * @param string $namespace Namespace to proxy or empty string for none - * @return Zend_XmlRpc_Client_ServerProxy - */ - public function getProxy($namespace = '') - { - if (empty($this->_proxyCache[$namespace])) { - $proxy = new Zend_XmlRpc_Client_ServerProxy($this, $namespace); - $this->_proxyCache[$namespace] = $proxy; - } - return $this->_proxyCache[$namespace]; - } - - /** - * Set skip system lookup flag - * - * @param bool $flag - * @return Zend_XmlRpc_Client - */ - public function setSkipSystemLookup($flag = true) - { - $this->_skipSystemLookup = (bool) $flag; - return $this; - } - - /** - * Skip system lookup when determining if parameter should be array or struct? - * - * @return bool - */ - public function skipSystemLookup() - { - return $this->_skipSystemLookup; - } - - /** - * Perform an XML-RPC request and return a response. - * - * @param Zend_XmlRpc_Request $request - * @param null|Zend_XmlRpc_Response $response - * @return void - * @throws Zend_XmlRpc_Client_HttpException - */ - public function doRequest($request, $response = null) - { - $this->_lastRequest = $request; - - if (PHP_VERSION_ID < 50600) { - iconv_set_encoding('input_encoding', 'UTF-8'); - iconv_set_encoding('output_encoding', 'UTF-8'); - iconv_set_encoding('internal_encoding', 'UTF-8'); - } else { - ini_set('input_encoding', 'UTF-8'); - ini_set('output_encoding', 'UTF-8'); - ini_set('default_charset', 'UTF-8'); - } - - $http = $this->getHttpClient(); - if($http->getUri() === null) { - $http->setUri($this->_serverAddress); - } - - $http->setHeaders(array( - 'Content-Type: text/xml; charset=utf-8', - 'Accept: text/xml', - )); - - if ($http->getHeader('user-agent') === null) { - $http->setHeaders(array('User-Agent: Zend_XmlRpc_Client')); - } - - $xml = $this->_lastRequest->__toString(); - $http->setRawData($xml); - $httpResponse = $http->request(Zend_Http_Client::POST); - - if (! $httpResponse->isSuccessful()) { - /** - * Exception thrown when an HTTP error occurs - * @see Zend_XmlRpc_Client_HttpException - */ - #require_once 'Zend/XmlRpc/Client/HttpException.php'; - throw new Zend_XmlRpc_Client_HttpException( - $httpResponse->getMessage(), - $httpResponse->getStatus()); - } - - if ($response === null) { - $response = new Zend_XmlRpc_Response(); - } - $this->_lastResponse = $response; - $this->_lastResponse->loadXml(trim($httpResponse->getBody())); - } - - /** - * Send an XML-RPC request to the service (for a specific method) - * - * @param string $method Name of the method we want to call - * @param array $params Array of parameters for the method - * @return mixed - * @throws Zend_XmlRpc_Client_FaultException - */ - public function call($method, $params=array()) - { - if (!$this->skipSystemLookup() && ('system.' != substr($method, 0, 7))) { - // Ensure empty array/struct params are cast correctly - // If system.* methods are not available, bypass. (ZF-2978) - $success = true; - try { - $signatures = $this->getIntrospector()->getMethodSignature($method); - } catch (Zend_XmlRpc_Exception $e) { - $success = false; - } - if ($success) { - $validTypes = array( - Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY, - Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64, - Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN, - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME, - Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE, - Zend_XmlRpc_Value::XMLRPC_TYPE_I4, - Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER, - Zend_XmlRpc_Value::XMLRPC_TYPE_NIL, - Zend_XmlRpc_Value::XMLRPC_TYPE_STRING, - Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT, - ); - - if (!is_array($params)) { - $params = array($params); - } - - foreach ($params as $key => $param) - { - if ($param instanceof Zend_XmlRpc_Value) { - continue; - } - - if (count($signatures) > 1) { - $type = Zend_XmlRpc_Value::getXmlRpcTypeByValue($param); - foreach ($signatures as $signature) { - if (!is_array($signature)) { - continue; - } - if (isset($signature['parameters'][$key])) { - if ($signature['parameters'][$key] == $type) { - break; - } - } - } - } elseif (isset($signatures[0]['parameters'][$key])) { - $type = $signatures[0]['parameters'][$key]; - } else { - $type = null; - } - - if (empty($type) || !in_array($type, $validTypes)) { - $type = Zend_XmlRpc_Value::AUTO_DETECT_TYPE; - } - - $params[$key] = Zend_XmlRpc_Value::getXmlRpcValue($param, $type); - } - } - } - - $request = $this->_createRequest($method, $params); - - $this->doRequest($request); - - if ($this->_lastResponse->isFault()) { - $fault = $this->_lastResponse->getFault(); - /** - * Exception thrown when an XML-RPC fault is returned - * @see Zend_XmlRpc_Client_FaultException - */ - #require_once 'Zend/XmlRpc/Client/FaultException.php'; - throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), - $fault->getCode()); - } - - return $this->_lastResponse->getReturnValue(); - } - - /** - * Create request object - * - * @return Zend_XmlRpc_Request - */ - protected function _createRequest($method, $params) - { - return new Zend_XmlRpc_Request($method, $params); - } -} diff --git a/library/Zend/XmlRpc/Client/Exception.php b/library/Zend/XmlRpc/Client/Exception.php deleted file mode 100644 index 000b993f3e..0000000000 --- a/library/Zend/XmlRpc/Client/Exception.php +++ /dev/null @@ -1,40 +0,0 @@ -_system = $client->getProxy('system'); - } - - /** - * Returns the signature for each method on the server, - * autodetecting whether system.multicall() is supported and - * using it if so. - * - * @return array - */ - public function getSignatureForEachMethod() - { - $methods = $this->listMethods(); - - #require_once 'Zend/XmlRpc/Client/FaultException.php'; - try { - $signatures = $this->getSignatureForEachMethodByMulticall($methods); - } catch (Zend_XmlRpc_Client_FaultException $e) { - // degrade to looping - } - - if (empty($signatures)) { - $signatures = $this->getSignatureForEachMethodByLooping($methods); - } - - return $signatures; - } - - /** - * Attempt to get the method signatures in one request via system.multicall(). - * This is a boxcar feature of XML-RPC and is found on fewer servers. However, - * can significantly improve performance if present. - * - * @param array $methods - * @return array array(array(return, param, param, param...)) - */ - public function getSignatureForEachMethodByMulticall($methods = null) - { - if ($methods === null) { - $methods = $this->listMethods(); - } - - $multicallParams = array(); - foreach ($methods as $method) { - $multicallParams[] = array('methodName' => 'system.methodSignature', - 'params' => array($method)); - } - - $serverSignatures = $this->_system->multicall($multicallParams); - - if (! is_array($serverSignatures)) { - $type = gettype($serverSignatures); - $error = "Multicall return is malformed. Expected array, got $type"; - #require_once 'Zend/XmlRpc/Client/IntrospectException.php'; - throw new Zend_XmlRpc_Client_IntrospectException($error); - } - - if (count($serverSignatures) != count($methods)) { - $error = 'Bad number of signatures received from multicall'; - #require_once 'Zend/XmlRpc/Client/IntrospectException.php'; - throw new Zend_XmlRpc_Client_IntrospectException($error); - } - - // Create a new signatures array with the methods name as keys and the signature as value - $signatures = array(); - foreach ($serverSignatures as $i => $signature) { - $signatures[$methods[$i]] = $signature; - } - - return $signatures; - } - - /** - * Get the method signatures for every method by - * successively calling system.methodSignature - * - * @param array $methods - * @return array - */ - public function getSignatureForEachMethodByLooping($methods = null) - { - if ($methods === null) { - $methods = $this->listMethods(); - } - - $signatures = array(); - foreach ($methods as $method) { - $signatures[$method] = $this->getMethodSignature($method); - } - - return $signatures; - } - - /** - * Call system.methodSignature() for the given method - * - * @param array $method - * @return array array(array(return, param, param, param...)) - */ - public function getMethodSignature($method) - { - $signature = $this->_system->methodSignature($method); - if (!is_array($signature)) { - $error = 'Invalid signature for method "' . $method . '"'; - #require_once 'Zend/XmlRpc/Client/IntrospectException.php'; - throw new Zend_XmlRpc_Client_IntrospectException($error); - } - return $signature; - } - - /** - * Call system.listMethods() - * - * @param array $method - * @return array array(method, method, method...) - */ - public function listMethods() - { - return $this->_system->listMethods(); - } - -} diff --git a/library/Zend/XmlRpc/Client/ServerProxy.php b/library/Zend/XmlRpc/Client/ServerProxy.php deleted file mode 100644 index 516619773b..0000000000 --- a/library/Zend/XmlRpc/Client/ServerProxy.php +++ /dev/null @@ -1,95 +0,0 @@ -foo->bar->baz()". - * - * @category Zend - * @package Zend_XmlRpc - * @subpackage Client - * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_XmlRpc_Client_ServerProxy -{ - /** - * @var Zend_XmlRpc_Client - */ - private $_client = null; - - /** - * @var string - */ - private $_namespace = ''; - - - /** - * @var array of Zend_XmlRpc_Client_ServerProxy - */ - private $_cache = array(); - - - /** - * Class constructor - * - * @param string $namespace - * @param Zend_XmlRpc_Client $client - */ - public function __construct($client, $namespace = '') - { - $this->_namespace = $namespace; - $this->_client = $client; - } - - - /** - * Get the next successive namespace - * - * @param string $name - * @return Zend_XmlRpc_Client_ServerProxy - */ - public function __get($namespace) - { - $namespace = ltrim("$this->_namespace.$namespace", '.'); - if (!isset($this->_cache[$namespace])) { - $this->_cache[$namespace] = new $this($this->_client, $namespace); - } - return $this->_cache[$namespace]; - } - - - /** - * Call a method in this namespace. - * - * @param string $methodN - * @param array $args - * @return mixed - */ - public function __call($method, $args) - { - $method = ltrim("$this->_namespace.$method", '.'); - return $this->_client->call($method, $args); - } -} diff --git a/library/Zend/XmlRpc/Exception.php b/library/Zend/XmlRpc/Exception.php deleted file mode 100644 index 8b07919235..0000000000 --- a/library/Zend/XmlRpc/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ - messages - * @var array - */ - protected $_internal = array( - 404 => 'Unknown Error', - - // 610 - 619 reflection errors - 610 => 'Invalid method class', - 611 => 'Unable to attach function or callback; not callable', - 612 => 'Unable to load array; not an array', - 613 => 'One or more method records are corrupt or otherwise unusable', - - // 620 - 629 dispatch errors - 620 => 'Method does not exist', - 621 => 'Error instantiating class to invoke method', - 622 => 'Method missing implementation', - 623 => 'Calling parameters do not match signature', - - // 630 - 639 request errors - 630 => 'Unable to read request', - 631 => 'Failed to parse request', - 632 => 'Invalid request, no method passed; request must contain a \'methodName\' tag', - 633 => 'Param must contain a value', - 634 => 'Invalid method name', - 635 => 'Invalid XML provided to request', - 636 => 'Error creating xmlrpc value', - - // 640 - 649 system.* errors - 640 => 'Method does not exist', - - // 650 - 659 response errors - 650 => 'Invalid XML provided for response', - 651 => 'Failed to parse response', - 652 => 'Invalid response', - 653 => 'Invalid XMLRPC value in response', - ); - - /** - * Constructor - * - * @return Zend_XmlRpc_Fault - */ - public function __construct($code = 404, $message = '') - { - $this->setCode($code); - $code = $this->getCode(); - - if (empty($message) && isset($this->_internal[$code])) { - $message = $this->_internal[$code]; - } elseif (empty($message)) { - $message = 'Unknown error'; - } - $this->setMessage($message); - } - - /** - * Set the fault code - * - * @param int $code - * @return Zend_XmlRpc_Fault - */ - public function setCode($code) - { - $this->_code = (int) $code; - return $this; - } - - /** - * Return fault code - * - * @return int - */ - public function getCode() - { - return $this->_code; - } - - /** - * Retrieve fault message - * - * @param string - * @return Zend_XmlRpc_Fault - */ - public function setMessage($message) - { - $this->_message = (string) $message; - return $this; - } - - /** - * Retrieve fault message - * - * @return string - */ - public function getMessage() - { - return $this->_message; - } - - /** - * Set encoding to use in fault response - * - * @param string $encoding - * @return Zend_XmlRpc_Fault - */ - public function setEncoding($encoding) - { - $this->_encoding = $encoding; - Zend_XmlRpc_Value::setEncoding($encoding); - return $this; - } - - /** - * Retrieve current fault encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Load an XMLRPC fault from XML - * - * @param string $fault - * @return boolean Returns true if successfully loaded fault response, false - * if response was not a fault response - * @throws Zend_XmlRpc_Exception if no or faulty XML provided, or if fault - * response does not contain either code or message - */ - public function loadXml($fault) - { - if (!is_string($fault)) { - #require_once 'Zend/XmlRpc/Exception.php'; - throw new Zend_XmlRpc_Exception('Invalid XML provided to fault'); - } - - try { - $xml = @new SimpleXMLElement($fault); - } catch (Exception $e) { - // Not valid XML - #require_once 'Zend/XmlRpc/Exception.php'; - throw new Zend_XmlRpc_Exception('Failed to parse XML fault: ' . $e->getMessage(), 500, $e); - } - - // Check for fault - if (!$xml->fault) { - // Not a fault - return false; - } - - if (!$xml->fault->value->struct) { - // not a proper fault - #require_once 'Zend/XmlRpc/Exception.php'; - throw new Zend_XmlRpc_Exception('Invalid fault structure', 500); - } - - $structXml = $xml->fault->value->asXML(); - $struct = Zend_XmlRpc_Value::getXmlRpcValue($structXml, Zend_XmlRpc_Value::XML_STRING); - $struct = $struct->getValue(); - - if (isset($struct['faultCode'])) { - $code = $struct['faultCode']; - } - if (isset($struct['faultString'])) { - $message = $struct['faultString']; - } - - if (empty($code) && empty($message)) { - #require_once 'Zend/XmlRpc/Exception.php'; - throw new Zend_XmlRpc_Exception('Fault code and string required'); - } - - if (empty($code)) { - $code = '404'; - } - - if (empty($message)) { - if (isset($this->_internal[$code])) { - $message = $this->_internal[$code]; - } else { - $message = 'Unknown Error'; - } - } - - $this->setCode($code); - $this->setMessage($message); - - return true; - } - - /** - * Determine if an XML response is an XMLRPC fault - * - * @param string $xml - * @return boolean - */ - public static function isFault($xml) - { - $fault = new self(); - #require_once 'Zend/XmlRpc/Exception.php'; - try { - $isFault = $fault->loadXml($xml); - } catch (Zend_XmlRpc_Exception $e) { - $isFault = false; - } - - return $isFault; - } - - /** - * Serialize fault to XML - * - * @return string - */ - public function saveXml() - { - // Create fault value - $faultStruct = array( - 'faultCode' => $this->getCode(), - 'faultString' => $this->getMessage() - ); - $value = Zend_XmlRpc_Value::getXmlRpcValue($faultStruct); - - $generator = Zend_XmlRpc_Value::getGenerator(); - $generator->openElement('methodResponse') - ->openElement('fault'); - $value->generateXml(); - $generator->closeElement('fault') - ->closeElement('methodResponse'); - - return $generator->flush(); - } - - /** - * Return XML fault response - * - * @return string - */ - public function __toString() - { - return $this->saveXML(); - } -} diff --git a/library/Zend/XmlRpc/Generator/DomDocument.php b/library/Zend/XmlRpc/Generator/DomDocument.php deleted file mode 100644 index 99138427a3..0000000000 --- a/library/Zend/XmlRpc/Generator/DomDocument.php +++ /dev/null @@ -1,101 +0,0 @@ -_dom->createElement($name); - - $this->_currentElement = $this->_currentElement->appendChild($newElement); - } - - /** - * Write XML text data into the currently opened XML element - * - * @param string $text - */ - protected function _writeTextData($text) - { - $this->_currentElement->appendChild($this->_dom->createTextNode($text)); - } - - /** - * Close an previously opened XML element - * - * Resets $_currentElement to the next parent node in the hierarchy - * - * @param string $name - * @return void - */ - protected function _closeElement($name) - { - if (isset($this->_currentElement->parentNode)) { - $this->_currentElement = $this->_currentElement->parentNode; - } - } - - /** - * Save XML as a string - * - * @return string - */ - public function saveXml() - { - return $this->_dom->saveXml(); - } - - /** - * Initializes internal objects - * - * @return void - */ - protected function _init() - { - $this->_dom = new DOMDocument('1.0', $this->_encoding); - $this->_currentElement = $this->_dom; - } -} diff --git a/library/Zend/XmlRpc/Generator/GeneratorAbstract.php b/library/Zend/XmlRpc/Generator/GeneratorAbstract.php deleted file mode 100644 index 03afcd696f..0000000000 --- a/library/Zend/XmlRpc/Generator/GeneratorAbstract.php +++ /dev/null @@ -1,150 +0,0 @@ -_encoding = $encoding; - $this->_init(); - } - - /** - * Start XML element - * - * Method opens a new XML element with an element name and an optional value - * - * @param string $name XML tag name - * @param string $value Optional value of the XML tag - * @return Zend_XmlRpc_Generator_Abstract Fluent interface - */ - public function openElement($name, $value = null) - { - $this->_openElement($name); - if ($value !== null) { - $this->_writeTextData($value); - } - - return $this; - } - - /** - * End of an XML element - * - * Method marks the end of an XML element - * - * @param string $name XML tag name - * @return Zend_XmlRpc_Generator_Abstract Fluent interface - */ - public function closeElement($name) - { - $this->_closeElement($name); - - return $this; - } - - /** - * Return XML as a string - * - * @return string - */ - abstract public function saveXml(); - - /** - * Return encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Returns the XML as a string and flushes all internal buffers - * - * @return string - */ - public function flush() - { - $xml = $this->saveXml(); - $this->_init(); - return $xml; - } - - /** - * Returns XML without document declaration - * - * @return string - */ - public function __toString() - { - return $this->stripDeclaration($this->saveXml()); - } - - /** - * Removes XML declaration from a string - * - * @param string $xml - * @return string - */ - public function stripDeclaration($xml) - { - return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml); - } - - /** - * Start XML element - * - * @param string $name XML element name - */ - abstract protected function _openElement($name); - - /** - * Write XML text data into the currently opened XML element - * - * @param string $text - */ - abstract protected function _writeTextData($text); - - /** - * End XML element - * - * @param string $name - */ - abstract protected function _closeElement($name); -} diff --git a/library/Zend/XmlRpc/Generator/XmlWriter.php b/library/Zend/XmlRpc/Generator/XmlWriter.php deleted file mode 100644 index 62dc84fa33..0000000000 --- a/library/Zend/XmlRpc/Generator/XmlWriter.php +++ /dev/null @@ -1,93 +0,0 @@ -_xmlWriter = new XMLWriter(); - $this->_xmlWriter->openMemory(); - $this->_xmlWriter->startDocument('1.0', $this->_encoding); - } - - - /** - * Open a new XML element - * - * @param string $name XML element name - * @return void - */ - protected function _openElement($name) - { - $this->_xmlWriter->startElement($name); - } - - /** - * Write XML text data into the currently opened XML element - * - * @param string $text XML text data - * @return void - */ - protected function _writeTextData($text) - { - $this->_xmlWriter->text($text); - } - - /** - * Close an previously opened XML element - * - * @param string $name - * @return void - */ - protected function _closeElement($name) - { - $this->_xmlWriter->endElement(); - - return $this; - } - - public function saveXml() - { - $xml = $this->_xmlWriter->flush(false); - return $xml; - } -} diff --git a/library/Zend/XmlRpc/Request.php b/library/Zend/XmlRpc/Request.php deleted file mode 100644 index b796025ab5..0000000000 --- a/library/Zend/XmlRpc/Request.php +++ /dev/null @@ -1,445 +0,0 @@ -setMethod($method); - } - - if ($params !== null) { - $this->setParams($params); - } - } - - - /** - * Set encoding to use in request - * - * @param string $encoding - * @return Zend_XmlRpc_Request - */ - public function setEncoding($encoding) - { - $this->_encoding = $encoding; - Zend_XmlRpc_Value::setEncoding($encoding); - return $this; - } - - /** - * Retrieve current request encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Set method to call - * - * @param string $method - * @return boolean Returns true on success, false if method name is invalid - */ - public function setMethod($method) - { - if (!is_string($method) || !preg_match('/^[a-z0-9_.:\/]+$/i', $method)) { - $this->_fault = new Zend_XmlRpc_Fault(634, 'Invalid method name ("' . $method . '")'); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - $this->_method = $method; - return true; - } - - /** - * Retrieve call method - * - * @return string - */ - public function getMethod() - { - return $this->_method; - } - - /** - * Add a parameter to the parameter stack - * - * Adds a parameter to the parameter stack, associating it with the type - * $type if provided - * - * @param mixed $value - * @param string $type Optional; type hinting - * @return void - */ - public function addParam($value, $type = null) - { - $this->_params[] = $value; - if (null === $type) { - // Detect type if not provided explicitly - if ($value instanceof Zend_XmlRpc_Value) { - $type = $value->getType(); - } else { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($value); - $type = $xmlRpcValue->getType(); - } - } - $this->_types[] = $type; - $this->_xmlRpcParams[] = array('value' => $value, 'type' => $type); - } - - /** - * Set the parameters array - * - * If called with a single, array value, that array is used to set the - * parameters stack. If called with multiple values or a single non-array - * value, the arguments are used to set the parameters stack. - * - * Best is to call with array of the format, in order to allow type hinting - * when creating the XMLRPC values for each parameter: - * - * $array = array( - * array( - * 'value' => $value, - * 'type' => $type - * )[, ... ] - * ); - * - * - * @access public - * @return void - */ - public function setParams() - { - $argc = func_num_args(); - $argv = func_get_args(); - if (0 == $argc) { - return; - } - - if ((1 == $argc) && is_array($argv[0])) { - $params = array(); - $types = array(); - $wellFormed = true; - foreach ($argv[0] as $arg) { - if (!is_array($arg) || !isset($arg['value'])) { - $wellFormed = false; - break; - } - $params[] = $arg['value']; - - if (!isset($arg['type'])) { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg['value']); - $arg['type'] = $xmlRpcValue->getType(); - } - $types[] = $arg['type']; - } - if ($wellFormed) { - $this->_xmlRpcParams = $argv[0]; - $this->_params = $params; - $this->_types = $types; - } else { - $this->_params = $argv[0]; - $this->_types = array(); - $xmlRpcParams = array(); - foreach ($argv[0] as $arg) { - if ($arg instanceof Zend_XmlRpc_Value) { - $type = $arg->getType(); - } else { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg); - $type = $xmlRpcValue->getType(); - } - $xmlRpcParams[] = array('value' => $arg, 'type' => $type); - $this->_types[] = $type; - } - $this->_xmlRpcParams = $xmlRpcParams; - } - return; - } - - $this->_params = $argv; - $this->_types = array(); - $xmlRpcParams = array(); - foreach ($argv as $arg) { - if ($arg instanceof Zend_XmlRpc_Value) { - $type = $arg->getType(); - } else { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg); - $type = $xmlRpcValue->getType(); - } - $xmlRpcParams[] = array('value' => $arg, 'type' => $type); - $this->_types[] = $type; - } - $this->_xmlRpcParams = $xmlRpcParams; - } - - /** - * Retrieve the array of parameters - * - * @return array - */ - public function getParams() - { - return $this->_params; - } - - /** - * Return parameter types - * - * @return array - */ - public function getTypes() - { - return $this->_types; - } - - /** - * Load XML and parse into request components - * - * @param string $request - * @return boolean True on success, false if an error occurred. - */ - public function loadXml($request) - { - if (!is_string($request)) { - $this->_fault = new Zend_XmlRpc_Fault(635); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - try { - $xml = Zend_Xml_Security::scan($request); - } catch (Zend_Xml_Exception $e) { - // Not valid XML - $this->_fault = new Zend_XmlRpc_Fault(631); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - // Check for method name - if (empty($xml->methodName)) { - // Missing method name - $this->_fault = new Zend_XmlRpc_Fault(632); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - $this->_method = (string) $xml->methodName; - - // Check for parameters - if (!empty($xml->params)) { - $types = array(); - $argv = array(); - foreach ($xml->params->children() as $param) { - if (!isset($param->value)) { - $this->_fault = new Zend_XmlRpc_Fault(633); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - try { - $param = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING); - $types[] = $param->getType(); - $argv[] = $param->getValue(); - } catch (Exception $e) { - $this->_fault = new Zend_XmlRpc_Fault(636); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - } - - $this->_types = $types; - $this->_params = $argv; - } - - $this->_xml = $request; - - return true; - } - - /** - * Does the current request contain errors and should it return a fault - * response? - * - * @return boolean - */ - public function isFault() - { - return $this->_fault instanceof Zend_XmlRpc_Fault; - } - - /** - * Retrieve the fault response, if any - * - * @return null|Zend_XmlRpc_Fault - */ - public function getFault() - { - return $this->_fault; - } - - /** - * Retrieve method parameters as XMLRPC values - * - * @return array - */ - protected function _getXmlRpcParams() - { - $params = array(); - if (is_array($this->_xmlRpcParams)) { - foreach ($this->_xmlRpcParams as $param) { - $value = $param['value']; - $type = isset($param['type']) ? $param['type'] : Zend_XmlRpc_Value::AUTO_DETECT_TYPE; - - if (!$value instanceof Zend_XmlRpc_Value) { - $value = Zend_XmlRpc_Value::getXmlRpcValue($value, $type); - } - $params[] = $value; - } - } - - return $params; - } - - /** - * Create XML request - * - * @return string - */ - public function saveXml() - { - $args = $this->_getXmlRpcParams(); - $method = $this->getMethod(); - - $generator = Zend_XmlRpc_Value::getGenerator(); - $generator->openElement('methodCall') - ->openElement('methodName', $method) - ->closeElement('methodName'); - - if (is_array($args) && count($args)) { - $generator->openElement('params'); - - foreach ($args as $arg) { - $generator->openElement('param'); - $arg->generateXml(); - $generator->closeElement('param'); - } - $generator->closeElement('params'); - } - $generator->closeElement('methodCall'); - - return $generator->flush(); - } - - /** - * Return XML request - * - * @return string - */ - public function __toString() - { - return $this->saveXML(); - } -} diff --git a/library/Zend/XmlRpc/Request/Http.php b/library/Zend/XmlRpc/Request/Http.php deleted file mode 100644 index a116bfd13c..0000000000 --- a/library/Zend/XmlRpc/Request/Http.php +++ /dev/null @@ -1,124 +0,0 @@ -_fault = new Zend_XmlRpc_Fault(630); - return; - } - - $this->_xml = $xml; - - $this->loadXml($xml); - } - - /** - * Retrieve the raw XML request - * - * @return string - */ - public function getRawRequest() - { - return $this->_xml; - } - - /** - * Get headers - * - * Gets all headers as key => value pairs and returns them. - * - * @return array - */ - public function getHeaders() - { - if (null === $this->_headers) { - $this->_headers = array(); - foreach ($_SERVER as $key => $value) { - if ('HTTP_' == substr($key, 0, 5)) { - $header = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); - $this->_headers[$header] = $value; - } - } - } - - return $this->_headers; - } - - /** - * Retrieve the full HTTP request, including headers and XML - * - * @return string - */ - public function getFullRequest() - { - $request = ''; - foreach ($this->getHeaders() as $key => $value) { - $request .= $key . ': ' . $value . "\n"; - } - - $request .= $this->_xml; - - return $request; - } -} diff --git a/library/Zend/XmlRpc/Request/Stdin.php b/library/Zend/XmlRpc/Request/Stdin.php deleted file mode 100644 index 92e8e736cb..0000000000 --- a/library/Zend/XmlRpc/Request/Stdin.php +++ /dev/null @@ -1,84 +0,0 @@ -_fault = new Zend_XmlRpc_Server_Exception(630); - return; - } - - $xml = ''; - while (!feof($fh)) { - $xml .= fgets($fh); - } - fclose($fh); - - $this->_xml = $xml; - - $this->loadXml($xml); - } - - /** - * Retrieve the raw XML request - * - * @return string - */ - public function getRawRequest() - { - return $this->_xml; - } -} diff --git a/library/Zend/XmlRpc/Response.php b/library/Zend/XmlRpc/Response.php deleted file mode 100644 index 3cdffb7c15..0000000000 --- a/library/Zend/XmlRpc/Response.php +++ /dev/null @@ -1,255 +0,0 @@ -setReturnValue($return, $type); - } - - /** - * Set encoding to use in response - * - * @param string $encoding - * @return Zend_XmlRpc_Response - */ - public function setEncoding($encoding) - { - $this->_encoding = $encoding; - Zend_XmlRpc_Value::setEncoding($encoding); - return $this; - } - - /** - * Retrieve current response encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Set the return value - * - * Sets the return value, with optional type hinting if provided. - * - * @param mixed $value - * @param string $type - * @return void - */ - public function setReturnValue($value, $type = null) - { - $this->_return = $value; - $this->_type = (string) $type; - } - - /** - * Retrieve the return value - * - * @return mixed - */ - public function getReturnValue() - { - return $this->_return; - } - - /** - * Retrieve the XMLRPC value for the return value - * - * @return Zend_XmlRpc_Value - */ - protected function _getXmlRpcReturn() - { - return Zend_XmlRpc_Value::getXmlRpcValue($this->_return); - } - - /** - * Is the response a fault response? - * - * @return boolean - */ - public function isFault() - { - return $this->_fault instanceof Zend_XmlRpc_Fault; - } - - /** - * Returns the fault, if any. - * - * @return null|Zend_XmlRpc_Fault - */ - public function getFault() - { - return $this->_fault; - } - - /** - * Load a response from an XML response - * - * Attempts to load a response from an XMLRPC response, autodetecting if it - * is a fault response. - * - * @param string $response - * @return boolean True if a valid XMLRPC response, false if a fault - * response or invalid input - */ - public function loadXml($response) - { - if (!is_string($response)) { - $this->_fault = new Zend_XmlRpc_Fault(650); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - try { - $xml = Zend_Xml_Security::scan($response); - } catch (Zend_Xml_Exception $e) { - // Not valid XML - $this->_fault = new Zend_XmlRpc_Fault(651); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - if (!empty($xml->fault)) { - // fault response - $this->_fault = new Zend_XmlRpc_Fault(); - $this->_fault->setEncoding($this->getEncoding()); - $this->_fault->loadXml($response); - return false; - } - - if (empty($xml->params)) { - // Invalid response - $this->_fault = new Zend_XmlRpc_Fault(652); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - try { - if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); - } - $valueXml = $xml->params->param->value->asXML(); - $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); - } catch (Zend_XmlRpc_Value_Exception $e) { - $this->_fault = new Zend_XmlRpc_Fault(653); - $this->_fault->setEncoding($this->getEncoding()); - return false; - } - - $this->setReturnValue($value->getValue()); - return true; - } - - /** - * Return response as XML - * - * @return string - */ - public function saveXml() - { - $value = $this->_getXmlRpcReturn(); - $generator = Zend_XmlRpc_Value::getGenerator(); - $generator->openElement('methodResponse') - ->openElement('params') - ->openElement('param'); - $value->generateXml(); - $generator->closeElement('param') - ->closeElement('params') - ->closeElement('methodResponse'); - - return $generator->flush(); - } - - /** - * Return XML response - * - * @return string - */ - public function __toString() - { - return $this->saveXML(); - } -} diff --git a/library/Zend/XmlRpc/Response/Http.php b/library/Zend/XmlRpc/Response/Http.php deleted file mode 100644 index e4d8257cfe..0000000000 --- a/library/Zend/XmlRpc/Response/Http.php +++ /dev/null @@ -1,51 +0,0 @@ -getEncoding())); - } - - return parent::__toString(); - } -} diff --git a/library/Zend/XmlRpc/Server.php b/library/Zend/XmlRpc/Server.php deleted file mode 100644 index 1f79a0cc31..0000000000 --- a/library/Zend/XmlRpc/Server.php +++ /dev/null @@ -1,615 +0,0 @@ - - * #require_once 'Zend/XmlRpc/Server.php'; - * #require_once 'Zend/XmlRpc/Server/Cache.php'; - * #require_once 'Zend/XmlRpc/Server/Fault.php'; - * #require_once 'My/Exception.php'; - * #require_once 'My/Fault/Observer.php'; - * - * // Instantiate server - * $server = new Zend_XmlRpc_Server(); - * - * // Allow some exceptions to report as fault responses: - * Zend_XmlRpc_Server_Fault::attachFaultException('My_Exception'); - * Zend_XmlRpc_Server_Fault::attachObserver('My_Fault_Observer'); - * - * // Get or build dispatch table: - * if (!Zend_XmlRpc_Server_Cache::get($filename, $server)) { - * #require_once 'Some/Service/Class.php'; - * #require_once 'Another/Service/Class.php'; - * - * // Attach Some_Service_Class in 'some' namespace - * $server->setClass('Some_Service_Class', 'some'); - * - * // Attach Another_Service_Class in 'another' namespace - * $server->setClass('Another_Service_Class', 'another'); - * - * // Create dispatch table cache file - * Zend_XmlRpc_Server_Cache::save($filename, $server); - * } - * - * $response = $server->handle(); - * echo $response; - * - * - * @category Zend - * @package Zend_XmlRpc - * @subpackage Server - * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_XmlRpc_Server extends Zend_Server_Abstract -{ - /** - * Character encoding - * @var string - */ - protected $_encoding = 'UTF-8'; - - /** - * Request processed - * @var null|Zend_XmlRpc_Request - */ - protected $_request = null; - - /** - * Class to use for responses; defaults to {@link Zend_XmlRpc_Response_Http} - * @var string - */ - protected $_responseClass = 'Zend_XmlRpc_Response_Http'; - - /** - * Dispatch table of name => method pairs - * @var Zend_Server_Definition - */ - protected $_table; - - /** - * PHP types => XML-RPC types - * @var array - */ - protected $_typeMap = array( - 'i4' => 'i4', - 'int' => 'int', - 'integer' => 'int', - 'Zend_Crypt_Math_BigInteger' => 'i8', - 'i8' => 'i8', - 'ex:i8' => 'i8', - 'double' => 'double', - 'float' => 'double', - 'real' => 'double', - 'boolean' => 'boolean', - 'bool' => 'boolean', - 'true' => 'boolean', - 'false' => 'boolean', - 'string' => 'string', - 'str' => 'string', - 'base64' => 'base64', - 'dateTime.iso8601' => 'dateTime.iso8601', - 'date' => 'dateTime.iso8601', - 'time' => 'dateTime.iso8601', - 'time' => 'dateTime.iso8601', - 'Zend_Date' => 'dateTime.iso8601', - 'DateTime' => 'dateTime.iso8601', - 'array' => 'array', - 'struct' => 'struct', - 'null' => 'nil', - 'nil' => 'nil', - 'ex:nil' => 'nil', - 'void' => 'void', - 'mixed' => 'struct', - ); - - /** - * Send arguments to all methods or just constructor? - * - * @var bool - */ - protected $_sendArgumentsToAllMethods = true; - - /** - * Constructor - * - * Creates system.* methods. - * - * @return void - */ - public function __construct() - { - $this->_table = new Zend_Server_Definition(); - $this->_registerSystemMethods(); - } - - /** - * Proxy calls to system object - * - * @param string $method - * @param array $params - * @return mixed - * @throws Zend_XmlRpc_Server_Exception - */ - public function __call($method, $params) - { - $system = $this->getSystem(); - if (!method_exists($system, $method)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Unknown instance method called on server: ' . $method); - } - return call_user_func_array(array($system, $method), $params); - } - - /** - * Attach a callback as an XMLRPC method - * - * Attaches a callback as an XMLRPC method, prefixing the XMLRPC method name - * with $namespace, if provided. Reflection is done on the callback's - * docblock to create the methodHelp for the XMLRPC method. - * - * Additional arguments to pass to the function at dispatch may be passed; - * any arguments following the namespace will be aggregated and passed at - * dispatch time. - * - * @param string|array $function Valid callback - * @param string $namespace Optional namespace prefix - * @return void - * @throws Zend_XmlRpc_Server_Exception - */ - public function addFunction($function, $namespace = '') - { - if (!is_string($function) && !is_array($function)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611); - } - - $argv = null; - if (2 < func_num_args()) { - $argv = func_get_args(); - $argv = array_slice($argv, 2); - } - - $function = (array) $function; - foreach ($function as $func) { - if (!is_string($func) || !function_exists($func)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611); - } - $reflection = Zend_Server_Reflection::reflectFunction($func, $argv, $namespace); - $this->_buildSignature($reflection); - } - } - - /** - * Attach class methods as XMLRPC method handlers - * - * $class may be either a class name or an object. Reflection is done on the - * class or object to determine the available public methods, and each is - * attached to the server as an available method; if a $namespace has been - * provided, that namespace is used to prefix the XMLRPC method names. - * - * Any additional arguments beyond $namespace will be passed to a method at - * invocation. - * - * @param string|object $class - * @param string $namespace Optional - * @param mixed $argv Optional arguments to pass to methods - * @return void - * @throws Zend_XmlRpc_Server_Exception on invalid input - */ - public function setClass($class, $namespace = '', $argv = null) - { - if (is_string($class) && !class_exists($class)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Invalid method class', 610); - } - - $args = null; - if (2 < func_num_args()) { - $args = func_get_args(); - $args = array_slice($args, 2); - } - - $dispatchable = Zend_Server_Reflection::reflectClass($class, $args, $namespace); - foreach ($dispatchable->getMethods() as $reflection) { - $this->_buildSignature($reflection, $class); - } - } - - /** - * Raise an xmlrpc server fault - * - * @param string|Exception $fault - * @param int $code - * @return Zend_XmlRpc_Server_Fault - */ - public function fault($fault = null, $code = 404) - { - if (!$fault instanceof Exception) { - $fault = (string) $fault; - if (empty($fault)) { - $fault = 'Unknown Error'; - } - #require_once 'Zend/XmlRpc/Server/Exception.php'; - $fault = new Zend_XmlRpc_Server_Exception($fault, $code); - } - - return Zend_XmlRpc_Server_Fault::getInstance($fault); - } - - /** - * Handle an xmlrpc call - * - * @param Zend_XmlRpc_Request $request Optional - * @return Zend_XmlRpc_Response|Zend_XmlRpc_Fault - */ - public function handle($request = false) - { - // Get request - if ((!$request || !$request instanceof Zend_XmlRpc_Request) - && (null === ($request = $this->getRequest())) - ) { - #require_once 'Zend/XmlRpc/Request/Http.php'; - $request = new Zend_XmlRpc_Request_Http(); - $request->setEncoding($this->getEncoding()); - } - - $this->setRequest($request); - - if ($request->isFault()) { - $response = $request->getFault(); - } else { - try { - $response = $this->_handle($request); - } catch (Exception $e) { - $response = $this->fault($e); - } - } - - // Set output encoding - $response->setEncoding($this->getEncoding()); - - return $response; - } - - /** - * Load methods as returned from {@link getFunctions} - * - * Typically, you will not use this method; it will be called using the - * results pulled from {@link Zend_XmlRpc_Server_Cache::get()}. - * - * @param array|Zend_Server_Definition $definition - * @return void - * @throws Zend_XmlRpc_Server_Exception on invalid input - */ - public function loadFunctions($definition) - { - if (!is_array($definition) && (!$definition instanceof Zend_Server_Definition)) { - if (is_object($definition)) { - $type = get_class($definition); - } else { - $type = gettype($definition); - } - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Unable to load server definition; must be an array or Zend_Server_Definition, received ' . $type, 612); - } - - $this->_table->clearMethods(); - $this->_registerSystemMethods(); - - if ($definition instanceof Zend_Server_Definition) { - $definition = $definition->getMethods(); - } - - foreach ($definition as $key => $method) { - if ('system.' == substr($key, 0, 7)) { - continue; - } - $this->_table->addMethod($method, $key); - } - } - - /** - * Set encoding - * - * @param string $encoding - * @return Zend_XmlRpc_Server - */ - public function setEncoding($encoding) - { - $this->_encoding = $encoding; - Zend_XmlRpc_Value::setEncoding($encoding); - return $this; - } - - /** - * Retrieve current encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Do nothing; persistence is handled via {@link Zend_XmlRpc_Server_Cache} - * - * @param mixed $mode - * @return void - */ - public function setPersistence($mode) - { - } - - /** - * Set the request object - * - * @param string|Zend_XmlRpc_Request $request - * @return Zend_XmlRpc_Server - * @throws Zend_XmlRpc_Server_Exception on invalid request class or object - */ - public function setRequest($request) - { - if (is_string($request) && class_exists($request)) { - $request = new $request(); - if (!$request instanceof Zend_XmlRpc_Request) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Invalid request class'); - } - $request->setEncoding($this->getEncoding()); - } elseif (!$request instanceof Zend_XmlRpc_Request) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Invalid request object'); - } - - $this->_request = $request; - return $this; - } - - /** - * Return currently registered request object - * - * @return null|Zend_XmlRpc_Request - */ - public function getRequest() - { - return $this->_request; - } - - /** - * Set the class to use for the response - * - * @param string $class - * @return boolean True if class was set, false if not - */ - public function setResponseClass($class) - { - if (!class_exists($class) or - ($c = new ReflectionClass($class) and !$c->isSubclassOf('Zend_XmlRpc_Response'))) { - - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Invalid response class'); - } - $this->_responseClass = $class; - return true; - } - - /** - * Retrieve current response class - * - * @return string - */ - public function getResponseClass() - { - return $this->_responseClass; - } - - /** - * Retrieve dispatch table - * - * @return array - */ - public function getDispatchTable() - { - return $this->_table; - } - - /** - * Returns a list of registered methods - * - * Returns an array of dispatchables (Zend_Server_Reflection_Function, - * _Method, and _Class items). - * - * @return array - */ - public function getFunctions() - { - return $this->_table->toArray(); - } - - /** - * Retrieve system object - * - * @return Zend_XmlRpc_Server_System - */ - public function getSystem() - { - return $this->_system; - } - - /** - * Send arguments to all methods? - * - * If setClass() is used to add classes to the server, this flag defined - * how to handle arguments. If set to true, all methods including constructor - * will receive the arguments. If set to false, only constructor will receive the - * arguments - */ - public function sendArgumentsToAllMethods($flag = null) - { - if ($flag === null) { - return $this->_sendArgumentsToAllMethods; - } - - $this->_sendArgumentsToAllMethods = (bool)$flag; - return $this; - } - - /** - * Map PHP type to XML-RPC type - * - * @param string $type - * @return string - */ - protected function _fixType($type) - { - if (isset($this->_typeMap[$type])) { - return $this->_typeMap[$type]; - } - return 'void'; - } - - /** - * Handle an xmlrpc call (actual work) - * - * @param Zend_XmlRpc_Request $request - * @return Zend_XmlRpc_Response - * @throws Zend_XmlRpcServer_Exception|Exception - * Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise, - * any other exception may be thrown by the callback - */ - protected function _handle(Zend_XmlRpc_Request $request) - { - $method = $request->getMethod(); - - // Check for valid method - if (!$this->_table->hasMethod($method)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 620); - } - - $info = $this->_table->getMethod($method); - $params = $request->getParams(); - $argv = $info->getInvokeArguments(); - if (0 < count($argv) and $this->sendArgumentsToAllMethods()) { - $params = array_merge($params, $argv); - } - - // Check calling parameters against signatures - $matched = false; - $sigCalled = $request->getTypes(); - - $sigLength = count($sigCalled); - $paramsLen = count($params); - if ($sigLength < $paramsLen) { - for ($i = $sigLength; $i < $paramsLen; ++$i) { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($params[$i]); - $sigCalled[] = $xmlRpcValue->getType(); - } - } - - $signatures = $info->getPrototypes(); - foreach ($signatures as $signature) { - $sigParams = $signature->getParameters(); - if ($sigCalled === $sigParams) { - $matched = true; - break; - } - } - if (!$matched) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623); - } - - $return = $this->_dispatch($info, $params); - $responseClass = $this->getResponseClass(); - return new $responseClass($return); - } - - /** - * Register system methods with the server - * - * @return void - */ - protected function _registerSystemMethods() - { - $system = new Zend_XmlRpc_Server_System($this); - $this->_system = $system; - $this->setClass($system, 'system'); - } -} diff --git a/library/Zend/XmlRpc/Server/Cache.php b/library/Zend/XmlRpc/Server/Cache.php deleted file mode 100644 index c77178d6fb..0000000000 --- a/library/Zend/XmlRpc/Server/Cache.php +++ /dev/null @@ -1,46 +0,0 @@ - true); - - /** - * @var array Array of fault observers - */ - protected static $_observers = array(); - - /** - * Constructor - * - * @param Exception $e - * @return Zend_XmlRpc_Server_Fault - */ - public function __construct(Exception $e) - { - $this->_exception = $e; - $code = 404; - $message = 'Unknown error'; - $exceptionClass = get_class($e); - - foreach (array_keys(self::$_faultExceptionClasses) as $class) { - if ($e instanceof $class) { - $code = $e->getCode(); - $message = $e->getMessage(); - break; - } - } - - parent::__construct($code, $message); - - // Notify exception observers, if present - if (!empty(self::$_observers)) { - foreach (array_keys(self::$_observers) as $observer) { - call_user_func(array($observer, 'observe'), $this); - } - } - } - - /** - * Return Zend_XmlRpc_Server_Fault instance - * - * @param Exception $e - * @return Zend_XmlRpc_Server_Fault - */ - public static function getInstance(Exception $e) - { - return new self($e); - } - - /** - * Attach valid exceptions that can be used to define xmlrpc faults - * - * @param string|array $classes Class name or array of class names - * @return void - */ - public static function attachFaultException($classes) - { - if (!is_array($classes)) { - $classes = (array) $classes; - } - - foreach ($classes as $class) { - if (is_string($class) && class_exists($class)) { - self::$_faultExceptionClasses[$class] = true; - } - } - } - - /** - * Detach fault exception classes - * - * @param string|array $classes Class name or array of class names - * @return void - */ - public static function detachFaultException($classes) - { - if (!is_array($classes)) { - $classes = (array) $classes; - } - - foreach ($classes as $class) { - if (is_string($class) && isset(self::$_faultExceptionClasses[$class])) { - unset(self::$_faultExceptionClasses[$class]); - } - } - } - - /** - * Attach an observer class - * - * Allows observation of xmlrpc server faults, thus allowing logging or mail - * notification of fault responses on the xmlrpc server. - * - * Expects a valid class name; that class must have a public static method - * 'observe' that accepts an exception as its sole argument. - * - * @param string $class - * @return boolean - */ - public static function attachObserver($class) - { - if (!is_string($class) - || !class_exists($class) - || !is_callable(array($class, 'observe'))) - { - return false; - } - - if (!isset(self::$_observers[$class])) { - self::$_observers[$class] = true; - } - - return true; - } - - /** - * Detach an observer - * - * @param string $class - * @return boolean - */ - public static function detachObserver($class) - { - if (!isset(self::$_observers[$class])) { - return false; - } - - unset(self::$_observers[$class]); - return true; - } - - /** - * Retrieve the exception - * - * @access public - * @return Exception - */ - public function getException() - { - return $this->_exception; - } -} diff --git a/library/Zend/XmlRpc/Server/System.php b/library/Zend/XmlRpc/Server/System.php deleted file mode 100644 index 21beb4c913..0000000000 --- a/library/Zend/XmlRpc/Server/System.php +++ /dev/null @@ -1,162 +0,0 @@ -_server = $server; - } - - /** - * List all available XMLRPC methods - * - * Returns an array of methods. - * - * @return array - */ - public function listMethods() - { - $table = $this->_server->getDispatchTable()->getMethods(); - return array_keys($table); - } - - /** - * Display help message for an XMLRPC method - * - * @param string $method - * @return string - */ - public function methodHelp($method) - { - $table = $this->_server->getDispatchTable(); - if (!$table->hasMethod($method)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640); - } - - return $table->getMethod($method)->getMethodHelp(); - } - - /** - * Return a method signature - * - * @param string $method - * @return array - */ - public function methodSignature($method) - { - $table = $this->_server->getDispatchTable(); - if (!$table->hasMethod($method)) { - #require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640); - } - $method = $table->getMethod($method)->toArray(); - return $method['prototypes']; - } - - /** - * Multicall - boxcar feature of XML-RPC for calling multiple methods - * in a single request. - * - * Expects a an array of structs representing method calls, each element - * having the keys: - * - methodName - * - params - * - * Returns an array of responses, one for each method called, with the value - * returned by the method. If an error occurs for a given method, returns a - * struct with a fault response. - * - * @see http://www.xmlrpc.com/discuss/msgReader$1208 - * @param array $methods - * @return array - */ - public function multicall($methods) - { - $responses = array(); - foreach ($methods as $method) { - $fault = false; - if (!is_array($method)) { - $fault = $this->_server->fault('system.multicall expects each method to be a struct', 601); - } elseif (!isset($method['methodName'])) { - $fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602); - } elseif (!isset($method['params'])) { - $fault = $this->_server->fault('Missing params', 603); - } elseif (!is_array($method['params'])) { - $fault = $this->_server->fault('Params must be an array', 604); - } else { - if ('system.multicall' == $method['methodName']) { - // don't allow recursive calls to multicall - $fault = $this->_server->fault('Recursive system.multicall forbidden', 605); - } - } - - if (!$fault) { - try { - $request = new Zend_XmlRpc_Request(); - $request->setMethod($method['methodName']); - $request->setParams($method['params']); - $response = $this->_server->handle($request); - if ($response instanceof Zend_XmlRpc_Fault - || $response->isFault() - ) { - $fault = $response; - } else { - $responses[] = $response->getReturnValue(); - } - } catch (Exception $e) { - $fault = $this->_server->fault($e); - } - } - - if ($fault) { - $responses[] = array( - 'faultCode' => $fault->getCode(), - 'faultString' => $fault->getMessage() - ); - } - } - - return $responses; - } -} diff --git a/library/Zend/XmlRpc/Value.php b/library/Zend/XmlRpc/Value.php deleted file mode 100644 index 2af87bdff6..0000000000 --- a/library/Zend/XmlRpc/Value.php +++ /dev/null @@ -1,525 +0,0 @@ -_type; - } - - /** - * Get XML generator instance - * - * @return Zend_XmlRpc_Generator_GeneratorAbstract - */ - public static function getGenerator() - { - if (!self::$_generator) { - if (extension_loaded('xmlwriter')) { - #require_once 'Zend/XmlRpc/Generator/XmlWriter.php'; - self::$_generator = new Zend_XmlRpc_Generator_XmlWriter(); - } else { - #require_once 'Zend/XmlRpc/Generator/DomDocument.php'; - self::$_generator = new Zend_XmlRpc_Generator_DomDocument(); - } - } - - return self::$_generator; - } - - /** - * Sets XML generator instance - * - * @param Zend_XmlRpc_Generator_GeneratorAbstract $generator - * @return void - */ - public static function setGenerator(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - self::$_generator = $generator; - } - - /** - * Changes the encoding of the generator - * - * @param string $encoding - * @return void - */ - public static function setEncoding($encoding) - { - $generator = self::getGenerator(); - $newGenerator = new $generator($encoding); - self::setGenerator($newGenerator); - } - - /** - * Return the value of this object, convert the XML-RPC native value into a PHP variable - * - * @return mixed - */ - abstract public function getValue(); - - - /** - * Return the XML code that represent a native MXL-RPC value - * - * @return string - */ - public function saveXml() - { - if (!$this->_xml) { - $this->generateXml(); - $this->_xml = (string) $this->getGenerator(); - } - return $this->_xml; - } - - /** - * Generate XML code that represent a native XML/RPC value - * - * @return void - */ - public function generateXml() - { - $this->_generateXml(); - } - - /** - * Creates a Zend_XmlRpc_Value* object, representing a native XML-RPC value - * A XmlRpcValue object can be created in 3 ways: - * 1. Autodetecting the native type out of a PHP variable - * (if $type is not set or equal to Zend_XmlRpc_Value::AUTO_DETECT_TYPE) - * 2. By specifing the native type ($type is one of the Zend_XmlRpc_Value::XMLRPC_TYPE_* constants) - * 3. From a XML string ($type is set to Zend_XmlRpc_Value::XML_STRING) - * - * By default the value type is autodetected according to it's PHP type - * - * @param mixed $value - * @param Zend_XmlRpc_Value::constant $type - * - * @return Zend_XmlRpc_Value - * @static - */ - public static function getXmlRpcValue($value, $type = self::AUTO_DETECT_TYPE) - { - switch ($type) { - case self::AUTO_DETECT_TYPE: - // Auto detect the XML-RPC native type from the PHP type of $value - return self::_phpVarToNativeXmlRpc($value); - - case self::XML_STRING: - // Parse the XML string given in $value and get the XML-RPC value in it - return self::_xmlStringToNativeXmlRpc($value); - - case self::XMLRPC_TYPE_I4: - // fall through to the next case - case self::XMLRPC_TYPE_INTEGER: - #require_once 'Zend/XmlRpc/Value/Integer.php'; - return new Zend_XmlRpc_Value_Integer($value); - - case self::XMLRPC_TYPE_I8: - // fall through to the next case - case self::XMLRPC_TYPE_APACHEI8: - #require_once 'Zend/XmlRpc/Value/BigInteger.php'; - return new Zend_XmlRpc_Value_BigInteger($value); - - case self::XMLRPC_TYPE_DOUBLE: - #require_once 'Zend/XmlRpc/Value/Double.php'; - return new Zend_XmlRpc_Value_Double($value); - - case self::XMLRPC_TYPE_BOOLEAN: - #require_once 'Zend/XmlRpc/Value/Boolean.php'; - return new Zend_XmlRpc_Value_Boolean($value); - - case self::XMLRPC_TYPE_STRING: - #require_once 'Zend/XmlRpc/Value/String.php'; - return new Zend_XmlRpc_Value_String($value); - - case self::XMLRPC_TYPE_BASE64: - #require_once 'Zend/XmlRpc/Value/Base64.php'; - return new Zend_XmlRpc_Value_Base64($value); - - case self::XMLRPC_TYPE_NIL: - // fall through to the next case - case self::XMLRPC_TYPE_APACHENIL: - #require_once 'Zend/XmlRpc/Value/Nil.php'; - return new Zend_XmlRpc_Value_Nil(); - - case self::XMLRPC_TYPE_DATETIME: - #require_once 'Zend/XmlRpc/Value/DateTime.php'; - return new Zend_XmlRpc_Value_DateTime($value); - - case self::XMLRPC_TYPE_ARRAY: - #require_once 'Zend/XmlRpc/Value/Array.php'; - return new Zend_XmlRpc_Value_Array($value); - - case self::XMLRPC_TYPE_STRUCT: - #require_once 'Zend/XmlRpc/Value/Struct.php'; - return new Zend_XmlRpc_Value_Struct($value); - - default: - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Given type is not a '. __CLASS__ .' constant'); - } - } - - /** - * Get XML-RPC type for a PHP native variable - * - * @static - * @param mixed $value - * @return string - */ - public static function getXmlRpcTypeByValue($value) - { - if (is_object($value)) { - if ($value instanceof Zend_XmlRpc_Value) { - return $value->getType(); - } elseif (($value instanceof Zend_Date) || ($value instanceof DateTime)) { - return self::XMLRPC_TYPE_DATETIME; - } - return self::getXmlRpcTypeByValue(get_object_vars($value)); - } elseif (is_array($value)) { - if (!empty($value) && is_array($value) && (array_keys($value) !== range(0, count($value) - 1))) { - return self::XMLRPC_TYPE_STRUCT; - } - return self::XMLRPC_TYPE_ARRAY; - } elseif (is_int($value)) { - return ($value > PHP_INT_MAX) ? self::XMLRPC_TYPE_I8 : self::XMLRPC_TYPE_INTEGER; - } elseif (is_double($value)) { - return self::XMLRPC_TYPE_DOUBLE; - } elseif (is_bool($value)) { - return self::XMLRPC_TYPE_BOOLEAN; - } elseif (is_null($value)) { - return self::XMLRPC_TYPE_NIL; - } elseif (is_string($value)) { - return self::XMLRPC_TYPE_STRING; - } - throw new Zend_XmlRpc_Value_Exception(sprintf( - 'No matching XMLRPC type found for php type %s.', - gettype($value) - )); - } - - /** - * Transform a PHP native variable into a XML-RPC native value - * - * @param mixed $value The PHP variable for convertion - * - * @return Zend_XmlRpc_Value - * @static - */ - protected static function _phpVarToNativeXmlRpc($value) - { - // @see http://framework.zend.com/issues/browse/ZF-8623 - if (is_object($value)) { - if ($value instanceof Zend_XmlRpc_Value) { - return $value; - } - if ($value instanceof Zend_Crypt_Math_BigInteger) { - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception( - 'Using Zend_Crypt_Math_BigInteger to get an ' . - 'instance of Zend_XmlRpc_Value_BigInteger is not ' . - 'available anymore.' - ); - } - } - - switch (self::getXmlRpcTypeByValue($value)) - { - case self::XMLRPC_TYPE_DATETIME: - #require_once 'Zend/XmlRpc/Value/DateTime.php'; - return new Zend_XmlRpc_Value_DateTime($value); - - case self::XMLRPC_TYPE_ARRAY: - #require_once 'Zend/XmlRpc/Value/Array.php'; - return new Zend_XmlRpc_Value_Array($value); - - case self::XMLRPC_TYPE_STRUCT: - #require_once 'Zend/XmlRpc/Value/Struct.php'; - return new Zend_XmlRpc_Value_Struct($value); - - case self::XMLRPC_TYPE_INTEGER: - #require_once 'Zend/XmlRpc/Value/Integer.php'; - return new Zend_XmlRpc_Value_Integer($value); - - case self::XMLRPC_TYPE_DOUBLE: - #require_once 'Zend/XmlRpc/Value/Double.php'; - return new Zend_XmlRpc_Value_Double($value); - - case self::XMLRPC_TYPE_BOOLEAN: - #require_once 'Zend/XmlRpc/Value/Boolean.php'; - return new Zend_XmlRpc_Value_Boolean($value); - - case self::XMLRPC_TYPE_NIL: - #require_once 'Zend/XmlRpc/Value/Nil.php'; - return new Zend_XmlRpc_Value_Nil; - - case self::XMLRPC_TYPE_STRING: - // Fall through to the next case - default: - // If type isn't identified (or identified as string), it treated as string - #require_once 'Zend/XmlRpc/Value/String.php'; - return new Zend_XmlRpc_Value_String($value); - } - } - - - /** - * Transform an XML string into a XML-RPC native value - * - * @param string|SimpleXMLElement $xml A SimpleXMLElement object represent the XML string - * It can be also a valid XML string for convertion - * - * @return Zend_XmlRpc_Value - * @static - */ - protected static function _xmlStringToNativeXmlRpc($xml) - { - self::_createSimpleXMLElement($xml); - - self::_extractTypeAndValue($xml, $type, $value); - - switch ($type) { - // All valid and known XML-RPC native values - case self::XMLRPC_TYPE_I4: - // Fall through to the next case - case self::XMLRPC_TYPE_INTEGER: - #require_once 'Zend/XmlRpc/Value/Integer.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Integer($value); - break; - case self::XMLRPC_TYPE_APACHEI8: - // Fall through to the next case - case self::XMLRPC_TYPE_I8: - #require_once 'Zend/XmlRpc/Value/BigInteger.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_BigInteger($value); - break; - case self::XMLRPC_TYPE_DOUBLE: - #require_once 'Zend/XmlRpc/Value/Double.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Double($value); - break; - case self::XMLRPC_TYPE_BOOLEAN: - #require_once 'Zend/XmlRpc/Value/Boolean.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Boolean($value); - break; - case self::XMLRPC_TYPE_STRING: - #require_once 'Zend/XmlRpc/Value/String.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_String($value); - break; - case self::XMLRPC_TYPE_DATETIME: // The value should already be in a iso8601 format - #require_once 'Zend/XmlRpc/Value/DateTime.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_DateTime($value); - break; - case self::XMLRPC_TYPE_BASE64: // The value should already be base64 encoded - #require_once 'Zend/XmlRpc/Value/Base64.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Base64($value, true); - break; - case self::XMLRPC_TYPE_NIL: - // Fall through to the next case - case self::XMLRPC_TYPE_APACHENIL: - // The value should always be NULL - #require_once 'Zend/XmlRpc/Value/Nil.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Nil(); - break; - case self::XMLRPC_TYPE_ARRAY: - // PHP 5.2.4 introduced a regression in how empty($xml->value) - // returns; need to look for the item specifically - $data = null; - foreach ($value->children() as $key => $value) { - if ('data' == $key) { - $data = $value; - break; - } - } - - if (null === $data) { - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Invalid XML for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type: ARRAY tag must contain DATA tag'); - } - $values = array(); - // Parse all the elements of the array from the XML string - // (simple xml element) to Zend_XmlRpc_Value objects - foreach ($data->value as $element) { - $values[] = self::_xmlStringToNativeXmlRpc($element); - } - #require_once 'Zend/XmlRpc/Value/Array.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Array($values); - break; - case self::XMLRPC_TYPE_STRUCT: - $values = array(); - // Parse all the memebers of the struct from the XML string - // (simple xml element) to Zend_XmlRpc_Value objects - foreach ($value->member as $member) { - // @todo? If a member doesn't have a tag, we don't add it to the struct - // Maybe we want to throw an exception here ? - if (!isset($member->value) or !isset($member->name)) { - continue; - //throw new Zend_XmlRpc_Value_Exception('Member of the '. self::XMLRPC_TYPE_STRUCT .' XML-RPC native type must contain a VALUE tag'); - } - $values[(string)$member->name] = self::_xmlStringToNativeXmlRpc($member->value); - } - #require_once 'Zend/XmlRpc/Value/Struct.php'; - $xmlrpcValue = new Zend_XmlRpc_Value_Struct($values); - break; - default: - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type'); - break; - } - $xmlrpcValue->_setXML($xml->asXML()); - - return $xmlrpcValue; - } - - protected static function _createSimpleXMLElement(&$xml) - { - if ($xml instanceof SimpleXMLElement) { - return; - } - - try { - $xml = new SimpleXMLElement($xml); - } catch (Exception $e) { - // The given string is not a valid XML - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Failed to create XML-RPC value from XML string: ' . $e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Extract XML/RPC type and value from SimpleXMLElement object - * - * @param SimpleXMLElement $xml - * @param string &$type Type bind variable - * @param string &$value Value bind variable - * @return void - */ - protected static function _extractTypeAndValue(SimpleXMLElement $xml, &$type, &$value) - { - list($type, $value) = each($xml); - - if (!$type and $value === null) { - $namespaces = array('ex' => 'http://ws.apache.org/xmlrpc/namespaces/extensions'); - foreach ($namespaces as $namespaceName => $namespaceUri) { - $namespaceXml = $xml->children($namespaceUri); - list($type, $value) = each($namespaceXml); - if ($type !== null) { - $type = $namespaceName . ':' . $type; - break; - } - } - } - - //if there is a child element, try to parse type for it - if (!$type && $value instanceof SimpleXMLElement) { - self::_extractTypeAndValue($value->children(), $type, $value); - } - - // If no type was specified, the default is string - if (!$type) { - $type = self::XMLRPC_TYPE_STRING; - if (preg_match('#^.*$#', $xml->asXML())) { - $value = str_replace(array('', ''), '', $xml->asXML()); - } - } - } - - /** - * @param string $xml - * @return void - */ - protected function _setXML($xml) - { - $this->_xml = $this->getGenerator()->stripDeclaration($xml); - } -} diff --git a/library/Zend/XmlRpc/Value/Array.php b/library/Zend/XmlRpc/Value/Array.php deleted file mode 100644 index 828682a1eb..0000000000 --- a/library/Zend/XmlRpc/Value/Array.php +++ /dev/null @@ -1,73 +0,0 @@ -_type = self::XMLRPC_TYPE_ARRAY; - parent::__construct($value); - } - - - /** - * Generate the XML code that represent an array native MXL-RPC value - * - * @return void - */ - protected function _generateXml() - { - $generator = $this->getGenerator(); - $generator->openElement('value') - ->openElement('array') - ->openElement('data'); - - if (is_array($this->_value)) { - foreach ($this->_value as $val) { - $val->generateXml(); - } - } - $generator->closeElement('data') - ->closeElement('array') - ->closeElement('value'); - } -} - diff --git a/library/Zend/XmlRpc/Value/Base64.php b/library/Zend/XmlRpc/Value/Base64.php deleted file mode 100644 index 92bc9ce069..0000000000 --- a/library/Zend/XmlRpc/Value/Base64.php +++ /dev/null @@ -1,68 +0,0 @@ -_type = self::XMLRPC_TYPE_BASE64; - - $value = (string)$value; // Make sure this value is string - if (!$alreadyEncoded) { - $value = base64_encode($value); // We encode it in base64 - } - $this->_value = $value; - } - - /** - * Return the value of this object, convert the XML-RPC native base64 value into a PHP string - * We return this value decoded (a normal string) - * - * @return string - */ - public function getValue() - { - return base64_decode($this->_value); - } -} diff --git a/library/Zend/XmlRpc/Value/BigInteger.php b/library/Zend/XmlRpc/Value/BigInteger.php deleted file mode 100644 index 925410a791..0000000000 --- a/library/Zend/XmlRpc/Value/BigInteger.php +++ /dev/null @@ -1,58 +0,0 @@ -_value = $integer->init($value); - $this->_type = self::XMLRPC_TYPE_I8; - } - - /** - * Return bigint value - * - * @return string - */ - public function getValue() - { - return $this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Boolean.php b/library/Zend/XmlRpc/Value/Boolean.php deleted file mode 100644 index b4e8366b89..0000000000 --- a/library/Zend/XmlRpc/Value/Boolean.php +++ /dev/null @@ -1,63 +0,0 @@ -_type = self::XMLRPC_TYPE_BOOLEAN; - // Make sure the value is boolean and then convert it into a integer - // The double convertion is because a bug in the ZendOptimizer in PHP version 5.0.4 - $this->_value = (int)(bool)$value; - } - - /** - * Return the value of this object, convert the XML-RPC native boolean value into a PHP boolean - * - * @return bool - */ - public function getValue() - { - return (bool)$this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Collection.php b/library/Zend/XmlRpc/Value/Collection.php deleted file mode 100644 index 0930ac14ae..0000000000 --- a/library/Zend/XmlRpc/Value/Collection.php +++ /dev/null @@ -1,73 +0,0 @@ - $value) { - // If the elements of the given array are not Zend_XmlRpc_Value objects, - // we need to convert them as such (using auto-detection from PHP value) - if (!$value instanceof parent) { - $value = self::getXmlRpcValue($value, self::AUTO_DETECT_TYPE); - } - $this->_value[$key] = $value; - } - } - - - /** - * Return the value of this object, convert the XML-RPC native collection values into a PHP array - * - * @return arary - */ - public function getValue() - { - $values = (array)$this->_value; - foreach ($values as $key => $value) { - /* @var $value Zend_XmlRpc_Value */ - $values[$key] = $value->getValue(); - } - return $values; - } -} diff --git a/library/Zend/XmlRpc/Value/DateTime.php b/library/Zend/XmlRpc/Value/DateTime.php deleted file mode 100644 index 21403c4927..0000000000 --- a/library/Zend/XmlRpc/Value/DateTime.php +++ /dev/null @@ -1,91 +0,0 @@ -_type = self::XMLRPC_TYPE_DATETIME; - - if ($value instanceof Zend_Date) { - $this->_value = $value->toString($this->_isoFormatString); - } elseif ($value instanceof DateTime) { - $this->_value = $value->format($this->_phpFormatString); - } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer - $this->_value = date($this->_phpFormatString, (int)$value); - } else { - $timestamp = new DateTime($value); - if ($timestamp === false) { // cannot convert the value to a timestamp - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); - } - - $this->_value = $timestamp->format($this->_phpFormatString); // Convert the timestamp to iso8601 format - } - } - - /** - * Return the value of this object as iso8601 dateTime value - * - * @return int As a Unix timestamp - */ - public function getValue() - { - return $this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Double.php b/library/Zend/XmlRpc/Value/Double.php deleted file mode 100644 index 9962efd7d8..0000000000 --- a/library/Zend/XmlRpc/Value/Double.php +++ /dev/null @@ -1,62 +0,0 @@ -_type = self::XMLRPC_TYPE_DOUBLE; - $precision = (int)ini_get('precision'); - $formatString = '%1.' . $precision . 'F'; - $this->_value = rtrim(sprintf($formatString, (float)$value), '0'); - } - - /** - * Return the value of this object, convert the XML-RPC native double value into a PHP float - * - * @return float - */ - public function getValue() - { - return (float)$this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Exception.php b/library/Zend/XmlRpc/Value/Exception.php deleted file mode 100644 index 84f2d051a5..0000000000 --- a/library/Zend/XmlRpc/Value/Exception.php +++ /dev/null @@ -1,39 +0,0 @@ - PHP_INT_MAX) { - #require_once 'Zend/XmlRpc/Value/Exception.php'; - throw new Zend_XmlRpc_Value_Exception('Overlong integer given'); - } - - $this->_type = self::XMLRPC_TYPE_INTEGER; - $this->_value = (int)$value; // Make sure this value is integer - } - - /** - * Return the value of this object, convert the XML-RPC native integer value into a PHP integer - * - * @return int - */ - public function getValue() - { - return $this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Nil.php b/library/Zend/XmlRpc/Value/Nil.php deleted file mode 100644 index b95825e9fc..0000000000 --- a/library/Zend/XmlRpc/Value/Nil.php +++ /dev/null @@ -1,60 +0,0 @@ -_type = self::XMLRPC_TYPE_NIL; - $this->_value = null; - } - - /** - * Return the value of this object, convert the XML-RPC native nill value into a PHP NULL - * - * @return null - */ - public function getValue() - { - return null; - } -} - diff --git a/library/Zend/XmlRpc/Value/Scalar.php b/library/Zend/XmlRpc/Value/Scalar.php deleted file mode 100644 index 0e2210f896..0000000000 --- a/library/Zend/XmlRpc/Value/Scalar.php +++ /dev/null @@ -1,53 +0,0 @@ -getGenerator(); - - $generator->openElement('value') - ->openElement($this->_type, $this->_value) - ->closeElement($this->_type) - ->closeElement('value'); - } -} diff --git a/library/Zend/XmlRpc/Value/String.php b/library/Zend/XmlRpc/Value/String.php deleted file mode 100644 index 5980a825b4..0000000000 --- a/library/Zend/XmlRpc/Value/String.php +++ /dev/null @@ -1,60 +0,0 @@ -_type = self::XMLRPC_TYPE_STRING; - - // Make sure this value is string and all XML characters are encoded - $this->_value = (string)$value; - } - - /** - * Return the value of this object, convert the XML-RPC native string value into a PHP string - * - * @return string - */ - public function getValue() - { - return (string)$this->_value; - } -} diff --git a/library/Zend/XmlRpc/Value/Struct.php b/library/Zend/XmlRpc/Value/Struct.php deleted file mode 100644 index e4a2d810fc..0000000000 --- a/library/Zend/XmlRpc/Value/Struct.php +++ /dev/null @@ -1,75 +0,0 @@ -_type = self::XMLRPC_TYPE_STRUCT; - parent::__construct($value); - } - - - /** - * Generate the XML code that represent struct native MXL-RPC value - * - * @return void - */ - protected function _generateXML() - { - $generator = $this->getGenerator(); - $generator->openElement('value') - ->openElement('struct'); - - if (is_array($this->_value)) { - foreach ($this->_value as $name => $val) { - /* @var $val Zend_XmlRpc_Value */ - $generator->openElement('member') - ->openElement('name', $name) - ->closeElement('name'); - $val->generateXml(); - $generator->closeElement('member'); - } - } - $generator->closeElement('struct') - ->closeElement('value'); - } -} diff --git a/tests/Zend/AllTests.php b/tests/Zend/AllTests.php index b19094d8da..52763fff45 100644 --- a/tests/Zend/AllTests.php +++ b/tests/Zend/AllTests.php @@ -106,7 +106,6 @@ if (PHP_OS != 'AIX') { require_once 'Zend/Wildfire/AllTests.php'; } -require_once 'Zend/XmlRpc/AllTests.php'; /** * @category Zend @@ -244,7 +243,6 @@ public static function suite() if (PHP_OS != 'AIX') { $suite->addTest(Zend_Wildfire_AllTests::suite()); } - $suite->addTest(Zend_XmlRpc_AllTests::suite()); return $suite; } diff --git a/tests/Zend/XmlRpc/AllTests.php b/tests/Zend/XmlRpc/AllTests.php deleted file mode 100644 index e02f0e380e..0000000000 --- a/tests/Zend/XmlRpc/AllTests.php +++ /dev/null @@ -1,76 +0,0 @@ -addTestSuite('Zend_XmlRpc_BigIntegerValueTest'); - $suite->addTestSuite('Zend_XmlRpc_ValueTest'); - $suite->addTestSuite('Zend_XmlRpc_RequestTest'); - $suite->addTestSuite('Zend_XmlRpc_Request_HttpTest'); - $suite->addTestSuite('Zend_XmlRpc_ResponseTest'); - $suite->addTestSuite('Zend_XmlRpc_FaultTest'); - $suite->addTestSuite('Zend_XmlRpc_ClientTest'); - $suite->addTestSuite('Zend_XmlRpc_ServerTest'); - $suite->addTestSuite('Zend_XmlRpc_GeneratorTest'); - $suite->addTestSuite('Zend_XmlRpc_Server_CacheTest'); - $suite->addTestSuite('Zend_XmlRpc_Server_FaultTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Zend_XmlRpc_AllTests::main') { - Zend_XmlRpc_AllTests::main(); -} diff --git a/tests/Zend/XmlRpc/BigIntegerValueTest.php b/tests/Zend/XmlRpc/BigIntegerValueTest.php deleted file mode 100644 index 60a1aa8c78..0000000000 --- a/tests/Zend/XmlRpc/BigIntegerValueTest.php +++ /dev/null @@ -1,184 +0,0 @@ -markTestSkipped($e->getMessage()); - } - } - - // BigInteger - - /** - * @group ZF-6445 - * @group ZF-8623 - */ - public function testBigIntegerGetValue() - { - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue); - $this->assertSame($bigIntegerValue, $bigInteger->getValue()); - } - - /** - * @group ZF-6445 - */ - public function testBigIntegerGetType() - { - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue); - $this->assertSame(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $bigInteger->getType()); - } - - /** - * @group ZF-6445 - */ - public function testBigIntegerGeneratedXml() - { - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue); - - $this->assertEquals( - '' . $bigIntegerValue . '', - $bigInteger->saveXml() - ); - } - - /** - * @group ZF-6445 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarschalBigIntegerFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue); - $bigIntegerXml = '' . $bigIntegerValue . ''; - - $value = Zend_XmlRpc_Value::getXmlRpcValue( - $bigIntegerXml, - Zend_XmlRpc_Value::XML_STRING - ); - - $this->assertSame($bigIntegerValue, $value->getValue()); - $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType()); - $this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml()); - } - - /** - * @group ZF-6445 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarschalBigIntegerFromApacheXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue); - $bigIntegerXml = '' . $bigIntegerValue . ''; - - $value = Zend_XmlRpc_Value::getXmlRpcValue( - $bigIntegerXml, - Zend_XmlRpc_Value::XML_STRING - ); - - $this->assertSame($bigIntegerValue, $value->getValue()); - $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType()); - $this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml()); - } - - /** - * @group ZF-6445 - */ - public function testMarshalBigIntegerFromNative() - { - $bigIntegerValue = (string)(PHP_INT_MAX + 42); - - $value = Zend_XmlRpc_Value::getXmlRpcValue( - $bigIntegerValue, - Zend_XmlRpc_Value::XMLRPC_TYPE_I8 - ); - - $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType()); - $this->assertSame($bigIntegerValue, $value->getValue()); - } - - /** - * @group ZF-6445 - */ - public function testMarschalBigIntegerFromCryptObjectThrowsException() - { - try { - Zend_XmlRpc_Value::getXmlRpcValue(new Zend_Crypt_Math_BigInteger); - $this->fail('expected Zend_XmlRpc_Value_Exception has not been thrown'); - } catch (Zend_XmlRpc_Value_Exception $exception) { - if (strpos($exception->getMessage(), 'Zend_Crypt_Math_BigInteger') === false) { - $this->fail('caught Zend_XmlRpc_Value_Exception does not contain expected text'); - } - } - } - - // Custom Assertions and Helper Methods - - public function wrapXml($xml) - { - return $xml . "\n"; - } -} - -// Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_BigIntegerValueTest::main") { - Zend_XmlRpc_ValueTest::main(); -} diff --git a/tests/Zend/XmlRpc/ClientTest.php b/tests/Zend/XmlRpc/ClientTest.php deleted file mode 100644 index 5359774066..0000000000 --- a/tests/Zend/XmlRpc/ClientTest.php +++ /dev/null @@ -1,821 +0,0 @@ -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(); -} diff --git a/tests/Zend/XmlRpc/FaultTest.php b/tests/Zend/XmlRpc/FaultTest.php deleted file mode 100644 index 1a0afcd8fe..0000000000 --- a/tests/Zend/XmlRpc/FaultTest.php +++ /dev/null @@ -1,299 +0,0 @@ -_fault = new Zend_XmlRpc_Fault(); - } - - /** - * Teardown environment - */ - public function tearDown() - { - unset($this->_fault); - } - - /** - * __construct() test - */ - public function testConstructor() - { - $this->assertTrue($this->_fault instanceof Zend_XmlRpc_Fault); - $this->assertEquals(404, $this->_fault->getCode()); - $this->assertEquals('Unknown Error', $this->_fault->getMessage()); - } - - /** - * get/setCode() test - */ - public function testCode() - { - $this->_fault->setCode('1000'); - $this->assertEquals(1000, $this->_fault->getCode()); - } - - /** - * get/setMessage() test - */ - public function testMessage() - { - $this->_fault->setMessage('Message'); - $this->assertEquals('Message', $this->_fault->getMessage()); - } - - protected function _createXml() - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $response = $dom->appendChild($dom->createElement('methodResponse')); - $fault = $response->appendChild($dom->createElement('fault')); - $value = $fault->appendChild($dom->createElement('value')); - $struct = $value->appendChild($dom->createElement('struct')); - - $member1 = $struct->appendChild($dom->createElement('member')); - $member1->appendChild($dom->createElement('name', 'faultCode')); - $value1 = $member1->appendChild($dom->createElement('value')); - $value1->appendChild($dom->createElement('int', 1000)); - - $member2 = $struct->appendChild($dom->createElement('member')); - $member2->appendChild($dom->createElement('name', 'faultString')); - $value2 = $member2->appendChild($dom->createElement('value')); - $value2->appendChild($dom->createElement('string', 'Error string')); - - return $dom->saveXml(); - } - - protected function _createNonStandardXml() - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $response = $dom->appendChild($dom->createElement('methodResponse')); - $fault = $response->appendChild($dom->createElement('fault')); - $value = $fault->appendChild($dom->createElement('value')); - $struct = $value->appendChild($dom->createElement('struct')); - - $member1 = $struct->appendChild($dom->createElement('member')); - $member1->appendChild($dom->createElement('name', 'faultCode')); - $value1 = $member1->appendChild($dom->createElement('value')); - $value1->appendChild($dom->createElement('int', 1000)); - - $member2 = $struct->appendChild($dom->createElement('member')); - $member2->appendChild($dom->createElement('name', 'faultString')); - $value2 = $member2->appendChild($dom->createElement('value', 'Error string')); - - return $dom->saveXml(); - } - - /** - * loadXml() test - */ - public function testLoadXml() - { - $xml = $this->_createXml(); - - try { - $parsed = $this->_fault->loadXml($xml); - } catch (Exception $e) { - $this->fail('Failed to parse XML: ' . $e->getMessage()); - } - $this->assertTrue($parsed, $xml); - - $this->assertEquals(1000, $this->_fault->getCode()); - $this->assertEquals('Error string', $this->_fault->getMessage()); - - try { - $parsed = $this->_fault->loadXml('foo'); - $this->fail('Should not parse invalid XML'); - } catch (Zend_XmlRpc_Exception $e) { - // do nothing - } - - $this->assertFalse($this->_fault->loadXml('')); - - try { - $this->assertFalse($this->_fault->loadXml('')); - $this->fail('Should throw an exception. No value element in fault'); - } catch (Zend_XmlRpc_Exception $e) { - $this->assertEquals('Invalid fault structure', $e->getMessage()); - $this->assertSame(500, $e->getCode()); - } - - try { - $this->_fault->loadXml(''); - $this->fail('Should throw an exception. No struct element in //fault/value'); - } catch (Zend_XmlRpc_Exception $e) { - $this->assertEquals('Invalid fault structure', $e->getMessage()); - $this->assertSame(500, $e->getCode()); - } - - try { - $this->_fault->loadXml(''); - $this->fail('Should throw an exception. Empty fault code and string in //fault/value'); - } catch (Zend_XmlRpc_Exception $e) { - $this->assertEquals('Fault code and string required', $e->getMessage()); - } - - $this->_fault->loadXml('' - . 'faultStringstr' - . ''); - $this->assertSame(404, $this->_fault->getCode(), 'If no fault code is given, use 404 as a default'); - - $this->_fault->loadXml('' - . 'faultCode610' - . ''); - $this->assertSame( - 'Invalid method class', $this->_fault->getMessage(), 'If empty fault string is given, resolve the code'); - - $this->_fault->loadXml('' - . 'faultCode1234' - . ''); - $this->assertSame( - 'Unknown Error', - $this->_fault->getMessage(), - 'If code resolval failed, use "Unknown Error"' - ); - } - - /** - * Zend_XmlRpc_Fault::isFault() test - */ - public function testIsFault() - { - $xml = $this->_createXml(); - - $this->assertTrue(Zend_XmlRpc_Fault::isFault($xml), $xml); - $this->assertFalse(Zend_XmlRpc_Fault::isFault('foo')); - $this->assertFalse(Zend_XmlRpc_Fault::isFault(array('foo'))); - } - - /** - * helper for saveXml() and __toString() tests - * - * @param string $xml - * @return void - */ - protected function _testXmlFault($xml) - { - try { - $sx = new SimpleXMLElement($xml); - } catch (Exception $e) { - $this->fail('Unable to parse generated XML'); - } - - $this->assertTrue($sx->fault ? true : false, $xml); - $this->assertTrue($sx->fault->value ? true : false, $xml); - $this->assertTrue($sx->fault->value->struct ? true : false, $xml); - $count = 0; - foreach ($sx->fault->value->struct->member as $member) { - $count++; - $this->assertTrue($member->name ? true : false, $xml); - $this->assertTrue($member->value ? true : false, $xml); - if ('faultCode' == (string) $member->name) { - $this->assertTrue($member->value->int ? true : false, $xml); - $this->assertEquals(1000, (int) $member->value->int, $xml); - } - if ('faultString' == (string) $member->name) { - $this->assertTrue($member->value->string ? true : false, $xml); - $this->assertEquals('Fault message', (string) $member->value->string, $xml); - } - } - - $this->assertEquals(2, $count, $xml); - } - - /** - * saveXml() test - */ - public function testSaveXML() - { - $this->_fault->setCode(1000); - $this->_fault->setMessage('Fault message'); - $xml = $this->_fault->saveXml(); - $this->_testXmlFault($xml); - } - - /** - * __toString() test - */ - public function test__toString() - { - $this->_fault->setCode(1000); - $this->_fault->setMessage('Fault message'); - $xml = $this->_fault->__toString(); - $this->_testXmlFault($xml); - } - - /** - * Test encoding settings - */ - public function testSetGetEncoding() - { - $this->assertEquals('UTF-8', $this->_fault->getEncoding()); - $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - $this->_fault->setEncoding('ISO-8859-1'); - $this->assertEquals('ISO-8859-1', $this->_fault->getEncoding()); - $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - } - - public function testUnknownErrorIsUsedIfUnknownErrorCodeEndEmptyMessageIsPassed() - { - $fault = new Zend_XmlRpc_Fault(1234); - $this->assertSame(1234, $fault->getCode()); - $this->assertSame('Unknown error', $fault->getMessage()); - } - - public function testFaultStringWithoutStringTypeDeclaration() - { - $xml = $this->_createNonStandardXml(); - - try { - $parsed = $this->_fault->loadXml($xml); - } catch (Exception $e) { - $this->fail('Failed to parse XML: ' . $e->getMessage()); - } - $this->assertTrue($parsed, $xml); - - $this->assertEquals('Error string', $this->_fault->getMessage()); - } -} diff --git a/tests/Zend/XmlRpc/GeneratorTest.php b/tests/Zend/XmlRpc/GeneratorTest.php deleted file mode 100644 index 3e5bce80b1..0000000000 --- a/tests/Zend/XmlRpc/GeneratorTest.php +++ /dev/null @@ -1,125 +0,0 @@ -openElement('element'); - $generator->closeElement('element'); - $this->assertXml('', $generator); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testCreatingSingleElementWithValue(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $generator->openElement('element', 'value'); - $generator->closeElement('element'); - $this->assertXml('value', $generator); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testCreatingComplexXmlDocument(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $generator->openElement('root'); - $generator->openElement('children'); - $generator->openElement('child', 'child1')->closeElement('child'); - $generator->openElement('child', 'child2')->closeElement('child'); - $generator->closeElement('children'); - $generator->closeElement('root'); - $this->assertXml( - 'child1child2', - $generator - ); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testFlushingGeneratorFlushesEverything(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $generator->openElement('test')->closeElement('test'); - $this->assertXml('', $generator); - $this->assertContains('', $generator->flush()); - $this->assertSame('', (string)$generator); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testSpecialCharsAreEncoded(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $generator->openElement('element', '<>&"\'€')->closeElement('element'); - $variant1 = '<>&"\'€'; - $variant2 = '<>&"\'€'; - try { - $this->assertXml($variant1, $generator); - } catch (PHPUnit_Framework_ExpectationFailedException $e) { - $this->assertXml($variant2, $generator); - } - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGeneratorsWithAlternateEncodings - */ - public function testDifferentEncodings(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $generator->openElement('element', '€')->closeElement('element'); - $this->assertXml('', $generator); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testFluentInterfacesProvided(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - $this->assertSame($generator, $generator->openElement('foo')); - $this->assertSame($generator, $generator->closeElement('foo')); - } - - public function assertXml($expected, $actual) - { - $expected = trim($expected); - $this->assertSame($expected, trim($actual)); - $xmlDecl = 'getEncoding() . '"?>' . "\n"; - $this->assertSame($xmlDecl . $expected, trim($actual->saveXml())); - } -} diff --git a/tests/Zend/XmlRpc/Request/HttpTest.php b/tests/Zend/XmlRpc/Request/HttpTest.php deleted file mode 100644 index 2555f5e1d7..0000000000 --- a/tests/Zend/XmlRpc/Request/HttpTest.php +++ /dev/null @@ -1,197 +0,0 @@ -xml =<< - - test.userUpdate - - - blahblahblah - - - - - salutation - Felsenblöcke - - - firstname - Lépiné - - - lastname - Géranté - - - company - Zend Technologies, Inc. - - - - - -EOX; - $this->request = new Zend_XmlRpc_Request_Http(); - $this->request->loadXml($this->xml); - - $this->server = $_SERVER; - foreach ($_SERVER as $key => $value) { - if ('HTTP_' == substr($key, 0, 5)) { - unset($_SERVER[$key]); - } - } - $_SERVER['HTTP_USER_AGENT'] = 'Zend_XmlRpc_Client'; - $_SERVER['HTTP_HOST'] = 'localhost'; - $_SERVER['HTTP_CONTENT_TYPE'] = 'text/xml'; - $_SERVER['HTTP_CONTENT_LENGTH'] = strlen($this->xml) + 1; - Zend_AllTests_StreamWrapper_PhpInput::mockInput($this->xml); - } - - /** - * Teardown environment - */ - public function tearDown() - { - $_SERVER = $this->server; - unset($this->request); - Zend_AllTests_StreamWrapper_PhpInput::restoreDefault(); - } - - public function testGetRawRequest() - { - $this->assertEquals($this->xml, $this->request->getRawRequest()); - } - - public function testGetHeaders() - { - $expected = array( - 'User-Agent' => 'Zend_XmlRpc_Client', - 'Host' => 'localhost', - 'Content-Type' => 'text/xml', - 'Content-Length' => 958 - ); - $this->assertEquals($expected, $this->request->getHeaders()); - } - - public function testGetFullRequest() - { - $expected =<<xml; - - $this->assertEquals($expected, $this->request->getFullRequest()); - } - - public function testCanPassInMethodAndParams() - { - try { - $request = new Zend_XmlRpc_Request_Http('foo', array('bar', 'baz')); - } catch (Exception $e) { - $this->fail('Should be able to pass in methods and params to request'); - } - } - - public function testExtendingClassShouldBeAbleToReceiveMethodAndParams() - { - try { - $request = new Zend_XmlRpc_Request_HttpTest_Extension('foo', array('bar', 'baz')); - } catch (Exception $e) { - $this->fail('Should be able to pass in methods and params to request'); - } - $this->assertEquals('foo', $request->method); - $this->assertEquals(array('bar', 'baz'), $request->params); - } - - public function testHttpRequestReadsFromPhpInput() - { - $this->assertNull(Zend_AllTests_StreamWrapper_PhpInput::argumentsPassedTo('stream_open')); - $request = new Zend_XmlRpc_Request_Http(); - list($path, $mode,) = Zend_AllTests_StreamWrapper_PhpInput::argumentsPassedTo('stream_open'); - $this->assertSame('php://input', $path); - $this->assertSame('rb', $mode); - $this->assertSame($this->xml, $request->getRawRequest()); - } - - public function testHttpRequestGeneratesFaultIfReadFromPhpInputFails() - { - Zend_AllTests_StreamWrapper_PhpInput::methodWillReturn('stream_open', false); - $request = new Zend_XmlRpc_Request_Http(); - $this->assertTrue($request->isFault()); - $this->assertSame(630, $request->getFault()->getCode()); - } -} - -class Zend_XmlRpc_Request_HttpTest_Extension extends Zend_XmlRpc_Request_Http -{ - public function __construct($method = null, $params = null) - { - $this->method = $method; - $this->params = (array) $params; - } -} - -// Call Zend_XmlRpc_Request_HttpTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Request_HttpTest::main") { - Zend_XmlRpc_Request_HttpTest::main(); -} diff --git a/tests/Zend/XmlRpc/RequestTest.php b/tests/Zend/XmlRpc/RequestTest.php deleted file mode 100644 index dec3f4075c..0000000000 --- a/tests/Zend/XmlRpc/RequestTest.php +++ /dev/null @@ -1,377 +0,0 @@ -_request = new Zend_XmlRpc_Request(); - } - - /** - * Teardown environment - */ - public function tearDown() - { - unset($this->_request); - } - - /** - * get/setMethod() test - */ - public function testMethod() - { - $this->assertTrue($this->_request->setMethod('testMethod')); - $this->assertTrue($this->_request->setMethod('testMethod9')); - $this->assertTrue($this->_request->setMethod('test.Method')); - $this->assertTrue($this->_request->setMethod('test_method')); - $this->assertTrue($this->_request->setMethod('test:method')); - $this->assertTrue($this->_request->setMethod('test/method')); - $this->assertFalse($this->_request->setMethod('testMethod-bogus')); - - $this->assertEquals('test/method', $this->_request->getMethod()); - } - - - /** - * __construct() test - */ - public function testConstructorOptionallySetsMethodAndParams() - { - $r = new Zend_XmlRpc_Request(); - $this->assertEquals('', $r->getMethod()); - $this->assertEquals(array(), $r->getParams()); - - $method = 'foo.bar'; - $params = array('baz', 1, array('foo' => 'bar')); - $r = new Zend_XmlRpc_Request($method, $params); - $this->assertEquals($method, $r->getMethod()); - $this->assertEquals($params, $r->getParams()); - } - - - /** - * addParam()/getParams() test - */ - public function testAddParam() - { - $this->_request->addParam('string1'); - $params = $this->_request->getParams(); - $this->assertEquals(1, count($params)); - $this->assertEquals('string1', $params[0]); - - $this->_request->addParam('string2'); - $params = $this->_request->getParams(); - $this->assertSame(2, count($params)); - $this->assertSame('string1', $params[0]); - $this->assertSame('string2', $params[1]); - - $this->_request->addParam(new Zend_XmlRpc_Value_String('foo')); - $params = $this->_request->getParams(); - $this->assertSame(3, count($params)); - $this->assertSame('string1', $params[0]); - $this->assertSame('string2', $params[1]); - $this->assertSame('foo', $params[2]->getValue()); - } - - public function testAddDateParamGeneratesCorrectXml() - { - $time = time(); - $this->_request->addParam($time, Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - $this->_request->setMethod('foo.bar'); - $xml = $this->_request->saveXml(); - $sxl = new SimpleXMLElement($xml); - $param = $sxl->params->param->value; - $type = 'dateTime.iso8601'; - $this->assertTrue(isset($param->{$type}), var_export($param, 1)); - $this->assertEquals($time, strtotime((string) $param->{$type})); - } - - /** - * setParams()/getParams() test - */ - public function testSetParams() - { - $params = array( - 'string1', - true, - array('one', 'two') - ); - $this->_request->setParams($params); - $returned = $this->_request->getParams(); - $this->assertSame($params, $returned); - - $params = array( - 'string2', - array('two', 'one') - ); - $this->_request->setParams($params); - $returned = $this->_request->getParams(); - $this->assertSame($params, $returned); - - $params = array(array('value' => 'foobar')); - $this->_request->setParams($params); - $this->assertSame(array('foobar'), $this->_request->getParams()); - $this->assertSame(array('string'), $this->_request->getTypes()); - - $null = new Zend_XmlRpc_Value_Nil(); - $this->_request->setParams('foo', 1, $null); - $this->assertSame(array('foo', 1, $null), $this->_request->getParams()); - $this->assertSame(array('string', 'int', 'nil'), $this->_request->getTypes()); - - $this->assertNull($this->_request->setParams(), 'Call without argument returns null'); - } - - /** - * loadXml() test - */ - public function testLoadXml() - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $mCall = $dom->appendChild($dom->createElement('methodCall')); - $mName = $mCall->appendChild($dom->createElement('methodName', 'do.Something')); - $params = $mCall->appendChild($dom->createElement('params')); - $param1 = $params->appendChild($dom->createElement('param')); - $value1 = $param1->appendChild($dom->createElement('value')); - $value1->appendChild($dom->createElement('string', 'string1')); - - $param2 = $params->appendChild($dom->createElement('param')); - $value2 = $param2->appendChild($dom->createElement('value')); - $value2->appendChild($dom->createElement('boolean', 1)); - - - $xml = $dom->saveXml(); - - try { - $parsed = $this->_request->loadXml($xml); - } catch (Exception $e) { - $this->fail('Failed to parse XML: ' . $e->getMessage()); - } - $this->assertTrue($parsed, $xml); - - $this->assertEquals('do.Something', $this->_request->getMethod()); - $test = array('string1', true); - $params = $this->_request->getParams(); - $this->assertSame($test, $params); - - try { - $parsed = $this->_request->loadXml('foo'); - } catch (Exception $e) { - $this->fail('Failed to parse XML: ' . $e->getMessage()); - } - $this->assertFalse($parsed, 'Parsed non-XML string?'); - } - - public function testPassingInvalidTypeToLoadXml() - { - $this->assertFalse($this->_request->loadXml(new stdClass())); - $this->assertTrue($this->_request->isFault()); - $this->assertSame(635, $this->_request->getFault()->getCode()); - $this->assertSame('Invalid XML provided to request', $this->_request->getFault()->getMessage()); - } - - public function testLoadingXmlWithoutMethodNameElement() - { - $this->assertFalse($this->_request->loadXml('')); - $this->assertTrue($this->_request->isFault()); - $this->assertSame(632, $this->_request->getFault()->getCode()); - $this->assertSame("Invalid request, no method passed; request must contain a 'methodName' tag", - $this->_request->getFault()->getMessage()); - } - - public function testLoadingXmlWithInvalidParams() - { - $this->assertFalse($this->_request->loadXml( - '' - . 'foo' - . '' - . '')); - $this->assertTrue($this->_request->isFault()); - $this->assertSame(633, $this->_request->getFault()->getCode()); - $this->assertSame( - 'Param must contain a value', - $this->_request->getFault()->getMessage()); - } - - public function testExceptionWhileLoadingXmlParamValueIsHandled() - { - $this->assertFalse($this->_request->loadXml( - '' - . 'foo' - . '' - . '')); - $this->assertTrue($this->_request->isFault()); - $this->assertSame(636, $this->_request->getFault()->getCode()); - $this->assertSame( - 'Error creating xmlrpc value', - $this->_request->getFault()->getMessage()); - } - - /** - * isFault() test - */ - public function testIsFault() - { - $this->assertFalse($this->_request->isFault()); - $this->_request->loadXml('foo'); - $this->assertTrue($this->_request->isFault()); - } - - /** - * getFault() test - */ - public function testGetFault() - { - $fault = $this->_request->getFault(); - $this->assertTrue(null === $fault); - $this->_request->loadXml('foo'); - $fault = $this->_request->getFault(); - $this->assertTrue($fault instanceof Zend_XmlRpc_Fault); - } - - /** - * helper for saveXml() and __toString() tests - * - * @param string $xml - * @return void - */ - protected function _testXmlRequest($xml, $argv) - { - try { - $sx = new SimpleXMLElement($xml); - } catch (Exception $e) { - $this->fail('Invalid XML returned'); - } - - $result = $sx->xpath('//methodName'); - $count = 0; - while (list( , $node) = each($result)) { - ++$count; - } - $this->assertEquals(1, $count, $xml); - - $result = $sx->xpath('//params'); - $count = 0; - while (list( , $node) = each($result)) { - ++$count; - } - $this->assertEquals(1, $count, $xml); - - try { - $methodName = (string) $sx->methodName; - $params = array( - (string) $sx->params->param[0]->value->string, - (bool) $sx->params->param[1]->value->boolean - ); - } catch (Exception $e) { - $this->fail('One or more inconsistencies parsing generated XML: ' . $e->getMessage()); - } - - $this->assertEquals('do.Something', $methodName); - $this->assertSame($argv, $params, $xml); - } - - /** - * testSaveXML() test - */ - public function testSaveXML() - { - $argv = array('string', true); - $this->_request->setMethod('do.Something'); - $this->_request->setParams($argv); - $xml = $this->_request->saveXml(); - $this->_testXmlRequest($xml, $argv); - } - - /** - * __toString() test - */ - public function test__toString() - { - $argv = array('string', true); - $this->_request->setMethod('do.Something'); - $this->_request->setParams($argv); - $xml = $this->_request->__toString(); - $this->_testXmlRequest($xml, $argv); - } - - /** - * Test encoding settings - */ - public function testSetGetEncoding() - { - $this->assertEquals('UTF-8', $this->_request->getEncoding()); - $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - $this->assertSame($this->_request, $this->_request->setEncoding('ISO-8859-1')); - $this->assertEquals('ISO-8859-1', $this->_request->getEncoding()); - $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - } - - /** - * @group ZF-12293 -+ * -+ * Test should remain, but is defunct since DOCTYPE presence should return FALSE -+ * from loadXml() - */ - public function testDoesNotAllowExternalEntities() - { - $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-request.xml'); - $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt')); - $this->_request->loadXml($payload); - $method = $this->_request->getMethod(); - $this->assertTrue(empty($method)); - if (is_string($method)) { - $this->assertNotContains('Local file inclusion', $method); - } - } - - public function testShouldDisallowsDoctypeInRequestXmlAndReturnFalseOnLoading() - { - $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-request.xml'); - $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt')); - $this->assertFalse($this->_request->loadXml($payload)); - } -} diff --git a/tests/Zend/XmlRpc/ResponseTest.php b/tests/Zend/XmlRpc/ResponseTest.php deleted file mode 100644 index 0b256fd236..0000000000 --- a/tests/Zend/XmlRpc/ResponseTest.php +++ /dev/null @@ -1,277 +0,0 @@ -_response = new Zend_XmlRpc_Response(); - } - - /** - * Teardown environment - */ - public function tearDown() - { - unset($this->_response); - } - - /** - * __construct() test - */ - public function test__construct() - { - $this->assertTrue($this->_response instanceof Zend_XmlRpc_Response); - } - - /** - * get/setReturnValue() test - */ - public function testReturnValue() - { - $this->_response->setReturnValue('string'); - $this->assertEquals('string', $this->_response->getReturnValue()); - - $this->_response->setReturnValue(array('one', 'two')); - $this->assertSame(array('one', 'two'), $this->_response->getReturnValue()); - } - - /** - * isFault() test - * - * Call as method call - * - * Returns: boolean - */ - public function testIsFault() - { - $this->assertFalse($this->_response->isFault()); - $this->_response->loadXml('foo'); - $this->assertTrue($this->_response->isFault()); - } - - /** - * Tests getFault() returns NULL (no fault) or the fault object - */ - public function testGetFault() - { - $this->assertNull($this->_response->getFault()); - $this->_response->loadXml('foo'); - $this->assertTrue($this->_response->getFault() instanceof Zend_XmlRpc_Fault); - } - - /** - * loadXml() test - * - * Call as method call - * - * Expects: - * - response: - * - * Returns: boolean - */ - public function testLoadXml() - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $response = $dom->appendChild($dom->createElement('methodResponse')); - $params = $response->appendChild($dom->createElement('params')); - $param = $params->appendChild($dom->createElement('param')); - $value = $param->appendChild($dom->createElement('value')); - $value->appendChild($dom->createElement('string', 'Return value')); - - $xml = $dom->saveXml(); - - $parsed = $this->_response->loadXml($xml); - $this->assertTrue($parsed, $xml); - $this->assertEquals('Return value', $this->_response->getReturnValue()); - } - - public function testLoadXmlWithInvalidValue() - { - $this->assertFalse($this->_response->loadXml(new stdClass())); - $this->assertTrue($this->_response->isFault()); - $this->assertSame(650, $this->_response->getFault()->getCode()); - } - - /** - * @group ZF-9039 - */ - public function testExceptionIsThrownWhenInvalidXmlIsReturnedByServer() - { - set_error_handler(array($this, 'trackError')); - $invalidResponse = 'foo'; - $response = new Zend_XmlRpc_Response(); - $this->assertFalse($this->_errorOccured); - $this->assertFalse($response->loadXml($invalidResponse)); - $this->assertFalse($this->_errorOccured); - } - - /** - * @group ZF-5404 - */ - public function testNilResponseFromXmlRpcServer() - { - $rawResponse = <<id1namebirdy num num!description -EOD; - try { - $response = new Zend_XmlRpc_Response(); - $ret = $response->loadXml($rawResponse); - } catch(Exception $e) { - $this->fail("Parsing the response should not throw an exception."); - } - - $this->assertTrue($ret); - $this->assertEquals(array( - 0 => array( - 'id' => 1, - 'name' => 'birdy num num!', - 'description' => null, - ) - ), $response->getReturnValue()); - } - - /** - * helper for saveXml() and __toString() tests - * - * @param string $xml - * @return void - */ - protected function _testXmlResponse($xml) - { - try { - $sx = new SimpleXMLElement($xml); - } catch (Exception $e) { - $this->fail('Invalid XML returned'); - } - - $this->assertTrue($sx->params ? true : false); - $this->assertTrue($sx->params->param ? true : false); - $this->assertTrue($sx->params->param->value ? true : false); - $this->assertTrue($sx->params->param->value->string ? true : false); - $this->assertEquals('return value', (string) $sx->params->param->value->string); - } - - /** - * saveXml() test - */ - public function testSaveXML() - { - $this->_response->setReturnValue('return value'); - $xml = $this->_response->saveXml(); - $this->_testXmlResponse($xml); - } - - /** - * __toString() test - */ - public function test__toString() - { - $this->_response->setReturnValue('return value'); - $xml = $this->_response->__toString(); - $this->_testXmlResponse($xml); - } - - /** - * Test encoding settings - */ - public function testSetGetEncoding() - { - $this->assertEquals('UTF-8', $this->_response->getEncoding()); - $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - $this->assertSame($this->_response, $this->_response->setEncoding('ISO-8859-1')); - $this->assertEquals('ISO-8859-1', $this->_response->getEncoding()); - $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - } - - public function testLoadXmlThrowsExceptionWithMissingNodes() - { - $sxl = new SimpleXMLElement('foo'); - $this->_loadXml($sxl->asXML()); - $sxl = new SimpleXMLElement('foo'); - $this->_loadXml($sxl->asXML()); - $sxl = new SimpleXMLElement('foo'); - $this->_loadXml($sxl->asXML()); - } - - protected function _loadXml($xml) - { - try { - $this->_response->loadXml($xml); - $this->fail('Invalid XML-RPC response should raise an exception'); - } catch (Exception $e) { - } - } - - public function trackError($error) - { - $this->_errorOccured = true; - } - - /** - * @group ZF-12293 - */ - public function testDoesNotAllowExternalEntities() - { - $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml'); - $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt')); - $this->_response->loadXml($payload); - $value = $this->_response->getReturnValue(); - $this->assertTrue(empty($value)); - if (is_string($value)) { - $this->assertNotContains('Local file inclusion', $value); - } - } - - public function testShouldDisallowsDoctypeInRequestXmlAndReturnFalseOnLoading() - { - $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml'); - $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt')); - $this->assertFalse($this->_response->loadXml($payload)); - } -} diff --git a/tests/Zend/XmlRpc/Server/CacheTest.php b/tests/Zend/XmlRpc/Server/CacheTest.php deleted file mode 100644 index 44b1c52c8c..0000000000 --- a/tests/Zend/XmlRpc/Server/CacheTest.php +++ /dev/null @@ -1,133 +0,0 @@ -_file = realpath(dirname(__FILE__)) . '/xmlrpc.cache'; - $this->_server = new Zend_XmlRpc_Server(); - $this->_server->setClass('Zend_XmlRpc_Server_Cache', 'cache'); - } - - /** - * Teardown environment - */ - public function tearDown() - { - if (file_exists($this->_file)) { - unlink($this->_file); - } - unset($this->_server); - } - - /** - * Tests functionality of both get() and save() - */ - public function testGetSave() - { - if (!is_writeable('./')) { - $this->markTestIncomplete('Directory no writable'); - } - - $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server)); - $expected = $this->_server->listMethods(); - $server = new Zend_XmlRpc_Server(); - $this->assertTrue(Zend_XmlRpc_Server_Cache::get($this->_file, $server)); - $actual = $server->listMethods(); - - $this->assertSame($expected, $actual); - } - - /** - * Zend_XmlRpc_Server_Cache::delete() test - */ - public function testDelete() - { - if (!is_writeable('./')) { - $this->markTestIncomplete('Directory no writable'); - } - - $this->assertTrue(Zend_XmlRpc_Server_Cache::save($this->_file, $this->_server)); - $this->assertTrue(Zend_XmlRpc_Server_Cache::delete($this->_file)); - } - - public function testShouldReturnFalseWithInvalidCache() - { - if (!is_writeable('./')) { - $this->markTestIncomplete('Directory no writable'); - } - - file_put_contents($this->_file, 'blahblahblah'); - $server = new Zend_XmlRpc_Server(); - $this->assertFalse(Zend_XmlRpc_Server_Cache::get($this->_file, $server)); - } -} - -// Call Zend_XmlRpc_Server_CacheTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Server_CacheTest::main") { - Zend_XmlRpc_Server_CacheTest::main(); -} diff --git a/tests/Zend/XmlRpc/Server/FaultTest.php b/tests/Zend/XmlRpc/Server/FaultTest.php deleted file mode 100644 index a82236bbae..0000000000 --- a/tests/Zend/XmlRpc/Server/FaultTest.php +++ /dev/null @@ -1,294 +0,0 @@ -assertTrue($fault instanceof Zend_XmlRpc_Server_Fault); - } - - /** - * Zend_XmlRpc_Server_Fault::attachFaultException() test - */ - public function testAttachFaultException() - { - Zend_XmlRpc_Server_Fault::attachFaultException('zxrs_fault_test_exception'); - $e = new zxrs_fault_test_exception('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('test exception', $fault->getMessage()); - $this->assertEquals(411, $fault->getCode()); - Zend_XmlRpc_Server_Fault::detachFaultException('zxrs_fault_test_exception'); - - $exceptions = array( - 'zxrs_fault_test_exception', - 'zxrs_fault_test_exception2', - 'zxrs_fault_test_exception3' - ); - Zend_XmlRpc_Server_Fault::attachFaultException($exceptions); - foreach ($exceptions as $class) { - $e = new $class('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('test exception', $fault->getMessage()); - $this->assertEquals(411, $fault->getCode()); - } - Zend_XmlRpc_Server_Fault::detachFaultException($exceptions); - } - - /** - * Tests ZF-1825 - * @return void - */ - public function testAttachFaultExceptionAllowsForDerivativeExceptionClasses() - { - Zend_XmlRpc_Server_Fault::attachFaultException('zxrs_fault_test_exception'); - $e = new zxrs_fault_test_exception4('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('test exception', $fault->getMessage()); - $this->assertEquals(411, $fault->getCode()); - Zend_XmlRpc_Server_Fault::detachFaultException('zxrs_fault_test_exception'); - } - - /** - * Zend_XmlRpc_Server_Fault::detachFaultException() test - */ - public function testDetachFaultException() - { - Zend_XmlRpc_Server_Fault::attachFaultException('zxrs_fault_test_exception'); - $e = new zxrs_fault_test_exception('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('test exception', $fault->getMessage()); - $this->assertEquals(411, $fault->getCode()); - Zend_XmlRpc_Server_Fault::detachFaultException('zxrs_fault_test_exception'); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('Unknown error', $fault->getMessage()); - $this->assertEquals(404, $fault->getCode()); - - - $exceptions = array( - 'zxrs_fault_test_exception', - 'zxrs_fault_test_exception2', - 'zxrs_fault_test_exception3' - ); - Zend_XmlRpc_Server_Fault::attachFaultException($exceptions); - foreach ($exceptions as $class) { - $e = new $class('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('test exception', $fault->getMessage()); - $this->assertEquals(411, $fault->getCode()); - } - Zend_XmlRpc_Server_Fault::detachFaultException($exceptions); - foreach ($exceptions as $class) { - $e = new $class('test exception', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $this->assertEquals('Unknown error', $fault->getMessage()); - $this->assertEquals(404, $fault->getCode()); - } - } - - /** - * Zend_XmlRpc_Server_Fault::attachObserver() test - */ - public function testAttachObserver() - { - Zend_XmlRpc_Server_Fault::attachObserver('zxrs_fault_observer'); - $e = new Zend_XmlRpc_Server_Exception('Checking observers', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $observed = zxrs_fault_observer::getObserved(); - zxrs_fault_observer::clearObserved(); - Zend_XmlRpc_Server_Fault::detachObserver('zxrs_fault_observer'); - - $this->assertTrue(!empty($observed)); - $f = array_shift($observed); - $this->assertTrue($f instanceof Zend_XmlRpc_Server_Fault); - $this->assertEquals('Checking observers', $f->getMessage()); - $this->assertEquals(411, $f->getCode()); - - $this->assertFalse(Zend_XmlRpc_Server_Fault::attachObserver('foo')); - } - - /** - * Zend_XmlRpc_Server_Fault::detachObserver() test - */ - public function testDetachObserver() - { - Zend_XmlRpc_Server_Fault::attachObserver('zxrs_fault_observer'); - $e = new Zend_XmlRpc_Server_Exception('Checking observers', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - zxrs_fault_observer::clearObserved(); - Zend_XmlRpc_Server_Fault::detachObserver('zxrs_fault_observer'); - - $e = new Zend_XmlRpc_Server_Exception('Checking observers', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - $observed = zxrs_fault_observer::getObserved(); - $this->assertTrue(empty($observed)); - - $this->assertFalse(Zend_XmlRpc_Server_Fault::detachObserver('foo')); - } - - /** - * getCode() test - */ - public function testGetCode() - { - $e = new Zend_XmlRpc_Server_Exception('Testing fault', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - - $this->assertEquals(411, $fault->getCode()); - } - - /** - * getException() test - */ - public function testGetException() - { - $e = new Zend_XmlRpc_Server_Exception('Testing fault', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - - $this->assertSame($e, $fault->getException()); - } - - /** - * getMessage() test - */ - public function testGetMessage() - { - $e = new Zend_XmlRpc_Server_Exception('Testing fault', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - - $this->assertEquals('Testing fault', $fault->getMessage()); - } - - /** - * __toString() test - */ - public function test__toString() - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $r = $dom->appendChild($dom->createElement('methodResponse')); - $f = $r->appendChild($dom->createElement('fault')); - $v = $f->appendChild($dom->createElement('value')); - $s = $v->appendChild($dom->createElement('struct')); - - $m1 = $s->appendChild($dom->createElement('member')); - $m1->appendChild($dom->createElement('name', 'faultCode')); - $cv = $m1->appendChild($dom->createElement('value')); - $cv->appendChild($dom->createElement('int', 411)); - - $m2 = $s->appendChild($dom->createElement('member')); - $m2->appendChild($dom->createElement('name', 'faultString')); - $sv = $m2->appendChild($dom->createElement('value')); - $sv->appendChild($dom->createElement('string', 'Testing fault')); - - $xml = $dom->saveXML(); - - require_once 'Zend/XmlRpc/Server/Exception.php'; - $e = new Zend_XmlRpc_Server_Exception('Testing fault', 411); - $fault = Zend_XmlRpc_Server_Fault::getInstance($e); - - $this->assertEquals(trim($xml), trim($fault->__toString())); - } -} - -class zxrs_fault_test_exception extends Exception {} -class zxrs_fault_test_exception2 extends Exception {} -class zxrs_fault_test_exception3 extends Exception {} -class zxrs_fault_test_exception4 extends zxrs_fault_test_exception {} - -class zxrs_fault_observer -{ - private static $_instance = false; - - public $observed = array(); - - private function __construct() - { - } - - public static function getInstance() - { - if (!self::$_instance) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - public static function observe(Zend_XmlRpc_Server_Fault $fault) - { - self::getInstance()->observed[] = $fault; - } - - public static function clearObserved() - { - self::getInstance()->observed = array(); - } - - public static function getObserved() - { - return self::getInstance()->observed; - } -} - -// Call Zend_XmlRpc_Server_FaultTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Server_FaultTest::main") { - Zend_XmlRpc_Server_FaultTest::main(); -} diff --git a/tests/Zend/XmlRpc/ServerTest.php b/tests/Zend/XmlRpc/ServerTest.php deleted file mode 100644 index a8cc0898dd..0000000000 --- a/tests/Zend/XmlRpc/ServerTest.php +++ /dev/null @@ -1,780 +0,0 @@ -_server = new Zend_XmlRpc_Server(); - } - - /** - * Teardown environment - */ - public function tearDown() - { - unset($this->_server); - } - - /** - * __construct() test - * - * Call as method call - * - * Returns: void - */ - public function test__construct() - { - $this->assertTrue($this->_server instanceof Zend_XmlRpc_Server); - } - - /** - * addFunction() test - * - * Call as method call - * - * Expects: - * - function: - * - namespace: Optional; has default; - * - * Returns: void - */ - public function testAddFunction() - { - try { - $this->_server->addFunction('Zend_XmlRpc_Server_testFunction', 'zsr'); - } catch (Zend_XmlRpc_Exception $e) { - $this->fail('Attachment should have worked'); - } - - $methods = $this->_server->listMethods(); - $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction', $methods)); - - try { - $this->_server->addFunction('nosuchfunction'); - $this->fail('nosuchfunction() should not exist and should throw an exception'); - } catch (Zend_XmlRpc_Exception $e) { - // do nothing - } - - $server = new Zend_XmlRpc_Server(); - try { - $server->addFunction( - array( - 'Zend_XmlRpc_Server_testFunction', - 'Zend_XmlRpc_Server_testFunction2', - ), - 'zsr' - ); - } catch (Zend_XmlRpc_Exception $e) { - $this->fail('Error attaching array of functions: ' . $e->getMessage()); - } - $methods = $server->listMethods(); - $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction', $methods)); - $this->assertTrue(in_array('zsr.Zend_XmlRpc_Server_testFunction2', $methods)); - } - - /** - * get/loadFunctions() test - */ - public function testFunctions() - { - try { - $this->_server->addFunction( - array( - 'Zend_XmlRpc_Server_testFunction', - 'Zend_XmlRpc_Server_testFunction2', - ), - 'zsr' - ); - } catch (Zend_XmlRpc_Exception $e) { - $this->fail('Error attaching functions: ' . $e->getMessage()); - } - - $expected = $this->_server->listMethods(); - - $functions = $this->_server->getFunctions(); - $server = new Zend_XmlRpc_Server(); - $server->loadFunctions($functions); - $actual = $server->listMethods(); - - $this->assertSame($expected, $actual); - } - - /** - * setClass() test - */ - public function testSetClass() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test'); - $methods = $this->_server->listMethods(); - $this->assertTrue(in_array('test.test1', $methods)); - $this->assertTrue(in_array('test.test2', $methods)); - $this->assertFalse(in_array('test._test3', $methods)); - $this->assertFalse(in_array('test.__construct', $methods)); - } - - /** - * @group ZF-6526 - */ - public function testSettingClassWithArguments() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'argv-argument'); - $this->assertTrue($this->_server->sendArgumentsToAllMethods()); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('test.test4'); - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertSame( - array('test1' => 'argv-argument', - 'test2' => null, - 'arg' => array('argv-argument')), - $response->getReturnValue()); - } - - public function testSettingClassWithArgumentsOnlyPassingToConstructor() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'a1', 'a2'); - $this->_server->sendArgumentsToAllMethods(false); - $this->assertFalse($this->_server->sendArgumentsToAllMethods()); - - $request = new Zend_XmlRpc_Request(); - $request->setMethod('test.test4'); - $request->setParams(array('foo')); - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertSame(array('test1' => 'a1', 'test2' => 'a2', 'arg' => array('foo')), $response->getReturnValue()); - } - - /** - * fault() test - */ - public function testFault() - { - $fault = $this->_server->fault('This is a fault', 411); - $this->assertTrue($fault instanceof Zend_XmlRpc_Server_Fault); - $this->assertEquals(411, $fault->getCode()); - $this->assertEquals('This is a fault', $fault->getMessage()); - - $fault = $this->_server->fault(new Zend_XmlRpc_Server_Exception('Exception fault', 511)); - $this->assertTrue($fault instanceof Zend_XmlRpc_Server_Fault); - $this->assertEquals(511, $fault->getCode()); - $this->assertEquals('Exception fault', $fault->getMessage()); - } - - /** - * handle() test - * - * Call as method call - * - * Expects: - * - request: Optional; - * - * Returns: Zend_XmlRpc_Response|Zend_XmlRpc_Fault - */ - public function testHandle() - { - $request = new Zend_XmlRpc_Request(); - $request->setMethod('system.listMethods'); - $response = $this->_server->handle($request); - - $this->assertTrue($response instanceof Zend_XmlRpc_Response); - $return = $response->getReturnValue(); - $this->assertTrue(is_array($return)); - $this->assertTrue(in_array('system.multicall', $return)); - } - - /** - * Test that only calling methods using a valid parameter signature works - */ - public function testHandle2() - { - $request = new Zend_XmlRpc_Request(); - $request->setMethod('system.methodHelp'); - $response = $this->_server->handle($request); - - $this->assertTrue($response instanceof Zend_XmlRpc_Fault); - $this->assertEquals(623, $response->getCode()); - } - - public function testCallingInvalidMethod() - { - $request = new Zend_XmlRpc_Request(); - $request->setMethod('invalid'); - $response = $this->_server->handle($request); - $this->assertTrue($response instanceof Zend_XmlRpc_Fault); - $this->assertSame('Method "invalid" does not exist', $response->getMessage()); - $this->assertSame(620, $response->getCode()); - } - - - /** - * setResponseClass() test - * - * Call as method call - * - * Expects: - * - class: - * - * Returns: boolean - */ - public function testSetResponseClass() - { - $this->assertTrue($this->_server->setResponseClass('Zend_XmlRpc_Server_testResponse')); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('system.listMethods'); - $response = $this->_server->handle($request); - - $this->assertTrue($response instanceof Zend_XmlRpc_Response); - $this->assertTrue($response instanceof Zend_XmlRpc_Server_testResponse); - } - - /** - * listMethods() test - * - * Call as method call - * - * Returns: array - */ - public function testListMethods() - { - $methods = $this->_server->listMethods(); - $this->assertTrue(is_array($methods)); - $this->assertTrue(in_array('system.listMethods', $methods)); - $this->assertTrue(in_array('system.methodHelp', $methods)); - $this->assertTrue(in_array('system.methodSignature', $methods)); - $this->assertTrue(in_array('system.multicall', $methods)); - } - - /** - * methodHelp() test - * - * Call as method call - * - * Expects: - * - method: - * - * Returns: string - */ - public function testMethodHelp() - { - $help = $this->_server->methodHelp('system.methodHelp', 'system.listMethods'); - $this->assertContains('Display help message for an XMLRPC method', $help); - - $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Method "foo" does not exist'); - $this->_server->methodHelp('foo'); - } - - /** - * methodSignature() test - * - * Call as method call - * - * Expects: - * - method: - * - * Returns: array - */ - public function testMethodSignature() - { - $sig = $this->_server->methodSignature('system.methodSignature'); - $this->assertTrue(is_array($sig)); - $this->assertEquals(1, count($sig), var_export($sig, 1)); - - $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Method "foo" does not exist'); - $this->_server->methodSignature('foo'); - } - - /** - * multicall() test - * - * Call as method call - * - * Expects: - * - methods: - * - * Returns: array - */ - public function testMulticall() - { - $struct = array( - array( - 'methodName' => 'system.listMethods', - 'params' => array() - ), - array( - 'methodName' => 'system.methodHelp', - 'params' => array('system.multicall') - ) - ); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('system.multicall'); - $request->addParam($struct); - $response = $this->_server->handle($request); - - $this->assertTrue($response instanceof Zend_XmlRpc_Response, $response->__toString() . "\n\n" . $request->__toString()); - $returns = $response->getReturnValue(); - $this->assertTrue(is_array($returns)); - $this->assertEquals(2, count($returns), var_export($returns, 1)); - $this->assertTrue(is_array($returns[0]), var_export($returns[0], 1)); - $this->assertTrue(is_string($returns[1]), var_export($returns[1], 1)); - } - - /** - * @group ZF-5635 - */ - public function testMulticallHandlesFaults() - { - $struct = array( - array( - 'methodName' => 'system.listMethods', - 'params' => array() - ), - array( - 'methodName' => 'undefined', - 'params' => array() - ) - ); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('system.multicall'); - $request->addParam($struct); - $response = $this->_server->handle($request); - - $this->assertTrue($response instanceof Zend_XmlRpc_Response, $response->__toString() . "\n\n" . $request->__toString()); - $returns = $response->getReturnValue(); - $this->assertTrue(is_array($returns)); - $this->assertEquals(2, count($returns), var_export($returns, 1)); - $this->assertTrue(is_array($returns[0]), var_export($returns[0], 1)); - $this->assertSame(array( - 'faultCode' => 620, 'faultString' => 'Method "undefined" does not exist'), - $returns[1], var_export($returns[1], 1)); - } - - /** - * Test get/setEncoding() - */ - public function testGetSetEncoding() - { - $this->assertEquals('UTF-8', $this->_server->getEncoding()); - $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - $this->assertSame($this->_server, $this->_server->setEncoding('ISO-8859-1')); - $this->assertEquals('ISO-8859-1', $this->_server->getEncoding()); - $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding()); - } - - /** - * Test request/response encoding - */ - public function testRequestResponseEncoding() - { - $response = $this->_server->handle(); - $request = $this->_server->getRequest(); - - $this->assertEquals('UTF-8', $request->getEncoding()); - $this->assertEquals('UTF-8', $response->getEncoding()); - } - - /** - * Test request/response encoding (alternate encoding) - */ - public function testRequestResponseEncoding2() - { - $this->_server->setEncoding('ISO-8859-1'); - $response = $this->_server->handle(); - $request = $this->_server->getRequest(); - - $this->assertEquals('ISO-8859-1', $request->getEncoding()); - $this->assertEquals('ISO-8859-1', $response->getEncoding()); - } - - public function testAddFunctionWithExtraArgs() - { - $this->_server->addFunction('Zend_XmlRpc_Server_testFunction', 'test', 'arg1'); - $methods = $this->_server->listMethods(); - $this->assertContains('test.Zend_XmlRpc_Server_testFunction', $methods); - } - - public function testAddFunctionThrowsExceptionWithBadData() - { - $o = new stdClass(); - try { - $this->_server->addFunction($o); - $this->fail('addFunction() should not accept objects'); - } catch (Zend_XmlRpc_Exception $e) { - // success - } - } - - public function testLoadFunctionsThrowsExceptionWithBadData() - { - $o = new stdClass(); - try { - $this->_server->loadFunctions($o); - $this->fail('loadFunctions() should not accept objects'); - } catch (Zend_XmlRpc_Exception $e) { - // success - } - - try { - $this->_server->loadFunctions('foo'); - $this->fail('loadFunctions() should not accept primitive values'); - } catch (Zend_XmlRpc_Server_Exception $e) { - // success - } - - $o = array($o); - try { - $this->_server->loadFunctions($o); - $this->fail('loadFunctions() should not allow non-reflection objects in an array'); - } catch (Zend_Server_Exception $e) { - $this->assertSame('Invalid method provided', $e->getMessage()); - } - } - - public function testLoadFunctionsReadsMethodsFromServerDefinitionObjects() - { - $mockedMethod = $this->getMock('Zend_Server_Method_Definition', array(), array(), '', false, - false); - $mockedDefinition = $this->getMock('Zend_Server_Definition', array(), array(), '', false, false); - $mockedDefinition->expects($this->once()) - ->method('getMethods') - ->will($this->returnValue(array('bar' => $mockedMethod))); - $this->_server->loadFunctions($mockedDefinition); - } - - public function testSetClassThrowsExceptionWithInvalidClass() - { - try { - $this->_server->setClass('mybogusclass'); - $this->fail('setClass() should not allow invalid classes'); - } catch (Zend_XmlRpc_Exception $e) { - } - } - - public function testSetRequestUsingString() - { - $this->_server->setRequest('Zend_XmlRpc_Server_testRequest'); - $req = $this->_server->getRequest(); - $this->assertTrue($req instanceof Zend_XmlRpc_Server_testRequest); - } - - public function testSetRequestThrowsExceptionOnBadClass() - { - try { - $this->_server->setRequest('Zend_XmlRpc_Server_testRequest2'); - $this->fail('Invalid request class should throw exception'); - } catch (Zend_XmlRpc_Exception $e) { - // success - } - - try { - $this->_server->setRequest($this); - $this->fail('Invalid request object should throw exception'); - } catch (Zend_XmlRpc_Exception $e) { - // success - } - } - - public function testHandleObjectMethod() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass'); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('test1'); - $request->addParam('value'); - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertEquals('String: value', $response->getReturnValue()); - } - - public function testHandleClassStaticMethod() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass'); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('test2'); - $request->addParam(array('value1', 'value2')); - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertEquals('value1; value2', $response->getReturnValue()); - } - - public function testHandleFunction() - { - $this->_server->addFunction('Zend_XmlRpc_Server_testFunction'); - $request = new Zend_XmlRpc_Request(); - $request->setMethod('Zend_XmlRpc_Server_testFunction'); - $request->setParams(array(array('value1'), 'key')); - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertEquals('key: value1', $response->getReturnValue()); - } - - public function testMulticallReturnsFaultsWithBadData() - { - // bad method array - $try = array( - 'system.listMethods', - array( - 'name' => 'system.listMethods' - ), - array( - 'methodName' => 'system.listMethods' - ), - array( - 'methodName' => 'system.listMethods', - 'params' => '' - ), - array( - 'methodName' => 'system.multicall', - 'params' => array() - ) - ); - $returned = $this->_server->multicall($try); - $this->assertTrue(is_array($returned)); - $this->assertEquals(5, count($returned)); - - $response = $returned[0]; - $this->assertTrue(is_array($response)); - $this->assertTrue(isset($response['faultCode'])); - $this->assertEquals(601, $response['faultCode']); - - $response = $returned[1]; - $this->assertTrue(is_array($response)); - $this->assertTrue(isset($response['faultCode'])); - $this->assertEquals(602, $response['faultCode']); - - $response = $returned[2]; - $this->assertTrue(is_array($response)); - $this->assertTrue(isset($response['faultCode'])); - $this->assertEquals(603, $response['faultCode']); - - $response = $returned[3]; - $this->assertTrue(is_array($response)); - $this->assertTrue(isset($response['faultCode'])); - $this->assertEquals(604, $response['faultCode']); - - $response = $returned[4]; - $this->assertTrue(is_array($response)); - $this->assertTrue(isset($response['faultCode'])); - $this->assertEquals(605, $response['faultCode']); - } - - /** - * @group ZF-2872 - */ - public function testCanMarshalBase64Requests() - { - $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test'); - $data = base64_encode('this is the payload'); - $param = array('type' => 'base64', 'value' => $data); - $request = new Zend_XmlRpc_Request('test.base64', array($param)); - - $response = $this->_server->handle($request); - $this->assertFalse($response instanceof Zend_XmlRpc_Fault); - $this->assertEquals($data, $response->getReturnValue()); - } - - /** - * @group ZF-6034 - */ - public function testPrototypeReturnValueMustReflectDocBlock() - { - $server = new Zend_XmlRpc_Server(); - $server->setClass('Zend_XmlRpc_Server_testClass'); - $table = $server->getDispatchTable(); - $method = $table->getMethod('test1'); - foreach ($method->getPrototypes() as $prototype) { - $this->assertNotEquals('void', $prototype->getReturnType(), var_export($prototype, 1)); - } - } - - public function testCallingUnregisteredMethod() - { - $this->setExpectedException('Zend_XmlRpc_Server_Exception', - 'Unknown instance method called on server: foobarbaz'); - $this->_server->foobarbaz(); - } - - public function testSetPersistenceDoesNothing() - { - $this->assertNull($this->_server->setPersistence('foo')); - $this->assertNull($this->_server->setPersistence('whatever')); - } - - public function testPassingInvalidRequestClassThrowsException() - { - $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid request class'); - $this->_server->setRequest('stdClass'); - } - - public function testPassingInvalidResponseClassThrowsException() - { - $this->setExpectedException('Zend_XmlRpc_Server_Exception', 'Invalid response class'); - $this->_server->setResponseClass('stdClass'); - } - - public function testCreatingFaultWithEmptyMessageResultsInUnknownError() - { - $fault = $this->_server->fault('', 123); - $this->assertSame('Unknown Error', $fault->getMessage()); - $this->assertSame(123, $fault->getCode()); - } -} - -/** - * Zend_XmlRpc_Server_testFunction - * - * Function for use with xmlrpc server unit tests - * - * @param array $var1 - * @param string $var2 - * @return string - */ -function Zend_XmlRpc_Server_testFunction($var1, $var2 = 'optional') -{ - return $var2 . ': ' . implode(',', (array) $var1); -} - -/** - * Zend_XmlRpc_Server_testFunction2 - * - * Function for use with xmlrpc server unit tests - * - * @return string - */ -function Zend_XmlRpc_Server_testFunction2() -{ - return 'function2'; -} - - -class Zend_XmlRpc_Server_testClass -{ - private $_value1; - private $_value2; - - /** - * Constructor - * - * @return void - */ - public function __construct($value1 = null, $value2 = null) - { - $this->_value1 = $value1; - $this->_value2 = $value2; - } - - /** - * Test1 - * - * Returns 'String: ' . $string - * - * @param string $string - * @return string - */ - public function test1($string) - { - return 'String: ' . (string) $string; - } - - /** - * Test2 - * - * Returns imploded array - * - * @param array $array - * @return string - */ - public static function test2($array) - { - return implode('; ', (array) $array); - } - - /** - * Test3 - * - * Should not be available... - * - * @return void - */ - protected function _test3() - { - } - - /** - * @param string $arg - * @return struct - */ - public function test4($arg) - { - return array('test1' => $this->_value1, 'test2' => $this->_value2, 'arg' => func_get_args()); - } - - /** - * Test base64 encoding in request and response - * - * @param base64 $data - * @return base64 - */ - public function base64($data) - { - return $data; - } -} - -class Zend_XmlRpc_Server_testResponse extends Zend_XmlRpc_Response -{ -} - -class Zend_XmlRpc_Server_testRequest extends Zend_XmlRpc_Request -{ -} - -// Call Zend_XmlRpc_ServerTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ServerTest::main") { - Zend_XmlRpc_ServerTest::main(); -} diff --git a/tests/Zend/XmlRpc/TestProvider.php b/tests/Zend/XmlRpc/TestProvider.php deleted file mode 100644 index fa089ec49f..0000000000 --- a/tests/Zend/XmlRpc/TestProvider.php +++ /dev/null @@ -1,43 +0,0 @@ -assertXmlRpcType('boolean', $val); - } - } - - public function testMarshalBooleanFromNative() - { - $native = true; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN); - - $this->assertXmlRpcType('boolean', $val); - $this->assertSame($native, $val->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalBooleanFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $xml = '1'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('boolean', $val); - $this->assertEquals('boolean', $val->getType()); - $this->assertSame(true, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - // Integer - - public function testFactoryAutodetectsInteger() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(1); - $this->assertXmlRpcType('integer', $val); - } - - public function testMarshalIntegerFromNative() - { - $native = 1; - $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_I4, - Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER); - - foreach ($types as $type) { - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, $type); - $this->assertXmlRpcType('integer', $val); - $this->assertSame($native, $val->getValue()); - } - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalIntegerFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - - $native = 1; - $xmls = array("$native", - "$native"); - - foreach ($xmls as $xml) { - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - $this->assertXmlRpcType('integer', $val); - $this->assertEquals('int', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - } - - /** - * @group ZF-3310 - */ - public function testMarshalI4FromOverlongNativeThrowsException() - { - $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given'); - $x = Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 5000, Zend_XmlRpc_Value::XMLRPC_TYPE_I4); - } - - /** - * @group ZF-3310 - */ - public function testMarshalIntegerFromOverlongNativeThrowsException() - { - $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given'); - Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 5000, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER); - } - - // Double - - public function testFactoryAutodetectsFloat() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue((float)1); - $this->assertXmlRpcType('double', $val); - } - - public function testMarshalDoubleFromNative() - { - $native = 1.1; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE); - - $this->assertXmlRpcType('double', $val); - $this->assertSame($native, $val->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalDoubleFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = 1.1; - $xml = "$native"; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('double', $val); - $this->assertEquals('double', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @group ZF-7712 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingDoubleWithHigherPrecisionFromNative(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - if (ini_get('precision') < 7) { - $this->markTestSkipped('precision is too low'); - } - - $native = 0.1234567; - $value = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE); - $this->assertXmlRpcType('double', $value); - $this->assertSame($native, $value->getValue()); - $this->assertSame('0.1234567', trim($value->saveXml())); - } - - /** - * @group ZF-7712 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingDoubleWithHigherPrecisionFromNativeWithTrailingZeros(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - if (ini_get('precision') < 7) { - $this->markTestSkipped('precision is too low'); - } - $native = 0.1; - $value = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE); - $this->assertXmlRpcType('double', $value); - $this->assertSame($native, $value->getValue()); - $this->assertSame('0.1', trim($value->saveXml())); - } - - // String - - public function testFactoryAutodetectsString() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(''); - $this->assertXmlRpcType('string', $val); - } - - - public function testMarshalStringFromNative() - { - $native = 'foo'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_STRING); - - $this->assertXmlRpcType('string', $val); - $this->assertSame($native, $val->getValue()); - } - - public function testFactoryAutodetectsStringAndSetsValueInArray() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(''. - '8'. - 'a'. - 'false'. - '', Zend_XmlRpc_Value::XML_STRING - ); - $this->assertXmlRpcType('array', $val); - $a = $val->getValue(); - $this->assertSame(8, $a[0]); - $this->assertSame('a', $a[1]); - $this->assertSame('false', $a[2]); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalStringFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = 'foo<>'; - $xml = "foo<>"; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('string', $val); - $this->assertEquals('string', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalStringFromDefault(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = 'foo
bar'; - $xml = "foo<br/>bar"; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('string', $val); - $this->assertEquals('string', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - //Nil - - public function testFactoryAutodetectsNil() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(NULL); - $this->assertXmlRpcType('nil', $val); - } - - public function testMarshalNilFromNative() - { - $native = NULL; - $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_NIL, - Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL); - foreach ($types as $type) { - $value = Zend_XmlRpc_Value::getXmlRpcValue($native, $type); - - $this->assertXmlRpcType('nil', $value); - $this->assertSame($native, $value->getValue()); - } - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalNilFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $xmls = array('', - ''); - - foreach ($xmls as $xml) { - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - $this->assertXmlRpcType('nil', $val); - $this->assertEquals('nil', $val->getType()); - $this->assertSame(NULL, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - } - - // Array - - public function testFactoryAutodetectsArray() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(array(0, 'foo')); - $this->assertXmlRpcType('array', $val); - } - - public function testMarshalArrayFromNative() - { - $native = array(0,1); - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY); - - $this->assertXmlRpcType('array', $val); - $this->assertSame($native, $val->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalArrayFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array(0,1); - $xml = '0' - . '1'; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('array', $val); - $this->assertEquals('array', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testEmptyXmlRpcArrayResultsInEmptyArray(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array(); - $xml = ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('array', $val); - $this->assertEquals('array', $val->getType()); - $this->assertSame($native, $val->getValue()); - - $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING); - $this->assertXmlRpcType('array', $value); - $this->assertEquals('array', $value->getType()); - $this->assertSame($native, $value->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testArrayMustContainDataElement(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array(); - $xml = ''; - - $this->setExpectedException('Zend_XmlRpc_Value_Exception', - 'Invalid XML for XML-RPC native array type: ARRAY tag must contain DATA tag'); - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - } - - /** - * @group ZF-5405 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalNilInStructWrappedInArray(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $expected = array(array('id' => '1', 'name' => 'vertebra, caudal', 'description' => null)); - $xml = '' - . 'id1' - . 'namevertebra, caudal' - . 'description' - . ''; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING); - $this->assertSame($expected, $val->getValue()); - } - - // Struct - - public function testFactoryAutodetectsStruct() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue(array('foo' => 0)); - $this->assertXmlRpcType('struct', $val); - } - - public function testFactoryAutodetectsStructFromObject() - { - $val = Zend_XmlRpc_Value::getXmlRpcValue((object)array('foo' => 0)); - $this->assertXmlRpcType('struct', $val); - } - - public function testMarshalStructFromNative() - { - $native = array('foo' => 0); - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT); - - $this->assertXmlRpcType('struct', $val); - $this->assertSame($native, $val->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalStructFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => 0, 'bar' => 'foo<>bar'); - $xml = 'foo0' - . 'bar' - . 'foo<>bar'; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingNestedStructFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => array('bar' => '
')); - $xml = 'foo' - . 'bar<br/>' - . ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertSame($this->wrapXml($xml), $val->saveXml()); - - $val = Zend_XmlRpc_Value::getXmlRpcValue($native); - $this->assertSame(trim($xml), trim($val->saveXml())); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingStructWithMemberWithoutValue(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => 0, 'bar' => 1); - $xml = '' - . 'foo0' - . 'foo' - . 'bar1' - . ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingStructWithMemberWithoutName(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => 0, 'bar' => 1); - $xml = '' - . 'foo0' - . 'foo' - . 'bar1' - . ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @group ZF-7639 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalStructFromXmlRpcWithEntities(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array(' ' => 0); - $xml = '&nbsp;0' - . ''; - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING); - $this->assertXmlRpcType('struct', $val); - $this->assertSame($native, $val->getValue()); - $this->assertSame($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @group ZF-3947 - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingStructsWithEmptyValueFromXmlRpcShouldRetainKeys(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => ''); - $xml = 'foo' - . ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshallingStructWithMultibyteValueFromXmlRpcRetainsMultibyteValue(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = array('foo' => 'ß'); - $xmlDecl = ''; - $xml = 'fooß'; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xmlDecl . $xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('struct', $val); - $this->assertEquals('struct', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT); - $this->assertSame($native, $val->getValue()); - $this->assertSame(trim($xml), trim($val->saveXml())); - } - - // DateTime - - public function testMarshalDateTimeFromNativeString() - { - $native = '1997-07-16T19:20+01:00'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - - $this->assertXmlRpcType('dateTime', $val); - - $expected = new Datetime($native); - $this->assertSame($expected->format($this->xmlRpcDateFormat), $val->getValue()); - } - - public function testMarshalDateTimeFromNativeStringProducesIsoOutput() - { - $native = '1997-07-16T19:20+01:00'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - - $this->assertXmlRpcType('dateTime', $val); - - $expected = new DateTime($native); - $received = $val->getValue(); - $this->assertEquals($expected->format($this->xmlRpcDateFormat), $received); - } - - public function testMarshalDateTimeFromInvalidString() - { - $phpunitVersion = PHPUnit_Runner_Version::id(); - if (version_compare($phpunitVersion, '3.7.0', '<=')) { - $this->markTestSkipped('Cannot expect generic exceptions prior to PHPUnit 3.7.'); - } - - $this->setExpectedException('Exception', "foobarbaz"); - Zend_XmlRpc_Value::getXmlRpcValue('foobarbaz', Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - } - - public function testMarshalDateTimeFromNativeInteger() - { - $native = strtotime('1997-07-16T19:20+01:00'); - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - - $this->assertXmlRpcType('dateTime', $val); - $this->assertSame($native, strtotime($val->getValue())); - } - - /** - * @group ZF-11588 - */ - public function testMarshalDateTimeBeyondUnixEpochFromNativeStringPassedToConstructor() - { - $native = '2040-01-01T00:00:00'; - $value = new Zend_XmlRpc_Value_DateTime($native); - $expected = new DateTime($native); - $this->assertSame($expected->format($this->xmlRpcDateFormat), $value->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalDateTimeFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $iso8601 = '1997-07-16T19:20+01:00'; - $xml = "$iso8601"; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('dateTime', $val); - $this->assertEquals('dateTime.iso8601', $val->getType()); - - $expected = new DateTime($iso8601); - $this->assertSame($expected->format($this->xmlRpcDateFormat), $val->getValue()); - - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - * @group ZF-4249 - */ - public function testMarshalDateTimeFromFromZendDate(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $date = new Zend_Date(array('year' => 2039, 'month' => 4, 'day' => 18, - 'hour' => 13, 'minute' => 14, 'second' => 15)); - $dateString = '20390418T13:14:15'; - $xml = "$dateString"; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($date, Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - $this->assertXmlRpcType('dateTime', $val); - $this->assertEquals('dateTime.iso8601', $val->getType()); - $this->assertSame($dateString, $val->getValue()); - $this->assertEquals(trim($xml), trim($val->saveXml())); - - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - * @group ZF-4249 - */ - public function testMarshalDateTimeFromZendDateAndAutodetectingType(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $date = new Zend_Date(array('year' => 2039, 'month' => 4, 'day' => 18, - 'hour' => 13, 'minute' => 14, 'second' => 15)); - $dateString = '20390418T13:14:15'; - $xml = "$dateString"; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($date, Zend_XmlRpc_Value::AUTO_DETECT_TYPE); - $this->assertXmlRpcType('dateTime', $val); - $this->assertEquals('dateTime.iso8601', $val->getType()); - $this->assertSame($dateString, $val->getValue()); - $this->assertEquals(trim($xml), trim($val->saveXml())); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - * @group ZF-4249 - */ - public function testMarshalDateTimeFromFromDateTime(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $dateString = '20390418T13:14:15'; - $date = new DateTime($dateString); - $dateString = '20390418T13:14:15'; - $xml = "$dateString"; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($date, Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME); - $this->assertXmlRpcType('dateTime', $val); - $this->assertEquals('dateTime.iso8601', $val->getType()); - $this->assertSame($dateString, $val->getValue()); - $this->assertEquals(trim($xml), trim($val->saveXml())); - - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - * @group ZF-4249 - */ - public function testMarshalDateTimeFromDateTimeAndAutodetectingType(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $dateString = '20390418T13:14:15'; - $date = new DateTime($dateString); - $xml = "$dateString"; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($date, Zend_XmlRpc_Value::AUTO_DETECT_TYPE); - $this->assertXmlRpcType('dateTime', $val); - $this->assertEquals('dateTime.iso8601', $val->getType()); - $this->assertSame($dateString, $val->getValue()); - $this->assertEquals(trim($xml), trim($val->saveXml())); - } - - /** - * @group ZF-10776 - */ - public function testGetValueDatetime() - { - $expectedValue = '20100101T00:00:00'; - $zfDate = new Zend_Date('2010-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss'); - $phpDatetime = new DateTime('20100101T00:00:00'); - $phpDateNative = '20100101T00:00:00'; - - $xmlRpcValueDateTime = new Zend_XmlRpc_Value_DateTime($zfDate); - $this->assertEquals($expectedValue, $xmlRpcValueDateTime->getValue()); - - $xmlRpcValueDateTime = new Zend_XmlRpc_Value_DateTime($phpDatetime); - $this->assertEquals($expectedValue, $xmlRpcValueDateTime->getValue()); - - $xmlRpcValueDateTime = new Zend_XmlRpc_Value_DateTime($phpDateNative); - $this->assertEquals($expectedValue, $xmlRpcValueDateTime->getValue()); - } - - // Base64 - - public function testMarshalBase64FromString() - { - $native = 'foo'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64); - - $this->assertXmlRpcType('base64', $val); - $this->assertSame($native, $val->getValue()); - } - - /** - * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators - */ - public function testMarshalBase64FromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator) - { - Zend_XmlRpc_Value::setGenerator($generator); - $native = 'foo'; - $xml = '' .base64_encode($native). ''; - - $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, - Zend_XmlRpc_Value::XML_STRING); - - $this->assertXmlRpcType('base64', $val); - $this->assertEquals('base64', $val->getType()); - $this->assertSame($native, $val->getValue()); - $this->assertEquals($this->wrapXml($xml), $val->saveXml()); - } - - public function testXmlRpcValueBase64GeneratedXmlContainsBase64EncodedText() - { - $native = 'foo'; - $val = Zend_XmlRpc_Value::getXmlRpcValue($native, - Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64); - - $this->assertXmlRpcType('base64', $val); - $xml = $val->saveXml(); - $encoded = base64_encode($native); - $this->assertContains($encoded, $xml); - } - - /** - * @group ZF-3862 - */ - public function testMarshalSerializedObjectAsBase64() - { - $o = new Zend_XmlRpc_SerializableTestClass(); - $o->setProperty('foobar'); - $serialized = serialize($o); - $val = Zend_XmlRpc_Value::getXmlRpcValue($serialized, - Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64); - - $this->assertXmlRpcType('base64', $val); - $o2 = unserialize($val->getValue()); - $this->assertSame('foobar', $o2->getProperty()); - } - - public function testChangingExceptionResetsGeneratorObject() - { - $generator = Zend_XmlRpc_Value::getGenerator(); - Zend_XmlRpc_Value::setEncoding('UTF-8'); - $this->assertNotSame($generator, Zend_XmlRpc_Value::getGenerator()); - $this->assertEquals($generator, Zend_XmlRpc_Value::getGenerator()); - - $generator = Zend_XmlRpc_Value::getGenerator(); - Zend_XmlRpc_Value::setEncoding('ISO-8859-1'); - $this->assertNotSame($generator, Zend_XmlRpc_Value::getGenerator()); - $this->assertNotEquals($generator, Zend_XmlRpc_Value::getGenerator()); - } - - // Exceptions - - public function testFactoryThrowsWhenInvalidTypeSpecified() - { - try { - Zend_XmlRpc_Value::getXmlRpcValue('', 'bad type here'); - $this->fail(); - } catch (Exception $e) { - $this->assertRegexp('/given type is not/i', $e->getMessage()); - } - } - - public function testPassingXmlRpcObjectReturnsTheSameObject() - { - $xmlRpcValue = new Zend_XmlRpc_Value_String('foo'); - $this->assertSame($xmlRpcValue, Zend_XmlRpc_Value::getXmlRpcValue($xmlRpcValue)); - } - - public function testGetXmlRpcTypeByValue() - { - $this->assertSame( - Zend_XmlRpc_Value::XMLRPC_TYPE_NIL, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(new Zend_XmlRpc_Value_Nil) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(new DateTime) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(new Zend_Date) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(array('foo' => 'bar')) - ); - - $object = new stdClass; - $object->foo = 'bar'; - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT, - Zend_XmlRpc_Value::getXmlRpcTypeByValue($object) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(new stdClass) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(array(1, 3, 3, 7)) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(42) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(13.37) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(true) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(false) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_NIL, - Zend_XmlRpc_Value::getXmlRpcTypeByValue(null) - ); - - $this->assertEquals( - Zend_XmlRpc_Value::XMLRPC_TYPE_STRING, - Zend_XmlRpc_Value::getXmlRpcTypeByValue('Zend Framework') - ); - } - - public function testGetXmlRpcTypeByValueThrowsExceptionOnInvalidValue() - { - $this->setExpectedException('Zend_XmlRpc_Value_Exception'); - Zend_XmlRpc_Value::getXmlRpcTypeByValue(fopen(__FILE__, 'r')); - } - - // Custom Assertions and Helper Methods - - public function assertXmlRpcType($type, $object) - { - $type = 'Zend_XmlRpc_Value_' . ucfirst($type); - $this->assertTrue($object instanceof $type); - } - - public function wrapXml($xml) - { - return $xml . "\n"; - } -} - -class Zend_XmlRpc_SerializableTestClass -{ - protected $_property; - public function setProperty($property) - { - $this->_property = $property; - } - - public function getProperty() - { - return $this->_property; - } -} - -// Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly. -if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ValueTest::main") { - Zend_XmlRpc_ValueTest::main(); -} diff --git a/tests/Zend/XmlRpc/_files/ZF12293-payload.txt b/tests/Zend/XmlRpc/_files/ZF12293-payload.txt deleted file mode 100644 index 598a221bd8..0000000000 --- a/tests/Zend/XmlRpc/_files/ZF12293-payload.txt +++ /dev/null @@ -1 +0,0 @@ -Local file inclusion diff --git a/tests/Zend/XmlRpc/_files/ZF12293-request.xml b/tests/Zend/XmlRpc/_files/ZF12293-request.xml deleted file mode 100644 index acb85f16d0..0000000000 --- a/tests/Zend/XmlRpc/_files/ZF12293-request.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - -]> - - &xxe; - diff --git a/tests/Zend/XmlRpc/_files/ZF12293-response.xml b/tests/Zend/XmlRpc/_files/ZF12293-response.xml deleted file mode 100644 index a6ae308d44..0000000000 --- a/tests/Zend/XmlRpc/_files/ZF12293-response.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - -]> - - - &xxe; - - diff --git a/tests/Zend/XmlRpc/_files/ZF1897-response-chunked.txt b/tests/Zend/XmlRpc/_files/ZF1897-response-chunked.txt deleted file mode 100644 index 21e859cfa0..0000000000 --- a/tests/Zend/XmlRpc/_files/ZF1897-response-chunked.txt +++ /dev/null @@ -1,22 +0,0 @@ -HTTP/1.1 200 OK -Date: Thu, 06 Sep 2007 14:58:44 GMT -Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3 Python/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e PHP/5.1.6 -X-Powered-By: PHP/5.1.6 -Connection: close -Transfer-Encoding: chunked -Content-Type: text/html; charset=iso-8859-1 - -92 - - - - - - - FOO - - - - -0 - diff --git a/tests/runalltests.php b/tests/runalltests.php index f226fb2398..979ed90f2f 100755 --- a/tests/runalltests.php +++ b/tests/runalltests.php @@ -58,7 +58,7 @@ $result = 0; // run through phpunit -while(list(, $file)=each($files)) { +foreach ($files as $file) { if ($_SERVER['TRAVIS_PHP_VERSION'] == 'hhvm' && $file == 'Zend/CodeGenerator/AllTests.php') { echo "Skipping $file on HHVM" . PHP_EOL; //gets stuck on the HHVM continue; @@ -68,7 +68,7 @@ system($PHPUNIT . ' --stderr -d memory_limit=-1 -d error_reporting=E_ALL\&E_STRICT -d display_errors=1 ' . escapeshellarg($file), $c_result); echo PHP_EOL; echo "Finished executing {$file}" . PHP_EOL; - + if ($c_result) { echo PHP_EOL . "Result of $file is $c_result" . PHP_EOL . PHP_EOL; $result = $c_result;