Skip to content

Commit 077766e

Browse files
Integration test coverage for rendition image generation
1 parent abd6fbf commit 077766e

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryRenditions\Test\Integration\Model;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem;
12+
use Magento\Framework\Filesystem\Directory\WriteInterface;
13+
use Magento\MediaGalleryRenditionsApi\Api\GenerateRenditionsInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class GenerateRenditionsTest extends TestCase
18+
{
19+
private const MEDIUM_SIZE_IMAGE = '/magento_medium_image.jpg';
20+
21+
private const LARGE_SIZE_IMAGE = '/magento_large_image.jpg';
22+
23+
private const RENDITIONS_FOLDER_NAME = '.renditions';
24+
25+
/**
26+
* @var GenerateRenditionsInterface
27+
*/
28+
private $generateRenditions;
29+
30+
/**
31+
* @var GetRenditionPathInterface
32+
*/
33+
private $mediaDirectory;
34+
35+
protected static $mediaDir;
36+
37+
public static function setUpBeforeClass(): void
38+
{
39+
/** @var WriteInterface $mediaDirectory */
40+
$mediaDirectory = Bootstrap::getObjectManager()->get(
41+
Filesystem::class
42+
)->getDirectoryWrite(
43+
DirectoryList::MEDIA
44+
);
45+
46+
self::$mediaDir = $mediaDirectory->getAbsolutePath();
47+
48+
$fixtureDir = realpath(__DIR__ . '/../_files');
49+
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);
52+
}
53+
54+
protected function setup(): void
55+
{
56+
$this->generateRenditions = Bootstrap::getObjectManager()->get(GenerateRenditionsInterface::class);
57+
$this->filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
58+
$this->mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
59+
}
60+
61+
public static function tearDownAfterClass(): void
62+
{
63+
/** @var WriteInterface $mediaDirectory */
64+
$mediaDirectory = Bootstrap::getObjectManager()->get(
65+
Filesystem::class
66+
)->getDirectoryWrite(
67+
DirectoryList::MEDIA
68+
);
69+
70+
if ($mediaDirectory->isExist(self::$mediaDir . self::LARGE_SIZE_IMAGE)) {
71+
$mediaDirectory->delete(self::$mediaDir . self::LARGE_SIZE_IMAGE);
72+
}
73+
if ($mediaDirectory->isExist(self::$mediaDir . self::MEDIUM_SIZE_IMAGE)) {
74+
$mediaDirectory->delete(self::$mediaDir . self::MEDIUM_SIZE_IMAGE);
75+
}
76+
if ($mediaDirectory->isExist(self::$mediaDir . self::RENDITIONS_FOLDER_NAME)) {
77+
$mediaDirectory->delete(self::$mediaDir . self::RENDITIONS_FOLDER_NAME);
78+
}
79+
}
80+
81+
/**
82+
* Test for generation of rendition images.
83+
*/
84+
public function testExecute(): void
85+
{
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));
89+
}
90+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryRenditions\Test\Integration\Model;
10+
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use Magento\Framework\Filesystem\Directory\ReadInterface;
15+
use Magento\MediaGalleryRenditionsApi\Api\GetRenditionPathInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class GetRenditionPathTest extends TestCase
20+
{
21+
private const MEDIUM_SIZE_IMAGE = '/magento_medium_image.jpg';
22+
23+
private const LARGE_SIZE_IMAGE = '/magento_large_image.jpg';
24+
25+
/**
26+
* @var GetRenditionPathInterface
27+
*/
28+
private $getRenditionPath;
29+
30+
/**
31+
* @var ReadInterface
32+
*/
33+
protected static $mediaDir;
34+
35+
public static function setUpBeforeClass(): void
36+
{
37+
/** @var WriteInterface $mediaDirectory */
38+
$mediaDirectory = Bootstrap::getObjectManager()->get(
39+
Filesystem::class
40+
)->getDirectoryWrite(
41+
DirectoryList::MEDIA
42+
);
43+
44+
self::$mediaDir = $mediaDirectory->getAbsolutePath();
45+
46+
$fixtureDir = realpath(__DIR__ . '/../_files');
47+
48+
copy($fixtureDir . self::LARGE_SIZE_IMAGE, self::$mediaDir . self::LARGE_SIZE_IMAGE);
49+
copy($fixtureDir . self::MEDIUM_SIZE_IMAGE, self::$mediaDir . self::MEDIUM_SIZE_IMAGE);
50+
}
51+
52+
protected function setup(): void
53+
{
54+
$this->getRenditionPath = Bootstrap::getObjectManager()->get(GetRenditionPathInterface::class);
55+
}
56+
57+
public static function tearDownAfterClass(): void
58+
{
59+
/** @var WriteInterface $mediaDirectory */
60+
$mediaDirectory = Bootstrap::getObjectManager()->get(
61+
Filesystem::class
62+
)->getDirectoryWrite(
63+
DirectoryList::MEDIA
64+
);
65+
66+
if ($mediaDirectory->isExist(self::$mediaDir . self::LARGE_SIZE_IMAGE)) {
67+
$mediaDirectory->delete(self::$mediaDir . self::LARGE_SIZE_IMAGE);
68+
}
69+
if ($mediaDirectory->isExist(self::$mediaDir . self::MEDIUM_SIZE_IMAGE)) {
70+
$mediaDirectory->delete(self::$mediaDir . self::MEDIUM_SIZE_IMAGE);
71+
}
72+
}
73+
74+
/**
75+
* Test for getting a rendition path.
76+
*/
77+
public function testExecute(): void
78+
{
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);
83+
}
84+
}
54 KB
Loading
34.2 KB
Loading

0 commit comments

Comments
 (0)