Просмотр исходного кода

Adding support for <ex:nil/>

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17934 44c647ce-9c0f-0410-b52a-842ac1e357ba
lars 16 лет назад
Родитель
Сommit
cb3ddd138b
2 измененных файлов с 38 добавлено и 25 удалено
  1. 19 13
      library/Zend/XmlRpc/Value.php
  2. 19 12
      tests/Zend/XmlRpc/ValueTest.php

+ 19 - 13
library/Zend/XmlRpc/Value.php

@@ -73,18 +73,19 @@ abstract class Zend_XmlRpc_Value
     /**
      * All the XML-RPC native types
      */
-    const XMLRPC_TYPE_I4       = 'i4';
-    const XMLRPC_TYPE_INTEGER  = 'int';
-    const XMLRPC_TYPE_I8       = 'i8';
-    const XMLRPC_TYPE_APACHEI8 = 'ex:i8';
-    const XMLRPC_TYPE_DOUBLE   = 'double';
-    const XMLRPC_TYPE_BOOLEAN  = 'boolean';
-    const XMLRPC_TYPE_STRING   = 'string';
-    const XMLRPC_TYPE_DATETIME = 'dateTime.iso8601';
-    const XMLRPC_TYPE_BASE64   = 'base64';
-    const XMLRPC_TYPE_ARRAY    = 'array';
-    const XMLRPC_TYPE_STRUCT   = 'struct';
-    const XMLRPC_TYPE_NIL      = 'nil';
+    const XMLRPC_TYPE_I4        = 'i4';
+    const XMLRPC_TYPE_INTEGER   = 'int';
+    const XMLRPC_TYPE_I8        = 'i8';
+    const XMLRPC_TYPE_APACHEI8  = 'ex:i8';
+    const XMLRPC_TYPE_DOUBLE    = 'double';
+    const XMLRPC_TYPE_BOOLEAN   = 'boolean';
+    const XMLRPC_TYPE_STRING    = 'string';
+    const XMLRPC_TYPE_DATETIME  = 'dateTime.iso8601';
+    const XMLRPC_TYPE_BASE64    = 'base64';
+    const XMLRPC_TYPE_ARRAY     = 'array';
+    const XMLRPC_TYPE_STRUCT    = 'struct';
+    const XMLRPC_TYPE_NIL       = 'nil';
+    const XMLRPC_TYPE_APACHENIL = 'ex:nil';
 
 
     /**
@@ -184,6 +185,8 @@ abstract class Zend_XmlRpc_Value
                 return new Zend_XmlRpc_Value_Base64($value);
 
             case self::XMLRPC_TYPE_NIL:
+                // fall through to the next case
+            case self::XMLRPC_TYPE_APACHENIL:
                 return new Zend_XmlRpc_Value_Nil();
 
             case self::XMLRPC_TYPE_DATETIME:
@@ -340,7 +343,10 @@ abstract class Zend_XmlRpc_Value
                 require_once 'Zend/XmlRpc/Value/Base64.php';
                 $xmlrpcValue = new Zend_XmlRpc_Value_Base64($value, true);
                 break;
-            case self::XMLRPC_TYPE_NIL:    // The value should always be NULL
+            case self::XMLRPC_TYPE_NIL:
+                // Fall through to the next case
+            case self::XMLRPC_TYPE_APACHENIL:
+                // The value should always be NULL
                 $xmlrpcValue = new Zend_XmlRpc_Value_Nil();
                 break;
             case self::XMLRPC_TYPE_ARRAY:

+ 19 - 12
tests/Zend/XmlRpc/ValueTest.php

@@ -305,23 +305,30 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
     public function testMarshalNilFromNative()
     {
         $native = NULL;
-        $val = Zend_XmlRpc_Value::getXmlRpcValue($native,
-                                    Zend_XmlRpc_Value::XMLRPC_TYPE_NIL);
+        $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', $val);
-        $this->assertSame($native, $val->getValue());
+            $this->assertXmlRpcType('nil', $value);
+            $this->assertSame($native, $value->getValue());
+        }
     }
 
     public function testMarshalNilFromXmlRpc()
     {
-        $xml = '<value><nil/></value>';
-        $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->assertType('DomElement', $val->getAsDOM());
-        $this->assertEquals($this->wrapXml($xml), $val->saveXML());
+        $xmls = array('<value><nil/></value>',
+                     '<value><ex:nil xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions"/></value>');
+
+        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->assertType('DomElement', $val->getAsDOM());
+            $this->assertEquals($this->wrapXml($xml), $val->saveXML());
+        }
     }
 
     // Array