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

Merge pull request #231 from volftomas/patch-1

Fixes default type == string
Matthew Weier O'Phinney 12 лет назад
Родитель
Сommit
aa76f02fa2
2 измененных файлов с 18 добавлено и 0 удалено
  1. 3 0
      library/Zend/XmlRpc/Value.php
  2. 15 0
      tests/Zend/XmlRpc/ValueTest.php

+ 3 - 0
library/Zend/XmlRpc/Value.php

@@ -508,6 +508,9 @@ abstract class Zend_XmlRpc_Value
         // If no type was specified, the default is string
         if (!$type) {
             $type = self::XMLRPC_TYPE_STRING;
+            if (preg_match('#^<value>.*</value>$#', $xml->asXML())) {
+                $value = str_replace(array('<value>', '</value>'), '', $xml->asXML());
+            }
         }
     }
 

+ 15 - 0
tests/Zend/XmlRpc/ValueTest.php

@@ -233,6 +233,21 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
         $this->assertSame($native, $val->getValue());
     }
 
+    public function testFactoryAutodetectsStringAndSetsValueInArray()
+    {
+        $val = Zend_XmlRpc_Value::getXmlRpcValue('<value><array><data>'.
+            '<value><i4>8</i4></value>'.
+            '<value>a</value>'.
+            '<value>false</value>'.
+            '</data></array></value>', 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
      */