You are here

protected function CSVExportViewsDataExportTests::testTrimFields in Views data export 7.4

Same name and namespace in other branches
  1. 7.3 tests/csv_export.test \CSVExportViewsDataExportTests::testTrimFields()

Test to ensure that HTML tags are kept in CSV files when requested.

File

tests/csv_export.test, line 113

Class

CSVExportViewsDataExportTests

Code

protected function testTrimFields() {
  $view = $this
    ->getBasicExportView();
  $display = $view->display['default']->handler;
  $display
    ->override_option('fields', array(
    'id' => array(
      'id' => 'id',
      'table' => 'views_test',
      'field' => 'id',
      'relationship' => 'none',
      'label' => 'ID',
    ),
    'name' => array(
      'id' => 'name',
      'table' => 'views_test',
      'field' => 'name',
      'relationship' => 'none',
      // Alter this field to include HTML.
      'alter' => array(
        'alter_text' => TRUE,
        'text' => ' [name]  ',
      ),
    ),
    'age' => array(
      'id' => 'age',
      'table' => 'views_test',
      'field' => 'age',
      'relationship' => 'none',
    ),
  ));
  $style_options = array(
    'exporter_options' => array(
      'trim' => FALSE,
    ),
  );
  $expected = '"ID","Name","Age"
"1"," John  ","25"
"2"," George  ","27"
"3"," Ringo  ","28"
"4"," Paul  ","26"
"5"," Meredith  ","30"';
  $message = 'Trim reverse test in ' . $this->vde_export_type . ' export matched expected output.';
  $this
    ->executeAndCompareGivenView($view, $expected, $message, $style_options);

  // And now make sure that trimming works as expected.
  $style_options = array(
    'exporter_options' => array(
      'trim' => TRUE,
    ),
  );
  $expected = '"ID","Name","Age"
"1","John","25"
"2","George","27"
"3","Ringo","28"
"4","Paul","26"
"5","Meredith","30"';
  $message = 'Trim test in ' . $this->vde_export_type . ' export matched expected output.';
  $this
    ->executeAndCompareGivenView($view, $expected, $message, $style_options);
}