@@ -229,8 +229,6 @@ function ($path) {
229229 self ::STORAGE_ROOT_DIR
230230 );
231231
232- $ this ->resizeParameters = ['width ' => 100 , 'height ' => 50 ];
233-
234232 $ this ->storageCollectionFactoryMock = $ this ->createPartialMock (
235233 CollectionFactory::class,
236234 ['create ' ]
@@ -296,31 +294,12 @@ function ($path) {
296294
297295 $ this ->imagesStorage = $ this ->objectManagerHelper ->getObject (
298296 Storage::class,
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- ]
297+ $ this ->getStorageClass (100 , 50 , $ allowedExtensions )
298+ );
299+
300+ $ this ->imagesStorageWithZeroHeight = $ this ->objectManagerHelper ->getObject (
301+ Storage::class,
302+ $ this ->getStorageClass (100 , 0 , $ allowedExtensions )
324303 );
325304 }
326305
@@ -696,4 +675,91 @@ public function testCreateDirectoryWithInvalidName()
696675 );
697676 $ this ->imagesStorage ->createDirectory ($ name , $ path );
698677 }
678+
679+ public function testResizeFileWithZeroHeight ()
680+ {
681+ $ path = 'target/path ' ;
682+ $ source = self ::STORAGE_ROOT_DIR . $ path ;
683+ $ fileName = 'image.jpg ' ;
684+ $ realPath = $ source . '/ ' . $ fileName ;
685+ $ thumbnailTargetPath = self ::STORAGE_ROOT_DIR . '.thumbs ' . $ path ;
686+ $ thumbnailDestination = $ thumbnailTargetPath . '/ ' . $ fileName ;
687+ $ result = false ;
688+ $ exceptionMessage = 'Exception message ' ;
689+ $ this ->directoryMock ->expects ($ this ->atLeastOnce ())->method ('getRelativePath ' )->willReturnMap (
690+ [
691+ [$ realPath , $ realPath ],
692+ [$ thumbnailTargetPath , $ thumbnailTargetPath ],
693+ [$ thumbnailDestination , $ thumbnailDestination ],
694+ ]
695+ );
696+ $ this ->directoryMock ->expects ($ this ->atLeastOnce ())->method ('isFile ' )
697+ ->willReturnMap (
698+ [
699+ [$ realPath , true ],
700+ [$ thumbnailDestination , true ],
701+ ]
702+ );
703+ $ this ->directoryMock ->expects ($ this ->atLeastOnce ())->method ('isExist ' )
704+ ->willReturnMap (
705+ [
706+ [$ realPath , true ],
707+ [$ thumbnailTargetPath , true ],
708+ ]
709+ );
710+ $ this ->driverMock ->expects (self ::once ())
711+ ->method ('fileGetContents ' )
712+ ->willReturn ('some content ' );
713+
714+
715+ $ image = $ this ->getMockBuilder (image::class)
716+ ->disableOriginalConstructor ()
717+ ->addMethods (['open ' , 'keepAspectRatio ' ])
718+ ->onlyMethods (['resize ' , 'save ' ])
719+ ->getMock ();
720+ $ image ->expects ($ this ->any ())->method ('open ' )->with ($ realPath );
721+ $ image ->expects ($ this ->any ())->method ('keepAspectRatio ' )->with (true );
722+ $ image ->expects ($ this ->once ())->method ('resize ' )->with (100 , 0 )
723+ ->willThrowException (new \LogicException ($ exceptionMessage ));
724+
725+
726+ $ this ->adapterFactoryMock ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ image );
727+
728+ // Logger should not log any critical errors in this scenario
729+ $ this ->loggerMock ->expects ($ this ->once ())
730+ ->method ('critical ' );
731+
732+ $ this ->assertEquals ($ result , $ this ->imagesStorageWithZeroHeight ->resizeFile ($ realPath ));
733+ }
734+
735+ public function getStorageClass ($ width , $ height , $ allowedExtensions )
736+ {
737+ $ this ->resizeParameters = ['width ' => $ width , 'height ' => $ height ];
738+ return
739+ [
740+ 'session ' => $ this ->sessionMock ,
741+ 'backendUrl ' => $ this ->backendUrlMock ,
742+ 'cmsWysiwygImages ' => $ this ->imageHelperMock ,
743+ 'coreFileStorageDb ' => $ this ->coreFileStorageMock ,
744+ 'filesystem ' => $ this ->filesystemMock ,
745+ 'imageFactory ' => $ this ->adapterFactoryMock ,
746+ 'assetRepo ' => $ this ->assetRepo ,
747+ 'storageCollectionFactory ' => $ this ->storageCollectionFactoryMock ,
748+ 'storageFileFactory ' => $ this ->storageFileFactoryMock ,
749+ 'storageDatabaseFactory ' => $ this ->storageDatabaseFactoryMock ,
750+ 'directoryDatabaseFactory ' => $ this ->directoryDatabaseFactoryMock ,
751+ 'uploaderFactory ' => $ this ->uploaderFactoryMock ,
752+ 'resizeParameters ' => $ this ->resizeParameters ,
753+ 'extensions ' => $ allowedExtensions ,
754+ 'dirs ' => [
755+ 'exclude ' => [],
756+ 'include ' => [],
757+ ],
758+ 'data ' => [],
759+ 'file ' => $ this ->fileMock ,
760+ 'ioFile ' => $ this ->ioFileMock ,
761+ 'coreConfig ' => $ this ->coreConfigMock ,
762+ 'logger ' => $ this ->loggerMock
763+ ];
764+ }
699765}
0 commit comments