Skip to content

Commit 0fdbb91

Browse files
author
Stanislav Idolov
authored
ENGCOM-3208: [Backport] move hardcoded MIME types from class private to DI configuration #18662
2 parents 82b50ac + ca94e72 commit 0fdbb91

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

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

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

8176
/**
8277
* ImageUploader constructor
@@ -89,6 +84,7 @@ class ImageUploader
8984
* @param string $baseTmpPath
9085
* @param string $basePath
9186
* @param string[] $allowedExtensions
87+
* @param string[] $allowedMimeTypes
9288
*/
9389
public function __construct(
9490
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
@@ -98,7 +94,8 @@ public function __construct(
9894
\Psr\Log\LoggerInterface $logger,
9995
$baseTmpPath,
10096
$basePath,
101-
$allowedExtensions
97+
$allowedExtensions,
98+
$allowedMimeTypes = []
10299
) {
103100
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
104101
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
@@ -108,6 +105,7 @@ public function __construct(
108105
$this->baseTmpPath = $baseTmpPath;
109106
$this->basePath = $basePath;
110107
$this->allowedExtensions = $allowedExtensions;
108+
$this->allowedMimeTypes = $allowedMimeTypes;
111109
}
112110

113111
/**
@@ -167,7 +165,7 @@ public function getBasePath()
167165
}
168166

169167
/**
170-
* Retrieve base path
168+
* Retrieve allowed extensions
171169
*
172170
* @return string[]
173171
*/

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
@@ -212,6 +212,12 @@
212212
<item name="gif" xsi:type="string">gif</item>
213213
<item name="png" xsi:type="string">png</item>
214214
</argument>
215+
<argument name="allowedMimeTypes" xsi:type="array">
216+
<item name="jpg" xsi:type="string">image/jpg</item>
217+
<item name="jpeg" xsi:type="string">image/jpeg</item>
218+
<item name="gif" xsi:type="string">image/gif</item>
219+
<item name="png" xsi:type="string">image/png</item>
220+
</argument>
215221
</arguments>
216222
</virtualType>
217223
<type name="Magento\Catalog\Controller\Adminhtml\Category\Image\Upload">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ protected function setUp()
4646
[
4747
'baseTmpPath' => $this->mediaDirectory->getRelativePath('tmp'),
4848
'basePath' => __DIR__,
49-
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png']
49+
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
50+
'allowedMimeTypes' => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']
5051
]
5152
);
5253
}

0 commit comments

Comments
 (0)