You are here

public function XmlHelperTestCase::assertFormatXml in Helper 7

1 call to XmlHelperTestCase::assertFormatXml()
XmlHelperTestCase::assertParseElements in tests/XmlHelperTestCase.test

File

tests/XmlHelperTestCase.test, line 22

Class

XmlHelperTestCase

Code

public function assertFormatXml($array, $expected) {
  $xml = format_xml_elements($array);

  // Apply some cleanup formatting to the XML to assure it matches correctly.
  $xml = preg_replace(array(
    '~<([^/> ]+)\\s+/>~',
    '~\\s+<~',
    '~>\\s+~',
    '~><~',
  ), array(
    '<$1></$1>',
    '<',
    ">",
    ">\n<",
  ), $xml);
  $expected = preg_replace(array(
    '~<([^/> ]+)\\s+/>~',
    '~\\s+<~',
    '~>\\s+~',
    '~><~',
  ), array(
    '<$1></$1>',
    '<',
    ">",
    ">\n<",
  ), $expected);
  $this
    ->assertIdentical($xml, $expected, format_string('Calling format_xml_elements(@input)<br/>Returned: <pre>@output</pre><br/>Expected: <pre>@expected</pre>', array(
    '@input' => print_r($array, TRUE),
    '@output' => $xml,
    '@expected' => $expected,
  )));
}