Fixing Xml::toString() not slugging elements with no children.

Thanks to jeremyharris for the patch.
Fixes #903
This commit is contained in:
mark_story 2011-05-28 16:19:54 -04:00
parent b76901eb43
commit 3f5850913a
2 changed files with 16 additions and 0 deletions

View file

@ -275,6 +275,9 @@ class XmlNode extends Object {
$node->normalize($val, $n, $options);
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
if ($options['slug'] == true) {
$key = Inflector::slug(Inflector::underscore($key));
}
$tmp =& $node->createElement($key);
if (!empty($val) || $val === 0 || $val === '0') {
$tmp->createTextNode($val);

View file

@ -1624,4 +1624,17 @@ class XmlTest extends CakeTestCase {
$this->assertIdentical($result, $expected);
}
function testToStringSlugging() {
$array = array(
'Response' => array(
'OneKey' => 'foo',
'TwoKey' => array('bar', 'baz')
)
);
$xml = new Xml($array, array('format' => 'tags'));
$result = $xml->toString(array('cdata' => false));
$expected = '<response><one_key>foo</one_key><two_key>bar</two_key><two_key>baz</two_key></response>';
$this->assertEqual($result, $expected);
}
}