@@ -28,12 +28,10 @@ class GenerateRenditionsTest extends TestCase
2828 private $ generateRenditions ;
2929
3030 /**
31- * @var GetRenditionPathInterface
31+ * @var WriteInterface
3232 */
3333 private $ mediaDirectory ;
3434
35- protected static $ mediaDir ;
36-
3735 public static function setUpBeforeClass (): void
3836 {
3937 /** @var WriteInterface $mediaDirectory */
@@ -43,12 +41,12 @@ public static function setUpBeforeClass(): void
4341 DirectoryList::MEDIA
4442 );
4543
46- self :: $ mediaDir = $ mediaDirectory ->getAbsolutePath ();
44+ $ mediaDir = $ mediaDirectory ->getAbsolutePath ();
4745
4846 $ fixtureDir = realpath (__DIR__ . '/../_files ' );
4947
50- copy ($ fixtureDir . self ::LARGE_SIZE_IMAGE , self :: $ mediaDir . self ::LARGE_SIZE_IMAGE );
51- copy ($ fixtureDir . self ::MEDIUM_SIZE_IMAGE , self :: $ mediaDir . self ::MEDIUM_SIZE_IMAGE );
48+ copy ($ fixtureDir . self ::LARGE_SIZE_IMAGE , $ mediaDir . self ::LARGE_SIZE_IMAGE );
49+ copy ($ fixtureDir . self ::MEDIUM_SIZE_IMAGE , $ mediaDir . self ::MEDIUM_SIZE_IMAGE );
5250 }
5351
5452 protected function setup (): void
@@ -66,25 +64,50 @@ public static function tearDownAfterClass(): void
6664 )->getDirectoryWrite (
6765 DirectoryList::MEDIA
6866 );
69-
70- if ($ mediaDirectory ->isExist (self :: $ mediaDir . self ::LARGE_SIZE_IMAGE )) {
71- $ mediaDirectory ->delete (self :: $ mediaDir . self ::LARGE_SIZE_IMAGE );
67+ $ mediaDir = $ mediaDirectory -> getAbsolutePath ();
68+ if ($ mediaDirectory ->isExist ($ mediaDir . self ::LARGE_SIZE_IMAGE )) {
69+ $ mediaDirectory ->delete ($ mediaDir . self ::LARGE_SIZE_IMAGE );
7270 }
73- if ($ mediaDirectory ->isExist (self :: $ mediaDir . self ::MEDIUM_SIZE_IMAGE )) {
74- $ mediaDirectory ->delete (self :: $ mediaDir . self ::MEDIUM_SIZE_IMAGE );
71+ if ($ mediaDirectory ->isExist ($ mediaDir . self ::MEDIUM_SIZE_IMAGE )) {
72+ $ mediaDirectory ->delete ($ mediaDir . self ::MEDIUM_SIZE_IMAGE );
7573 }
76- if ($ mediaDirectory ->isExist (self :: $ mediaDir . self ::RENDITIONS_FOLDER_NAME )) {
77- $ mediaDirectory ->delete (self :: $ mediaDir . self ::RENDITIONS_FOLDER_NAME );
74+ if ($ mediaDirectory ->isExist ($ mediaDir . self ::RENDITIONS_FOLDER_NAME )) {
75+ $ mediaDirectory ->delete ($ mediaDir . self ::RENDITIONS_FOLDER_NAME );
7876 }
7977 }
8078
8179 /**
80+ * @dataProvider renditionsImageProvider
81+ *
8282 * Test for generation of rendition images.
8383 */
84- public function testExecute (): void
84+ public function testExecute (string $ path , string $ renditionPath , bool $ isRenditionsGenerated ): void
85+ {
86+ $ this ->generateRenditions ->execute ([$ path ]);
87+ $ expectedRenditionPath = $ this ->mediaDirectory ->getAbsolutePath ($ renditionPath );
88+ if ($ isRenditionsGenerated ) {
89+ $ this ->assertFileExists ($ expectedRenditionPath );
90+ } else {
91+ $ this ->assertFileDoesNotExist ($ expectedRenditionPath );
92+ }
93+ }
94+
95+ /**
96+ * @return array
97+ */
98+ public function renditionsImageProvider (): array
8599 {
86- $ this ->generateRenditions ->execute ([self ::LARGE_SIZE_IMAGE , self ::MEDIUM_SIZE_IMAGE ]);
87- $ this ->assertFileExists ($ this ->mediaDirectory ->getAbsolutePath (self ::RENDITIONS_FOLDER_NAME . self ::LARGE_SIZE_IMAGE ));
88- $ this ->assertFileDoesNotExist ($ this ->mediaDirectory ->getAbsolutePath (self ::RENDITIONS_FOLDER_NAME . self ::MEDIUM_SIZE_IMAGE ));
100+ return [
101+ 'rendition_image_not_generated ' => [
102+ 'path ' => '/magento_medium_image.jpg ' ,
103+ 'renditionPath ' => ".renditions/magento_medium_image.jpg " ,
104+ 'isRenditionsGenerated ' => false
105+ ],
106+ 'rendition_image_generated ' => [
107+ 'path ' => '/magento_large_image.jpg ' ,
108+ 'renditionPath ' => ".renditions/magento_large_image.jpg " ,
109+ 'isRenditionsGenerated ' => true
110+ ]
111+ ];
89112 }
90113}
0 commit comments