Skip to content

Commit

Permalink
MNT Fix Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 12, 2024
1 parent 4cdd203 commit de12af1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/Forms/GridField/GridFieldExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Forms\GridField;

use League\Csv\Bom;
use League\Csv\Writer;
use LogicException;
use SilverStripe\Control\HTTPRequest;
Expand Down Expand Up @@ -180,8 +181,8 @@ public function generateExportFileData($gridField)
$csvWriter = Writer::createFromFileObject(new \SplTempFileObject());
$csvWriter->setDelimiter($this->getCsvSeparator());
$csvWriter->setEnclosure($this->getCsvEnclosure());
$csvWriter->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries
$csvWriter->setOutputBOM(Writer::BOM_UTF8);
$csvWriter->setEndOfLine("\r\n"); //use windows line endings for compatibility with some csv libraries
$csvWriter->setOutputBOM(Bom::Utf8);

if (!Config::inst()->get(get_class($this), 'xls_export_disabled')) {
$csvWriter->addFormatter(function (array $row) {
Expand Down Expand Up @@ -269,11 +270,7 @@ public function generateExportFileData($gridField)
}
}

if (method_exists($csvWriter, 'getContent')) {
return $csvWriter->getContent();
}

return (string)$csvWriter;
return $csvWriter->toString();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Forms/GridField/GridFieldExportButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Forms\Tests\GridField;

use League\Csv\Bom;
use League\Csv\Reader;
use LogicException;
use ReflectionMethod;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function testCanView()

$this->assertEquals(
"$bom\"My Name\"\r\n",
(string) $csvReader
(string) $csvReader->toString()
);
}

Expand Down Expand Up @@ -224,7 +225,7 @@ protected function createReader($string)

// Explicitly set the output BOM in league/csv 9
if (method_exists($reader, 'getContent')) {
$reader->setOutputBOM(Reader::BOM_UTF8);
$reader->setOutputBOM(Bom::Utf8);
}

return $reader;
Expand Down

0 comments on commit de12af1

Please sign in to comment.