99use Magento \CatalogImportExport \Model \Import \Uploader ;
1010use Magento \Framework \Exception \LocalizedException ;
1111use Magento \Framework \Filesystem ;
12+ use Magento \Framework \Filesystem \Directory \Write ;
1213use Magento \Framework \Filesystem \Driver \Http ;
1314use Magento \Framework \Filesystem \Driver \Https ;
1415use Magento \Framework \Filesystem \DriverPool ;
@@ -58,7 +59,7 @@ class UploaderTest extends TestCase
5859 protected $ readFactory ;
5960
6061 /**
61- * @var \Magento\Framework\Filesystem\Directory\Writer |MockObject
62+ * @var WriteInterface |MockObject
6263 */
6364 protected $ directoryMock ;
6465
@@ -96,7 +97,7 @@ protected function setUp(): void
9697 ->setMethods (['create ' ])
9798 ->getMock ();
9899
99- $ this ->directoryMock = $ this ->getMockBuilder (\ Magento \ Framework \ Filesystem \ Directory \Writer ::class)
100+ $ this ->directoryMock = $ this ->getMockBuilder (Write ::class)
100101 ->setMethods (['writeFile ' , 'getRelativePath ' , 'isWritable ' , 'getAbsolutePath ' ])
101102 ->disableOriginalConstructor ()
102103 ->getMock ();
@@ -186,14 +187,21 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName, $che
186187 ->willReturn ($ destDir . '/ ' . $ expectedFileName );
187188 $ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )
188189 ->willReturnSelf ();
190+
191+ $ returnFile = $ destDir . DIRECTORY_SEPARATOR . $ expectedFileName ;
192+
189193 $ this ->uploader ->expects ($ this ->once ())->method ('save ' )
190194 ->with ($ destDir . '/ ' . $ expectedFileName )
191- ->willReturn (['name ' => $ expectedFileName , 'path ' => 'absPath ' ]);
195+ ->willReturn ([
196+ 'name ' => $ expectedFileName ,
197+ 'path ' => 'absPath ' ,
198+ 'file ' => $ returnFile
199+ ]);
192200
193201 $ this ->uploader ->setDestDir ($ destDir );
194202 $ result = $ this ->uploader ->move ($ fileUrl );
195203
196- $ this ->assertEquals (['name ' => $ expectedFileName ], $ result );
204+ $ this ->assertEquals (['name ' => $ expectedFileName, ' file ' => $ returnFile ], $ result );
197205 $ this ->assertArrayNotHasKey ('path ' , $ result );
198206 }
199207
@@ -209,11 +217,50 @@ public function testMoveFileName()
209217 //Check invoking of getTmpDir(), _setUploadFile(), save() methods.
210218 $ this ->uploader ->expects ($ this ->once ())->method ('getTmpDir ' )->willReturn ('' );
211219 $ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )->willReturnSelf ();
220+
221+ $ returnFile = $ destDir . DIRECTORY_SEPARATOR . $ fileName ;
222+
212223 $ this ->uploader ->expects ($ this ->once ())->method ('save ' )->with ($ destDir . '/ ' . $ fileName )
213- ->willReturn (['name ' => $ fileName ]);
224+ ->willReturn (['name ' => $ fileName , 'file ' => $ returnFile ]);
225+
226+ $ this ->uploader ->setDestDir ($ destDir );
227+ $ this ->assertEquals (['name ' => $ fileName , 'file ' => $ returnFile ], $ this ->uploader ->move ($ fileName ));
228+ }
229+
230+ public function testFilenameLength ()
231+ {
232+ $ destDir = 'var/tmp/ ' . str_repeat ('testFilenameLength ' , 13 ); // 242 characters
233+
234+ $ fileName = \uniqid (); // 13 characters
235+
236+ $ this ->directoryMock ->expects ($ this ->once ())
237+ ->method ('isWritable ' )
238+ ->with ($ destDir )
239+ ->willReturn (true );
240+
241+ $ this ->directoryMock ->expects ($ this ->once ())
242+ ->method ('getRelativePath ' )
243+ ->with ($ fileName )
244+ ->willReturn (null );
245+
246+ $ this ->directoryMock ->expects ($ this ->once ())
247+ ->method ('getAbsolutePath ' )
248+ ->with ($ destDir )
249+ ->willReturn ($ destDir );
250+
251+ $ this ->uploader ->expects ($ this ->once ())
252+ ->method ('save ' )
253+ ->with ($ destDir )
254+ ->willReturn ([
255+ 'name ' => $ fileName ,
256+ 'file ' => $ destDir . DIRECTORY_SEPARATOR . $ fileName // 256 characters
257+ ]);
214258
215259 $ this ->uploader ->setDestDir ($ destDir );
216- $ this ->assertEquals (['name ' => $ fileName ], $ this ->uploader ->move ($ fileName ));
260+
261+ $ this ->expectException (\LengthException::class);
262+
263+ $ this ->uploader ->move ($ fileName );
217264 }
218265
219266 /**
0 commit comments