diff --git a/lib/Cake/Test/Case/View/XmlViewTest.php b/lib/Cake/Test/Case/View/XmlViewTest.php index 44582e79a..f7697bdf0 100644 --- a/lib/Cake/Test/Case/View/XmlViewTest.php +++ b/lib/Cake/Test/Case/View/XmlViewTest.php @@ -64,6 +64,13 @@ class XmlViewTest extends CakeTestCase { $expected = Xml::build(array('response' => array('users' => $data)))->asXML(); $this->assertSame($expected, $output); + + $Controller->set('_rootNode', 'custom_name'); + $View = new XmlView($Controller); + $output = $View->render(false); + + $expected = Xml::build(array('custom_name' => array('users' => $data)))->asXML(); + $this->assertSame($expected, $output); } /** @@ -79,13 +86,20 @@ class XmlViewTest extends CakeTestCase { $Controller->set($data); $Controller->set('_serialize', array('no', 'user')); $View = new XmlView($Controller); + $this->assertSame('application/xml', $Response->type()); $output = $View->render(false); - $expected = array( 'response' => array('no' => $data['no'], 'user' => $data['user']) ); $this->assertSame(Xml::build($expected)->asXML(), $output); - $this->assertSame('application/xml', $Response->type()); + + $Controller->set('_rootNode', 'custom_name'); + $View = new XmlView($Controller); + $output = $View->render(false); + $expected = array( + 'custom_name' => array('no' => $data['no'], 'user' => $data['user']) + ); + $this->assertSame(Xml::build($expected)->asXML(), $output); } /** diff --git a/lib/Cake/View/XmlView.php b/lib/Cake/View/XmlView.php index 7e757b54c..68e8c650e 100644 --- a/lib/Cake/View/XmlView.php +++ b/lib/Cake/View/XmlView.php @@ -99,15 +99,17 @@ class XmlView extends View { * @return string The serialized data */ protected function _serialize($serialize) { + $rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'response'; + if (is_array($serialize)) { - $data = array('response' => array()); + $data = array($rootNode => array()); foreach ($serialize as $key) { - $data['response'][$key] = $this->viewVars[$key]; + $data[$rootNode][$key] = $this->viewVars[$key]; } } else { $data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; if (is_array($data) && Set::numeric(array_keys($data))) { - $data = array('response' => array($serialize => $data)); + $data = array($rootNode => array($serialize => $data)); } } return Xml::fromArray($data)->asXML();