Skip to content

Commit

Permalink
Fixed testcase for empty enclosure to be Cake 3.x compliant.
Browse files Browse the repository at this point in the history
Changed strict check for enclosure from null to '' null delimiter is changed to '"'.
  • Loading branch information
martonmiklos committed Aug 30, 2015
1 parent 591a70f commit eda31f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/View/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected function _generateRow($row = null)
$newline = $this->viewVars['_newline'];

$row = str_replace(["\r\n", "\n", "\r"], $newline, $row);
if ($enclosure === null) {
if ($enclosure === '') {
// fputcsv does not supports empty enclosure
if (fputs($fp, implode($delimiter, $row) . "\n") === false) {
return false;
Expand Down
19 changes: 11 additions & 8 deletions tests/TestCase/View/CsvViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public function testPassingQueryAsData()
*/
public function testRenderEnclosure()
{
$Request = new CakeRequest();
$Response = new CakeResponse();
$Request = new Request();
$Response = new Response();
$Controller = new Controller($Request, $Response);
$data = array(array('user', 'fake apple', 'list', 'a b c', 'item2'));
$testData = array(
Expand All @@ -277,12 +277,15 @@ public function testRenderEnclosure()
'' => "user,fake apple,list,a b c,item2" . PHP_EOL,
);

foreach ($testData as $enclosure => $output) {
$Controller->set(array('data' => $data, '_serialize' => 'data', '_enclosure' => $enclosure));
$View = new CsvView($Controller);
$renderOutput = $View->render(false);
$this->assertSame($renderOutput, $output);
$this->assertSame('text/csv', $Response->type());
foreach ($testData as $enclosure => $expected) {
$_serialize = 'data';
$this->view->set('data', $data);
$this->view->set(['_serialize' => 'data']);
$this->view->viewVars['_enclosure'] = $enclosure;
$output = $this->view->render(false);

$this->assertSame($expected, $output);
$this->assertSame('text/csv', $this->response->type());
}
}
}

0 comments on commit eda31f4

Please sign in to comment.