Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions app/code/Magento/Catalog/Model/ImageUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ class ImageUploader
/**
* List of allowed image mime types
*
* @var array
* @var string[]
*/
private $allowedMimeTypes = [
'image/jpg',
'image/jpeg',
'image/gif',
'image/png'
];
private $allowedMimeTypes;

/**
* ImageUploader constructor
Expand All @@ -89,6 +84,7 @@ class ImageUploader
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
* @param string[] $allowedMimeTypes
*/
public function __construct(
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
Expand All @@ -98,7 +94,8 @@ public function __construct(
\Psr\Log\LoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
$allowedExtensions,
$allowedMimeTypes = []
) {
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
Expand All @@ -108,6 +105,7 @@ public function __construct(
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;
$this->allowedMimeTypes = $allowedMimeTypes;
}

/**
Expand Down Expand Up @@ -167,7 +165,7 @@ public function getBasePath()
}

/**
* Retrieve base path
* Retrieve allowed extensions
*
* @return string[]
*/
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ class ImageUploaderTest extends \PHPUnit\Framework\TestCase
/**
* Allowed extensions
*
* @var string
* @var array
*/
private $allowedExtensions;

/**
* Allowed mime types
*
* @var array
*/
private $allowedMimeTypes;

protected function setUp()
{
$this->coreFileStorageDatabaseMock = $this->createMock(
Expand All @@ -97,6 +104,7 @@ protected function setUp()
$this->baseTmpPath = 'base/tmp/';
$this->basePath = 'base/real/';
$this->allowedExtensions = ['.jpg'];
$this->allowedMimeTypes = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png'];

$this->imageUploader =
new \Magento\Catalog\Model\ImageUploader(
Expand All @@ -107,7 +115,8 @@ protected function setUp()
$this->loggerMock,
$this->baseTmpPath,
$this->basePath,
$this->allowedExtensions
$this->allowedExtensions,
$this->allowedMimeTypes
);
}

Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
<argument name="allowedMimeTypes" xsi:type="array">
<item name="jpg" xsi:type="string">image/jpg</item>
<item name="jpeg" xsi:type="string">image/jpeg</item>
<item name="gif" xsi:type="string">image/gif</item>
<item name="png" xsi:type="string">image/png</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Controller\Adminhtml\Category\Image\Upload">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function setUp()
[
'baseTmpPath' => $this->mediaDirectory->getRelativePath('tmp'),
'basePath' => __DIR__,
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png']
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
'allowedMimeTypes' => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']
]
);
}
Expand Down