Skip to content

Commit 4b79d4d

Browse files
committed
upload media files fix
1 parent e6e6769 commit 4b79d4d

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ protected function _objectConstructor()
410410
$this->_filesystem->expects($this->once())
411411
->method('getDirectoryWrite')
412412
->with(DirectoryList::ROOT)
413-
->will($this->returnValue(self::MEDIA_DIRECTORY));
413+
->willReturn($this->_mediaDirectory);
414414

415415
$this->validator->expects($this->any())->method('init');
416416
return $this;
@@ -1229,6 +1229,56 @@ public function testParseAttributesWithWrappedValuesWillReturnsLowercasedAttribu
12291229
$this->assertArrayNotHasKey('PARAM2', $attributes);
12301230
}
12311231

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+
12321282
/**
12331283
* Test that errors occurred during importing images are logged.
12341284
*
@@ -1275,6 +1325,20 @@ function ($name) use ($throwException, $exception) {
12751325
);
12761326
}
12771327

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+
12781342
/**
12791343
* Data provider for testUploadMediaFiles.
12801344
*

0 commit comments

Comments
 (0)