You are here

protected function XMLExportViewsDataExportExporterTests::testCData in Views data export 7.4

Test that fields can be correctly escaped in CDATA tags.

File

tests/exporter_tests/xml.test, line 250

Class

XMLExportViewsDataExportExporterTests

Code

protected function testCData() {

  // Set up a dataset with illegal characters, which requires CDATA tags.
  $CDATA_dataset = array(
    array(
      'illegal_content' => 'illegal XML characters < & >',
      'name' => 'John',
      'age' => 25,
      'job' => 'singer',
      'created' => gmmktime(0, 0, 0, 1, 1, 2000),
    ),
  );

  // Write the dataset out, specifying the illegal_content attribute as
  // requiring CDATA tags.
  $result = $this
    ->executeFullWrite($this
    ->getExporter(array(
    'cdata_wrapper' => array(
      'illegal_content',
    ),
  )), $CDATA_dataset, 0, array(
    'illegal_content' => 'illegal_content',
    'name' => 'name',
    'age' => 'age',
    'job' => 'job',
    'created' => 'created',
  ));

  // Expect the illegal_content attribute value to be in CDATA tags.
  $expected = '  <item>
    <illegal_content><![CDATA[illegal XML characters < & >]]></illegal_content>
    <name>John</name>
    <age>25</age>
    <job>singer</job>
    <created>946684800</created>
  </item>
';
  $this
    ->logVerboseResult($result, 'Actual result');
  $this
    ->logVerboseResult($expected, 'Expected result');
  $this
    ->assertEqual($result, $expected, 'The content is as expected.');
}