@@ -410,7 +410,7 @@ protected function _objectConstructor()
410
410
$ this ->_filesystem ->expects ($ this ->once ())
411
411
->method ('getDirectoryWrite ' )
412
412
->with (DirectoryList::ROOT )
413
- ->will ($ this ->returnValue ( self :: MEDIA_DIRECTORY ) );
413
+ ->willReturn ($ this ->_mediaDirectory );
414
414
415
415
$ this ->validator ->expects ($ this ->any ())->method ('init ' );
416
416
return $ this ;
@@ -1229,6 +1229,56 @@ public function testParseAttributesWithWrappedValuesWillReturnsLowercasedAttribu
1229
1229
$ this ->assertArrayNotHasKey ('PARAM2 ' , $ attributes );
1230
1230
}
1231
1231
1232
+ /**
1233
+ * @param bool $isRead
1234
+ * @param bool $isWrite
1235
+ * @param string $message
1236
+ * @dataProvider fillUploaderObjectDataProvider
1237
+ */
1238
+ public function testFillUploaderObject ($ isRead , $ isWrite , $ message )
1239
+ {
1240
+ $ fileUploaderMock = $ this
1241
+ ->getMockBuilder (\Magento \CatalogImportExport \Model \Import \Uploader::class)
1242
+ ->disableOriginalConstructor ()
1243
+ ->getMock ();
1244
+
1245
+ $ fileUploaderMock
1246
+ ->method ('setTmpDir ' )
1247
+ ->with ('pub/media/import ' )
1248
+ ->willReturn ($ isRead );
1249
+
1250
+ $ fileUploaderMock
1251
+ ->method ('setDestDir ' )
1252
+ ->with ('pub/media/catalog/product ' )
1253
+ ->willReturn ($ isWrite );
1254
+
1255
+ $ this ->_mediaDirectory
1256
+ ->method ('getRelativePath ' )
1257
+ ->willReturnMap (
1258
+ [
1259
+ ['import ' , 'import ' ],
1260
+ ['catalog/product ' , 'catalog/product ' ],
1261
+ ]
1262
+ );
1263
+
1264
+ $ this ->_mediaDirectory
1265
+ ->method ('create ' )
1266
+ ->with ('pub/media/catalog/product ' );
1267
+
1268
+ $ this ->_uploaderFactory
1269
+ ->expects ($ this ->once ())
1270
+ ->method ('create ' )
1271
+ ->willReturn ($ fileUploaderMock );
1272
+
1273
+ try {
1274
+ $ this ->importProduct ->getUploader ();
1275
+ $ this ->assertNotNull ($ this ->getPropertyValue ($ this ->importProduct , '_fileUploader ' ));
1276
+ } catch (\Magento \Framework \Exception \LocalizedException $ e ) {
1277
+ $ this ->assertNull ($ this ->getPropertyValue ($ this ->importProduct , '_fileUploader ' ));
1278
+ $ this ->assertEquals ($ message , $ e ->getMessage ());
1279
+ }
1280
+ }
1281
+
1232
1282
/**
1233
1283
* Test that errors occurred during importing images are logged.
1234
1284
*
@@ -1275,6 +1325,20 @@ function ($name) use ($throwException, $exception) {
1275
1325
);
1276
1326
}
1277
1327
1328
+ /**
1329
+ * Data provider for testFillUploaderObject.
1330
+ *
1331
+ * @return array
1332
+ */
1333
+ public function fillUploaderObjectDataProvider ()
1334
+ {
1335
+ return [
1336
+ [false , true , 'File directory \'pub/media/import \' is not readable. ' ],
1337
+ [true , false , 'File directory \'pub/media/catalog/product \' is not writable. ' ],
1338
+ [true , true , '' ],
1339
+ ];
1340
+ }
1341
+
1278
1342
/**
1279
1343
* Data provider for testUploadMediaFiles.
1280
1344
*
0 commit comments