You are here

public function CSVTest::testCSV in Forena Reports 8

Table function

File

tests/src/Unit/Document/CSVTest.php, line 50

Class

CSVTest
Test CSV @group Forena @require module forena @coversDefaultClass \Drupal\forena\FrxPlugin\Document\CSV

Namespace

Drupal\Tests\forena\Unit\Document

Code

public function testCSV() {
  $doc = DocManager::instance()
    ->setDocument('csv');
  $doc
    ->header();
  $doc
    ->write($this->table);
  $doc
    ->footer();
  $report = $doc
    ->flush();

  // Check the headers
  $this
    ->assertContains("col_1,col_2", $report, 'Column Headers present');
  $this
    ->assertContains("1,2", $report, "Simple numbers present");
  $this
    ->assertContains('"text, with, commas",text without commas', $report);

  // Check headers
  $headers = $doc->headers;
  $this
    ->assertArrayHasKey('Content-Type', $headers);
  $this
    ->assertContains('application/csv', $headers['Content-Type']);
}