Skip to content

Commit 58d40d3

Browse files
Dataprovider added
1 parent 077766e commit 58d40d3

File tree

2 files changed

+62
-22
lines changed

2 files changed

+62
-22
lines changed

MediaGalleryRenditions/Test/Integration/Model/GenerateRenditionsTest.php

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

MediaGalleryRenditions/Test/Integration/Model/GetRenditionPathTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,30 @@ public static function tearDownAfterClass(): void
7272
}
7373

7474
/**
75+
* @dataProvider getImageProvider
76+
*
7577
* Test for getting a rendition path.
7678
*/
77-
public function testExecute(): void
79+
public function testExecute(string $path, string $expectedRenditionPath): void
7880
{
79-
$expectedOriginalImagePath = $this->getRenditionPath->execute(self::MEDIUM_SIZE_IMAGE);
80-
$expectedRenditionImagePath = $this->getRenditionPath->execute(self::LARGE_SIZE_IMAGE);
81-
$this->assertEquals(self::MEDIUM_SIZE_IMAGE, $expectedOriginalImagePath);
82-
$this->assertEquals('.renditions' . self::LARGE_SIZE_IMAGE, $expectedRenditionImagePath);
81+
$getRenditionPath = $this->getRenditionPath->execute($path);
82+
$this->assertEquals($expectedRenditionPath, $getRenditionPath);
83+
}
84+
85+
/**
86+
* @return array
87+
*/
88+
public function getImageProvider(): array
89+
{
90+
return [
91+
'return_original_path' => [
92+
'path' => '/magento_medium_image.jpg',
93+
'expectedRenditionPath' => '/magento_medium_image.jpg'
94+
],
95+
'return_rendition_path' => [
96+
'path' => '/magento_large_image.jpg',
97+
'expectedRenditionPath' => '.renditions/magento_large_image.jpg'
98+
]
99+
];
83100
}
84101
}

0 commit comments

Comments
 (0)