9
9
use Magento \CatalogImportExport \Model \Import \Uploader ;
10
10
use Magento \Framework \Exception \LocalizedException ;
11
11
use Magento \Framework \Filesystem ;
12
+ use Magento \Framework \Filesystem \Directory \Write ;
12
13
use Magento \Framework \Filesystem \Driver \Http ;
13
14
use Magento \Framework \Filesystem \Driver \Https ;
14
15
use Magento \Framework \Filesystem \DriverPool ;
@@ -58,7 +59,7 @@ class UploaderTest extends TestCase
58
59
protected $ readFactory ;
59
60
60
61
/**
61
- * @var \Magento\Framework\Filesystem\Directory\Writer |MockObject
62
+ * @var WriteInterface |MockObject
62
63
*/
63
64
protected $ directoryMock ;
64
65
@@ -96,7 +97,7 @@ protected function setUp(): void
96
97
->setMethods (['create ' ])
97
98
->getMock ();
98
99
99
- $ this ->directoryMock = $ this ->getMockBuilder (\ Magento \ Framework \ Filesystem \ Directory \Writer ::class)
100
+ $ this ->directoryMock = $ this ->getMockBuilder (Write ::class)
100
101
->setMethods (['writeFile ' , 'getRelativePath ' , 'isWritable ' , 'getAbsolutePath ' ])
101
102
->disableOriginalConstructor ()
102
103
->getMock ();
@@ -186,14 +187,21 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName, $che
186
187
->willReturn ($ destDir . '/ ' . $ expectedFileName );
187
188
$ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )
188
189
->willReturnSelf ();
190
+
191
+ $ returnFile = $ destDir . DIRECTORY_SEPARATOR . $ expectedFileName ;
192
+
189
193
$ this ->uploader ->expects ($ this ->once ())->method ('save ' )
190
194
->with ($ destDir . '/ ' . $ expectedFileName )
191
- ->willReturn (['name ' => $ expectedFileName , 'path ' => 'absPath ' ]);
195
+ ->willReturn ([
196
+ 'name ' => $ expectedFileName ,
197
+ 'path ' => 'absPath ' ,
198
+ 'file ' => $ returnFile
199
+ ]);
192
200
193
201
$ this ->uploader ->setDestDir ($ destDir );
194
202
$ result = $ this ->uploader ->move ($ fileUrl );
195
203
196
- $ this ->assertEquals (['name ' => $ expectedFileName ], $ result );
204
+ $ this ->assertEquals (['name ' => $ expectedFileName, ' file ' => $ returnFile ], $ result );
197
205
$ this ->assertArrayNotHasKey ('path ' , $ result );
198
206
}
199
207
@@ -209,11 +217,50 @@ public function testMoveFileName()
209
217
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
210
218
$ this ->uploader ->expects ($ this ->once ())->method ('getTmpDir ' )->willReturn ('' );
211
219
$ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )->willReturnSelf ();
220
+
221
+ $ returnFile = $ destDir . DIRECTORY_SEPARATOR . $ fileName ;
222
+
212
223
$ 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
+ ]);
214
258
215
259
$ 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 );
217
264
}
218
265
219
266
/**
0 commit comments