Forráskód Böngészése

[ZF-8898] Handling xmlrpc i8 Tags

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23363 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan 15 éve
szülő
commit
57785db6f4

+ 7 - 2
library/Zend/XmlRpc/Value.php

@@ -270,9 +270,14 @@ abstract class Zend_XmlRpc_Value
                     return $value;
                 }
 
+                // @see http://framework.zend.com/issues/browse/ZF-8623
                 if ($value instanceof Zend_Crypt_Math_BigInteger) {
-                    require_once 'Zend/XmlRpc/Value/BigInteger.php';
-                    return new Zend_XmlRpc_Value_BigInteger($value);
+                    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.'
+                    );
                 }
 
                 if ($value instanceof Zend_Date or $value instanceof DateTime) {

+ 9 - 16
library/Zend/XmlRpc/Value/BigInteger.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Zend Framework
  *
@@ -20,13 +21,11 @@
  * @version    $Id$
  */
 
-
 /**
  * Zend_XmlRpc_Value_Integer
  */
 require_once 'Zend/XmlRpc/Value/Integer.php';
 
-
 /**
  * @category   Zend
  * @package    Zend_XmlRpc
@@ -37,29 +36,23 @@ require_once 'Zend/XmlRpc/Value/Integer.php';
 class Zend_XmlRpc_Value_BigInteger extends Zend_XmlRpc_Value_Integer
 {
     /**
-     * @var Zend_Crypt_Math_BigInteger
-     */
-    protected $_integer;
-
-    /**
      * @param mixed $value
      */
     public function __construct($value)
     {
         require_once 'Zend/Crypt/Math/BigInteger.php';
-        $this->_integer = new Zend_Crypt_Math_BigInteger();
-        $this->_value = $this->_integer->init($this->_value);
-
+        $integer = new Zend_Crypt_Math_BigInteger;
+        $this->_value = $integer->init($value);
         $this->_type = self::XMLRPC_TYPE_I8;
     }
-
+    
     /**
-     * Return bigint value object
-     *
-     * @return Zend_Crypt_Math_BigInteger
+     * Return bigint value
+     * 
+     * @return string
      */
     public function getValue()
     {
-        return $this->_integer;
+        return $this->_value;
     }
-}
+}

+ 97 - 32
tests/Zend/XmlRpc/ValueTest.php

@@ -149,50 +149,115 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
     }
 
     // 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(
+            '<value><i8>' . $bigIntegerValue . '</i8></value>',
+            $bigInteger->saveXml()
+        );
+    }
+    
     /**
      * @group ZF-6445
      * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
      */
-    public function testMarshalBigIntegerFromFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
+    public function testMarschalBigIntegerFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
     {
         Zend_XmlRpc_Value::setGenerator($generator);
-        $bigInt = (string)(PHP_INT_MAX + 1);
-        $native = new Zend_Crypt_Math_BigInteger();
-        $native->init($bigInt);
-
-        $xmlStrings = array("<value><i8>$bigInt</i8></value>",
-                            "<value><ex:i8 xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">$bigInt</ex:i8></value>");
-
-        foreach ($xmlStrings as $xml) {
-            $value = Zend_XmlRpc_Value::getXmlRpcValue($xml, Zend_XmlRpc_Value::XML_STRING);
-            $this->assertEquals($native, $value->getValue());
-            $this->assertEquals('i8', $value->getType());
-            $this->assertEquals($this->wrapXml($xml), $value->saveXml());
-        }
-    }
-
+        
+        $bigIntegerValue = (string)(PHP_INT_MAX + 42);
+        $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
+        $bigIntegerXml = '<value><i8>' . $bigIntegerValue . '</i8></value>';
+        
+        $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 = '<value><ex:i8 xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">' . $bigIntegerValue . '</ex:i8></value>';
+        
+        $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()
     {
-        $native = (string)(PHP_INT_MAX + 1);
-        $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8,
-                       Zend_XmlRpc_Value::XMLRPC_TYPE_I8);
-
-        $bigInt = new Zend_Crypt_Math_BigInteger();
-        $bigInt->init($native);
-
-        foreach ($types as $type) {
-            $value = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
-            $this->assertSame('i8', $value->getType());
-            $this->assertEquals($bigInt, $value->getValue());
+        $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');
+            }
         }
-
-        $value = Zend_XmlRpc_Value::getXmlRpcValue($bigInt);
-        $this->assertSame('i8', $value->getType());
-        $this->assertEquals($bigInt, $value->getValue());
     }
 
     // Double