Skip to content

Commit 3c2cf7e

Browse files
Chhandak.BaruaChhandak.Barua
Chhandak.Barua
authored and
Chhandak.Barua
committed
ACP2E-3127: imagecreatetruecolor(): Argument #2 () must be greater than 0. Can't upload specific image
1 parent 42d6ed0 commit 3c2cf7e

File tree

1 file changed

+27
-95
lines changed

1 file changed

+27
-95
lines changed

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

Lines changed: 27 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ class StorageTest extends TestCase
5454
*/
5555
private $imagesStorage;
5656

57-
/**
58-
* @var Storage
59-
*/
60-
private $imagesStorageWithZeroHeight;
61-
6257
/**
6358
* @var MockObject
6459
*/
@@ -234,6 +229,8 @@ function ($path) {
234229
self::STORAGE_ROOT_DIR
235230
);
236231

232+
$this->resizeParameters = ['width' => 100, 'height' => 50];
233+
237234
$this->storageCollectionFactoryMock = $this->createPartialMock(
238235
CollectionFactory::class,
239236
['create']
@@ -299,12 +296,31 @@ function ($path) {
299296

300297
$this->imagesStorage = $this->objectManagerHelper->getObject(
301298
Storage::class,
302-
$this->getStorageClass(100, 50, $allowedExtensions)
303-
);
304-
305-
$this->imagesStorageWithZeroHeight = $this->objectManagerHelper->getObject(
306-
Storage::class,
307-
$this->getStorageClass(100, 0, $allowedExtensions)
299+
[
300+
'session' => $this->sessionMock,
301+
'backendUrl' => $this->backendUrlMock,
302+
'cmsWysiwygImages' => $this->imageHelperMock,
303+
'coreFileStorageDb' => $this->coreFileStorageMock,
304+
'filesystem' => $this->filesystemMock,
305+
'imageFactory' => $this->adapterFactoryMock,
306+
'assetRepo' => $this->assetRepo,
307+
'storageCollectionFactory' => $this->storageCollectionFactoryMock,
308+
'storageFileFactory' => $this->storageFileFactoryMock,
309+
'storageDatabaseFactory' => $this->storageDatabaseFactoryMock,
310+
'directoryDatabaseFactory' => $this->directoryDatabaseFactoryMock,
311+
'uploaderFactory' => $this->uploaderFactoryMock,
312+
'resizeParameters' => $this->resizeParameters,
313+
'extensions' => $allowedExtensions,
314+
'dirs' => [
315+
'exclude' => [],
316+
'include' => [],
317+
],
318+
'data' => [],
319+
'file' => $this->fileMock,
320+
'ioFile' => $this->ioFileMock,
321+
'coreConfig' => $this->coreConfigMock,
322+
'logger' => $this->loggerMock
323+
]
308324
);
309325
}
310326

@@ -680,88 +696,4 @@ public function testCreateDirectoryWithInvalidName()
680696
);
681697
$this->imagesStorage->createDirectory($name, $path);
682698
}
683-
684-
public function testResizeFileWithZeroHeight()
685-
{
686-
$path = 'target/path';
687-
$source = self::STORAGE_ROOT_DIR . $path;
688-
$fileName = 'image.jpg';
689-
$realPath = $source . '/' . $fileName;
690-
$thumbnailTargetPath = self::STORAGE_ROOT_DIR . '.thumbs' . $path;
691-
$thumbnailDestination = $thumbnailTargetPath . '/' . $fileName;
692-
$result = false;
693-
$exceptionMessage = 'Exception message';
694-
$this->directoryMock->expects($this->atLeastOnce())->method('getRelativePath')->willReturnMap(
695-
[
696-
[$realPath, $realPath],
697-
[$thumbnailTargetPath, $thumbnailTargetPath],
698-
[$thumbnailDestination, $thumbnailDestination],
699-
]
700-
);
701-
$this->directoryMock->expects($this->atLeastOnce())->method('isFile')
702-
->willReturnMap(
703-
[
704-
[$realPath, true],
705-
[$thumbnailDestination, true],
706-
]
707-
);
708-
$this->directoryMock->expects($this->atLeastOnce())->method('isExist')
709-
->willReturnMap(
710-
[
711-
[$realPath, true],
712-
[$thumbnailTargetPath, true],
713-
]
714-
);
715-
$this->driverMock->expects(self::once())
716-
->method('fileGetContents')
717-
->willReturn('some content');
718-
719-
$image = $this->getMockBuilder(image::class)
720-
->disableOriginalConstructor()
721-
->addMethods(['open', 'keepAspectRatio'])
722-
->onlyMethods(['resize', 'save'])
723-
->getMock();
724-
$image->expects($this->any())->method('open')->with($realPath);
725-
$image->expects($this->any())->method('keepAspectRatio')->with(true);
726-
$image->expects($this->once())->method('resize')->with(100, 0)
727-
->willThrowException(new \LogicException($exceptionMessage));
728-
$this->adapterFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($image);
729-
730-
// Logger should not log any critical errors in this scenario
731-
$this->loggerMock->expects($this->once())
732-
->method('critical');
733-
734-
$this->assertEquals($result, $this->imagesStorageWithZeroHeight->resizeFile($realPath));
735-
}
736-
737-
public function getStorageClass($width, $height, $allowedExtensions)
738-
{
739-
$this->resizeParameters = ['width' => $width, 'height' => $height];
740-
return
741-
[
742-
'session' => $this->sessionMock,
743-
'backendUrl' => $this->backendUrlMock,
744-
'cmsWysiwygImages' => $this->imageHelperMock,
745-
'coreFileStorageDb' => $this->coreFileStorageMock,
746-
'filesystem' => $this->filesystemMock,
747-
'imageFactory' => $this->adapterFactoryMock,
748-
'assetRepo' => $this->assetRepo,
749-
'storageCollectionFactory' => $this->storageCollectionFactoryMock,
750-
'storageFileFactory' => $this->storageFileFactoryMock,
751-
'storageDatabaseFactory' => $this->storageDatabaseFactoryMock,
752-
'directoryDatabaseFactory' => $this->directoryDatabaseFactoryMock,
753-
'uploaderFactory' => $this->uploaderFactoryMock,
754-
'resizeParameters' => $this->resizeParameters,
755-
'extensions' => $allowedExtensions,
756-
'dirs' => [
757-
'exclude' => [],
758-
'include' => [],
759-
],
760-
'data' => [],
761-
'file' => $this->fileMock,
762-
'ioFile' => $this->ioFileMock,
763-
'coreConfig' => $this->coreConfigMock,
764-
'logger' => $this->loggerMock
765-
];
766-
}
767699
}

0 commit comments

Comments
 (0)