Skip to content
Permalink
Browse files

Changing the default format of fromArray from attributes to tags.

  • Loading branch information...
jrbasso committed Sep 7, 2010
1 parent 87604f9 commit 5f902d42e0dfe3b231d48f00e1ed142bb7531914
Showing with 7 additions and 7 deletions.
  1. +1 −1 cake/libs/xml.php
  2. +6 −6 cake/tests/cases/libs/xml.test.php
@@ -106,7 +106,7 @@ public static function build($input) {
* @param string $format If create childs ('tags') or attributes ('attribute').
* @return object SimpleXMLElement
*/
public static function fromArray($input, $format = 'attribute') {
public static function fromArray($input, $format = 'tags') {
if (!is_array($input) || count($input) !== 1) {
throw new Exception(__('Invalid input.'));
}
@@ -115,14 +115,14 @@ public function testFromArray() {
)
)
);
$obj = Xml::fromArray($xml);
$obj = Xml::fromArray($xml, 'attributes');
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual(count($obj), 2);
$xmlText = '<' . '?xml version="1.0"?><tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
$obj = Xml::fromArray($xml, 'tags');
$obj = Xml::fromArray($xml);
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual(count($obj), 2);
@@ -202,7 +202,7 @@ public function testFromArray() {
)
)
);
$obj = Xml::fromArray($xml);
$obj = Xml::fromArray($xml, 'attributes');
$xmlText = '<' . '?xml version="1.0"?><tags><tag id="1">defect</tag></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
}
@@ -318,8 +318,8 @@ public function testToArray() {
)
)
);
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'tags')), $array);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'attributes')), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $array);
$array = array(
'tags' => array(
@@ -353,7 +353,7 @@ public function testToArray() {
)
)
);
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'attributes')), $expected);
$xml = '<root>';
$xml .= '<tag id="1">defect</tag>';

0 comments on commit 5f902d4

Please sign in to comment.
You can’t perform that action at this time.