Skip to content

Commit 3eadcc4

Browse files
committed
MAGETWO-90070: Image uploader improvements
1 parent 1ca70b1 commit 3eadcc4

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public function moveFileFromTmp($imageName)
230230
* @return string[]
231231
*
232232
* @throws \Magento\Framework\Exception\LocalizedException
233-
* @throws \Exception
234233
*/
235234
public function saveFileToTmpDir($fileId)
236235
{

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ public function deleteFile($target)
478478
* @param string $type Type of storage, e.g. image, media etc.
479479
* @return array File info Array
480480
* @throws \Magento\Framework\Exception\LocalizedException
481-
* @throws \Exception
482481
*/
483482
public function uploadFile($targetPath, $type = null)
484483
{
@@ -757,7 +756,7 @@ protected function _getRelativePathToRoot($path)
757756
}
758757

759758
/**
760-
* Prepare mime types config settings
759+
* Prepare mime types config settings.
761760
*
762761
* @param string|null $type Type of storage, e.g. image, media etc.
763762
* @return array Array of allowed file extensions
@@ -770,7 +769,7 @@ private function getAllowedMimeTypes($type = null): array
770769
}
771770

772771
/**
773-
* Get list of allowed file extensions with mime type in values
772+
* Get list of allowed file extensions with mime type in values.
774773
*
775774
* @param string|null $type
776775
* @return array
@@ -782,6 +781,7 @@ private function getExtensionsList($type = null): array
782781
} else {
783782
$allowed = $this->_extensions['allowed'];
784783
}
784+
785785
return $allowed;
786786
}
787787
}

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,22 @@ public function testGetResizeHeight()
250250

251251
/**
252252
* @covers \Magento\Cms\Model\Wysiwyg\Images\Storage::deleteDirectory
253+
* @expectedException \Magento\Framework\Exception\LocalizedException
254+
* @expectedExceptionMessage Directory /storage/some/another/dir is not under storage root path.
253255
*/
254256
public function testDeleteDirectoryOverRoot()
255257
{
256-
$this->expectException(
257-
\Magento\Framework\Exception\LocalizedException::class,
258-
sprintf('Directory %s is not under storage root path.', self::INVALID_DIRECTORY_OVER_ROOT)
259-
);
260258
$this->driverMock->expects($this->atLeastOnce())->method('getRealPathSafety')->will($this->returnArgument(0));
261259
$this->imagesStorage->deleteDirectory(self::INVALID_DIRECTORY_OVER_ROOT);
262260
}
263261

264262
/**
265263
* @covers \Magento\Cms\Model\Wysiwyg\Images\Storage::deleteDirectory
264+
* @expectedException \Magento\Framework\Exception\LocalizedException
265+
* @expectedExceptionMessage We can't delete root directory /storage/root/dir right now.
266266
*/
267267
public function testDeleteRootDirectory()
268268
{
269-
$this->expectException(
270-
\Magento\Framework\Exception\LocalizedException::class,
271-
sprintf('We can\'t delete root directory %s right now.', self::STORAGE_ROOT_DIR)
272-
);
273269
$this->driverMock->expects($this->atLeastOnce())->method('getRealPathSafety')->will($this->returnArgument(0));
274270
$this->imagesStorage->deleteDirectory(self::STORAGE_ROOT_DIR);
275271
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class ImageUploaderTest extends \PHPUnit\Framework\TestCase
3434
*/
3535
private $mediaDirectory;
3636

37+
/**
38+
* @inheritdoc
39+
*/
3740
protected function setUp()
3841
{
3942
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -46,12 +49,15 @@ protected function setUp()
4649
[
4750
'baseTmpPath' => $this->mediaDirectory->getRelativePath('tmp'),
4851
'basePath' => __DIR__,
49-
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png']
52+
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
5053
]
5154
);
5255
}
5356

54-
public function testSaveFileToTmpDir()
57+
/**
58+
* @return void
59+
*/
60+
public function testSaveFileToTmpDir(): void
5561
{
5662
$fileName = 'magento_small_image.jpg';
5763
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
@@ -75,8 +81,9 @@ public function testSaveFileToTmpDir()
7581
/**
7682
* @expectedException \Magento\Framework\Exception\LocalizedException
7783
* @expectedExceptionMessage File validation failed.
84+
* @return void
7885
*/
79-
public function testSaveFileToTmpDirWithWrongExtension()
86+
public function testSaveFileToTmpDirWithWrongExtension(): void
8087
{
8188
$fileName = 'text.txt';
8289
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
@@ -100,8 +107,9 @@ public function testSaveFileToTmpDirWithWrongExtension()
100107
/**
101108
* @expectedException \Magento\Framework\Exception\LocalizedException
102109
* @expectedExceptionMessage File validation failed.
110+
* @return void
103111
*/
104-
public function testSaveFileToTmpDirWithWrongFile()
112+
public function testSaveFileToTmpDirWithWrongFile(): void
105113
{
106114
$fileName = 'file.gif';
107115
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);

lib/internal/Magento/Framework/File/Mime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Mime
5959
];
6060

6161
/**
62-
* List of mime types that can be defined by file extension
62+
* List of mime types that can be defined by file extension.
6363
*
6464
* @var array $defineByExtensionList
6565
*/
@@ -125,7 +125,7 @@ private function getNativeMimeType(string $file): string
125125
}
126126

127127
/**
128-
* Get file extension by file name
128+
* Get file extension by file name.
129129
*
130130
* @param string $file
131131
* @return string

0 commit comments

Comments
 (0)