@@ -54,11 +54,6 @@ class StorageTest extends TestCase
54
54
*/
55
55
private $ imagesStorage ;
56
56
57
- /**
58
- * @var Storage
59
- */
60
- private $ imagesStorageWithZeroHeight ;
61
-
62
57
/**
63
58
* @var MockObject
64
59
*/
@@ -234,6 +229,8 @@ function ($path) {
234
229
self ::STORAGE_ROOT_DIR
235
230
);
236
231
232
+ $ this ->resizeParameters = ['width ' => 100 , 'height ' => 50 ];
233
+
237
234
$ this ->storageCollectionFactoryMock = $ this ->createPartialMock (
238
235
CollectionFactory::class,
239
236
['create ' ]
@@ -299,12 +296,31 @@ function ($path) {
299
296
300
297
$ this ->imagesStorage = $ this ->objectManagerHelper ->getObject (
301
298
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
+ ]
308
324
);
309
325
}
310
326
@@ -680,88 +696,4 @@ public function testCreateDirectoryWithInvalidName()
680
696
);
681
697
$ this ->imagesStorage ->createDirectory ($ name , $ path );
682
698
}
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
- }
767
699
}
0 commit comments