Browse Source

ZF-11385: Tests to ensure that Zend_Json::fromXml implements recursion depth limit properly

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24406 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 14 years ago
parent
commit
3a24d653f8
1 changed files with 48 additions and 0 deletions
  1. 48 0
      tests/Zend/Json/JsonXMLTest.php

+ 48 - 0
tests/Zend/Json/JsonXMLTest.php

@@ -586,6 +586,54 @@ EOT;
 
     }
 
+    /**
+     * @group ZF-11385
+     * @expectedException Zend_Json_Exception
+     * @dataProvider providerNestingDepthIsHandledProperly
+     */
+    public function testNestingDepthIsHandledProperlyWhenNestingDepthExceedsMaximum($xmlStringContents)
+    {        
+        Zend_Json::$maxRecursionDepthAllowed = 1;
+        Zend_Json::fromXml($xmlStringContents, true);
+    }
+    
+    /**
+     * @group ZF-11385
+     * @dataProvider providerNestingDepthIsHandledProperly
+     */
+    public function testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum($xmlStringContents)
+    {   
+        try {
+            Zend_Json::$maxRecursionDepthAllowed = 25;
+            $jsonString = Zend_Json::fromXml($xmlStringContents, true);
+            $jsonArray = Zend_Json::decode($jsonString);
+            $this->assertNotNull($jsonArray, "JSON decode result is NULL");
+            $this->assertSame('A', $jsonArray['response']['message_type']['defaults']['close_rules']['after_responses']);
+        } catch ( Zend_Json_Exception $ex ) {
+            $this->fail('Zend_Json::fromXml does not implement recursion check properly');
+        }
+    }
+    
+    /**
+     * XML document provider for ZF-11385 tests
+     * @return array
+     */
+    public static function providerNestingDepthIsHandledProperly()
+    {
+        $xmlStringContents = <<<EOT
+<response>
+	<message_type>
+		<defaults>
+			<close_rules>
+				<after_responses>A</after_responses>
+			</close_rules>
+		</defaults>
+	</message_type>
+</response>
+EOT;
+        return array(array($xmlStringContents));
+    }
+    
 } // End of class Zend_Json_JsonXMLTest