1.20.x common.test | CommonBackdropFormatXmlElementsUnitTestCase::testParseFormatXmlElements() |
Provide a sample data structure and verify the XML results.
File
- modules/
simpletest/ tests/ common.test, line 2873 - Tests for common.inc functionality.
Class
- CommonBackdropFormatXmlElementsUnitTestCase
- Tests the format_xml_elements() API function.
Code
function testParseFormatXmlElements() {
$structure = array(
// Test normal key => value pairs.
'key-value-pairs' => array(
'second-1' => 'foo',
'second-2' => 'bar',
),
// Test normal key => value pairs.
'attributes' => array(
array(
'key' => 'second',
'value' => 'baz',
'attributes' => array(
'attr-1' => 'foo',
'attr-2' => 'bar',
),
),
),
// Test encoded vs. normal.
'encoding' => array(
array(
'key' => 'second',
'value' => '<foo>',
),
array(
'key' => 'second',
'value' => check_plain('<bar>'),
'encoded' => TRUE,
),
),
// Test nesting multiple levels.
'nested' => array(
array(
'key' => 'second',
'value' => array(
'third' => 'foo'
),
),
),
);
$expected_output = <<<EOF
<key-value-pairs>
<second-1>foo</second-1>
<second-2>bar</second-2>
</key-value-pairs>
<attributes>
<second attr-1="foo" attr-2="bar">baz</second>
</attributes>
<encoding>
<second><foo></second>
<second><bar></second>
</encoding>
<nested>
<second>
<third>foo</third>
</second>
</nested>
EOF;
$this->assertIdentical($expected_output, format_xml_elements($structure));
}