77
88use Laminas \Stdlib \Parameters ;
99use Magento \Backend \Block \Template \Context ;
10+ use Magento \Framework \App \Filesystem \DirectoryList ;
1011use Magento \Framework \Data \Collection ;
12+ use Magento \Framework \Filesystem ;
1113use Magento \Framework \View \LayoutInterface ;
1214use Magento \TestFramework \Helper \Bootstrap ;
1315use PHPUnit \Framework \TestCase ;
@@ -34,7 +36,7 @@ protected function setUp(): void
3436 {
3537 parent ::setUp ();
3638
37- $ this ->_layoutMock = Bootstrap::getObjectManager ()->get (
39+ $ this ->_layoutMock = Bootstrap::getObjectManager ()->create (
3840 LayoutInterface::class
3941 );
4042 $ context = Bootstrap::getObjectManager ()->create (
@@ -122,4 +124,21 @@ public function testExtendedTemplateMarkup(): void
122124 $ html = str_replace (["\n" , " " ], '' , $ html );
123125 $ this ->assertStringEndsWith ("</table></div> " , $ html );
124126 }
127+
128+ public function testGetCsvFileStartsWithBOM (): void
129+ {
130+ $ collection = Bootstrap::getObjectManager ()->create (Collection::class);
131+ $ this ->_block ->setCollection ($ collection );
132+ $ data = $ this ->_block ->getCsvFile ();
133+
134+ $ filesystem = Bootstrap::getObjectManager ()->get (Filesystem::class);
135+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_DIR );
136+ self ::assertTrue ($ directory ->isFile ($ data ['value ' ]));
137+ self ::assertStringStartsWith (
138+ pack ('CCC ' , 0xef , 0xbb , 0xbf ),
139+ $ directory ->readFile ($ data ['value ' ])
140+ );
141+
142+ $ directory ->delete ($ data ['value ' ]);
143+ }
125144}
0 commit comments