CSVTest.php in Forena Reports 8
File
tests/src/Unit/Document/CSVTest.php
View source
<?php
namespace Drupal\Tests\forena\Unit\Document;
use Drupal\forena\DocManager;
use Drupal\Tests\forena\Unit\FrxTestCase;
class CSVTest extends FrxTestCase {
private $table = '
<div>
<table>
<thead>
<tr>
<th>col_1</th>
<th>col_2</th>
</tr>
</thead>
<tbody>
<tr >
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>text, with, commas</td>
<td>text without commas</td>
</tr>
</tbody>
</table>
</div>';
public function testCSV() {
$doc = DocManager::instance()
->setDocument('csv');
$doc
->header();
$doc
->write($this->table);
$doc
->footer();
$report = $doc
->flush();
$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);
$headers = $doc->headers;
$this
->assertArrayHasKey('Content-Type', $headers);
$this
->assertContains('application/csv', $headers['Content-Type']);
}
}