Skip to content

Commit

Permalink
Merge branch 'ACP2E-2214' of https://github.com/magento-l3/magento2ce
Browse files Browse the repository at this point in the history
…into PR-L3-08112023
  • Loading branch information
chittima committed Sep 14, 2023
2 parents 11b3612 + 491e34e commit b8b0bf1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/code/Magento/Backend/Block/Widget/Grid/Extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ public function getCsvFile()
$stream = $this->_directory->openFile($file, 'w+');

$stream->lock();
$stream->write(pack('CCC', 0xef, 0xbb, 0xbf));
$stream->writeCsv($this->_getExportHeaders());
$this->_exportIterateCollection('_exportCsvItem', [$stream]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use Laminas\Stdlib\Parameters;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Data\Collection;
use Magento\Framework\Filesystem;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
Expand All @@ -34,7 +36,7 @@ protected function setUp(): void
{
parent::setUp();

$this->_layoutMock = Bootstrap::getObjectManager()->get(
$this->_layoutMock = Bootstrap::getObjectManager()->create(
LayoutInterface::class
);
$context = Bootstrap::getObjectManager()->create(
Expand Down Expand Up @@ -122,4 +124,21 @@ public function testExtendedTemplateMarkup(): void
$html = str_replace(["\n", " "], '', $html);
$this->assertStringEndsWith("</table></div>", $html);
}

public function testGetCsvFileStartsWithBOM(): void
{
$collection = Bootstrap::getObjectManager()->create(Collection::class);
$this->_block->setCollection($collection);
$data = $this->_block->getCsvFile();

$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
self::assertTrue($directory->isFile($data['value']));
self::assertStringStartsWith(
pack('CCC', 0xef, 0xbb, 0xbf),
$directory->readFile($data['value'])
);

$directory->delete($data['value']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ private function getTablerateCsv(): string
$exportCsv = $gridBlock->setWebsiteId($this->websiteId)->setConditionName('package_weight')->getCsvFile();
$exportCsvContent = $varDirectory->openFile($exportCsv['value'], 'r')->readAll();

$bom = pack('CCC', 0xef, 0xbb, 0xbf);
if (substr($exportCsvContent, 0, 3) === $bom) {
$exportCsvContent = substr($exportCsvContent, 3);
}

return $exportCsvContent;
}
}

0 comments on commit b8b0bf1

Please sign in to comment.