mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing Xml::toString() not slugging elements with no children.
Thanks to jeremyharris for the patch. Fixes #903
This commit is contained in:
parent
b76901eb43
commit
3f5850913a
2 changed files with 16 additions and 0 deletions
|
@ -275,6 +275,9 @@ class XmlNode extends Object {
|
||||||
|
|
||||||
$node->normalize($val, $n, $options);
|
$node->normalize($val, $n, $options);
|
||||||
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
|
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
|
||||||
|
if ($options['slug'] == true) {
|
||||||
|
$key = Inflector::slug(Inflector::underscore($key));
|
||||||
|
}
|
||||||
$tmp =& $node->createElement($key);
|
$tmp =& $node->createElement($key);
|
||||||
if (!empty($val) || $val === 0 || $val === '0') {
|
if (!empty($val) || $val === 0 || $val === '0') {
|
||||||
$tmp->createTextNode($val);
|
$tmp->createTextNode($val);
|
||||||
|
|
|
@ -1624,4 +1624,17 @@ class XmlTest extends CakeTestCase {
|
||||||
$this->assertIdentical($result, $expected);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue