فهرست منبع

Added the test for the ZF-3257

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23916 44c647ce-9c0f-0410-b52a-842ac1e357ba
ezimuel 14 سال پیش
والد
کامیت
b83a9061c8
1فایلهای تغییر یافته به همراه40 افزوده شده و 2 حذف شده
  1. 40 2
      tests/Zend/Json/JsonXMLTest.php

+ 40 - 2
tests/Zend/Json/JsonXMLTest.php

@@ -514,7 +514,7 @@ EOT;
      * XML characteristic to be tested: XML containing invalid syntax.
      *
      */
-/*
+
     public function testUsingXML7()
     {
         // Set the XML contents that will be tested here.
@@ -547,7 +547,45 @@ EOT;
 
         $this->assertNotSame($ex, null, "Zend_JSON::fromXml returned an exception.");
     } // End of function testUsingXML7
-*/
+
+    /**
+     *  @group ZF-3257
+     */
+
+    public function testUsingXML8() {
+
+        // Set the XML contents that will be tested here.
+        $xmlStringContents = <<<EOT
+<?xml version="1.0"?>
+<a><b id="foo" />bar</a>
+
+EOT;
+
+        // There are not going to be any XML attributes in this test XML.
+        // Hence, set the flag to ignore XML attributes.
+        $ignoreXmlAttributes = false;
+        $jsonContents = "";
+        $ex = null;
+
+        // Convert XML to JSON now.
+        // fromXml function simply takes a String containing XML contents as input.
+        try {
+            $jsonContents = Zend_Json::fromXml($xmlStringContents, $ignoreXmlAttributes);
+        } catch (Exception $ex) {
+            ;
+        }
+        $this->assertSame($ex, null, "Zend_JSON::fromXml returned an exception.");
+
+        // Convert the JSON string into a PHP array.
+        $phpArray = Zend_Json::decode($jsonContents);
+        // Test if it is not a NULL object.
+        $this->assertNotNull($phpArray, "JSON result for XML input 1 is NULL");
+
+        $this->assertSame("bar", $phpArray['a']['@text'], "The text element of a is not correct");
+        $this->assertSame("foo", $phpArray['a']['b']['@attributes']['id'], "The id attribute of b is not correct");
+
+    }
+
 } // End of class Zend_Json_JsonXMLTest