Skip to content

Commit 4cf339c

Browse files
author
Stanislav Idolov
authored
ENGCOM-3157: move hardcoded MIME types from class private to DI configuration. #18365
2 parents a21092c + 1d0b07d commit 4cf339c

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

app/code/Magento/Catalog/Model/ImageUploader.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ class ImageUploader
6767
/**
6868
* List of allowed image mime types
6969
*
70-
* @var array
70+
* @var string[]
7171
*/
72-
private $allowedMimeTypes = [
73-
'image/jpg',
74-
'image/jpeg',
75-
'image/gif',
76-
'image/png',
77-
];
72+
private $allowedMimeTypes;
7873

7974
/**
8075
* ImageUploader constructor
@@ -87,6 +82,7 @@ class ImageUploader
8782
* @param string $baseTmpPath
8883
* @param string $basePath
8984
* @param string[] $allowedExtensions
85+
* @param string[] $allowedMimeTypes
9086
*/
9187
public function __construct(
9288
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
@@ -96,7 +92,8 @@ public function __construct(
9692
\Psr\Log\LoggerInterface $logger,
9793
$baseTmpPath,
9894
$basePath,
99-
$allowedExtensions
95+
$allowedExtensions,
96+
$allowedMimeTypes = []
10097
) {
10198
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
10299
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
@@ -106,6 +103,7 @@ public function __construct(
106103
$this->baseTmpPath = $baseTmpPath;
107104
$this->basePath = $basePath;
108105
$this->allowedExtensions = $allowedExtensions;
106+
$this->allowedMimeTypes = $allowedMimeTypes;
109107
}
110108

111109
/**
@@ -165,7 +163,7 @@ public function getBasePath()
165163
}
166164

167165
/**
168-
* Retrieve base path
166+
* Retrieve allowed extensions
169167
*
170168
* @return string[]
171169
*/

app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ class ImageUploaderTest extends \PHPUnit\Framework\TestCase
6969
/**
7070
* Allowed extensions
7171
*
72-
* @var string
72+
* @var array
7373
*/
7474
private $allowedExtensions;
7575

76+
/**
77+
* Allowed mime types
78+
*
79+
* @var array
80+
*/
81+
private $allowedMimeTypes;
82+
7683
protected function setUp()
7784
{
7885
$this->coreFileStorageDatabaseMock = $this->createMock(
@@ -97,6 +104,7 @@ protected function setUp()
97104
$this->baseTmpPath = 'base/tmp/';
98105
$this->basePath = 'base/real/';
99106
$this->allowedExtensions = ['.jpg'];
107+
$this->allowedMimeTypes = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png'];
100108

101109
$this->imageUploader =
102110
new \Magento\Catalog\Model\ImageUploader(
@@ -107,7 +115,8 @@ protected function setUp()
107115
$this->loggerMock,
108116
$this->baseTmpPath,
109117
$this->basePath,
110-
$this->allowedExtensions
118+
$this->allowedExtensions,
119+
$this->allowedMimeTypes
111120
);
112121
}
113122

app/code/Magento/Catalog/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@
220220
<item name="gif" xsi:type="string">gif</item>
221221
<item name="png" xsi:type="string">png</item>
222222
</argument>
223+
<argument name="allowedMimeTypes" xsi:type="array">
224+
<item name="jpg" xsi:type="string">image/jpg</item>
225+
<item name="jpeg" xsi:type="string">image/jpeg</item>
226+
<item name="gif" xsi:type="string">image/gif</item>
227+
<item name="png" xsi:type="string">image/png</item>
228+
</argument>
223229
</arguments>
224230
</virtualType>
225231
<type name="Magento\Catalog\Controller\Adminhtml\Category\Image\Upload">

dev/tests/integration/testsuite/Magento/Catalog/Model/ImageUploaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function setUp()
5050
'baseTmpPath' => $this->mediaDirectory->getRelativePath('tmp'),
5151
'basePath' => __DIR__,
5252
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
53+
'allowedMimeTypes' => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']
5354
]
5455
);
5556
}

0 commit comments

Comments
 (0)