You are here

protected function XMLExportViewsDataExportExporterTests::testTransform in Views data export 7.4

Test the space character swap-out options.

File

tests/exporter_tests/xml.test, line 98

Class

XMLExportViewsDataExportExporterTests

Code

protected function testTransform() {

  // Set up a dataset with spaces in the attribute names.
  $spaced_dataset = array(
    array(
      'name of artist' => 'John Lennon',
      'their age' => 25,
      'their job' => 'they are a Singer',
      'created' => gmmktime(0, 0, 0, 1, 1, 2000),
    ),
  );

  // Test each of the different swap-out options.
  // Dash.
  $result = $this
    ->executeFullWrite($this
    ->getExporter(array(
    'transform' => true,
    'transform_type' => 'dash',
  )), $spaced_dataset, 0, array(
    'name of artist' => 'name of artist',
    'their age' => 'their age',
    'their job' => 'their job',
    'created' => 'created',
  ));
  $expected = '  <item>
    <name-of-artist>John Lennon</name-of-artist>
    <their-age>25</their-age>
    <their-job>they are a Singer</their-job>
    <created>946684800</created>
  </item>
';
  $this
    ->logVerboseResult($result, 'Actual result');
  $this
    ->logVerboseResult($expected, 'Expected result');
  $this
    ->assertEqual($result, $expected, 'The content is as expected.');

  // Underline.
  $result = $this
    ->executeFullWrite($this
    ->getExporter(array(
    'transform' => true,
    'transform_type' => 'underline',
  )), $spaced_dataset, 0, array(
    'name of artist' => 'name of artist',
    'their age' => 'their age',
    'their job' => 'their job',
    'created' => 'created',
  ));
  $expected = '  <item>
    <name_of_artist>John Lennon</name_of_artist>
    <their_age>25</their_age>
    <their_job>they are a Singer</their_job>
    <created>946684800</created>
  </item>
';
  $this
    ->logVerboseResult($result, 'Actual result');
  $this
    ->logVerboseResult($expected, 'Expected result');
  $this
    ->assertEqual($result, $expected, 'The content is as expected.');

  // camelCase.
  $result = $this
    ->executeFullWrite($this
    ->getExporter(array(
    'transform' => true,
    'transform_type' => 'camelCase',
  )), $spaced_dataset, 0, array(
    'name of artist' => 'name of artist',
    'their age' => 'their age',
    'their job' => 'their job',
    'created' => 'created',
  ));
  $expected = '  <item>
    <nameOfArtist>John Lennon</nameOfArtist>
    <theirAge>25</theirAge>
    <theirJob>they are a Singer</theirJob>
    <created>946684800</created>
  </item>
';
  $this
    ->logVerboseResult($result, 'Actual result');
  $this
    ->logVerboseResult($expected, 'Expected result');
  $this
    ->assertEqual($result, $expected, 'The content is as expected.');

  // PascalCase.
  $result = $this
    ->executeFullWrite($this
    ->getExporter(array(
    'transform' => true,
    'transform_type' => 'PascalCase',
  )), $spaced_dataset, 0, array(
    'name of artist' => 'name of artist',
    'their age' => 'their age',
    'their job' => 'their job',
    'created' => 'created',
  ));
  $expected = '  <item>
    <NameOfArtist>John Lennon</NameOfArtist>
    <TheirAge>25</TheirAge>
    <TheirJob>they are a Singer</TheirJob>
    <Created>946684800</Created>
  </item>
';
  $this
    ->logVerboseResult($result, 'Actual result');
  $this
    ->logVerboseResult($expected, 'Expected result');
  $this
    ->assertEqual($result, $expected, 'The content is as expected.');
}