Skip to content

Commit dd9e165

Browse files
MAGETWO-58729: [Generator] Add images to performance profile generator
1 parent c803240 commit dd9e165

File tree

1 file changed

+51
-15
lines changed

1 file changed

+51
-15
lines changed

setup/src/Magento/Setup/Test/Unit/Fixtures/AttributeSet/SwatchesGeneratorTest.php

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Magento\Setup\Test\Unit\Fixtures\AttributeSet;
88

9-
use Magento\Catalog\Model\Product\Media\Config;
10-
use Magento\Framework\Filesystem;
9+
use Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory;
10+
use Magento\Setup\Fixtures\ImagesGenerator\ImagesGenerator;
1111
use Magento\Setup\Fixtures\AttributeSet\SwatchesGenerator;
1212
use Magento\Swatches\Helper\Media;
1313
use Magento\Swatches\Model\Swatch;
@@ -19,35 +19,58 @@ class SwatchesGeneratorTest extends \PHPUnit_Framework_TestCase
1919
*/
2020
private $swatchesGeneratorMock;
2121

22+
/**
23+
* @var array
24+
*/
25+
private $imagePathFixture = [
26+
'option_1' => '/<-o->',
27+
'option_2' => '/>o<',
28+
'option_3' => '/|o|'
29+
];
30+
2231
public function setUp()
2332
{
24-
// Mock Filesystem
25-
$filesystemMock = $this->getMockBuilder(Filesystem::class)
33+
// Mock Swatch Media Helper
34+
$swatchHelperMock = $this->getMockBuilder(Media::class)
2635
->disableOriginalConstructor()
2736
->getMock();
2837

29-
// Mock Media Config
30-
$mediaConfigMock = $this->getMockBuilder(Config::class)
38+
$swatchHelperMock
39+
->expects($this->any())
40+
->method('moveImageFromTmp')
41+
->willReturnOnConsecutiveCalls(...array_values($this->imagePathFixture));
42+
43+
// Mock image generator
44+
$imageGeneratorMock = $this->getMockBuilder(ImagesGenerator::class)
3145
->disableOriginalConstructor()
3246
->getMock();
3347

34-
// Mock Swatch Media Helper
35-
$swatchHelperMock = $this->getMockBuilder(Media::class)
48+
$imageGeneratorMock
49+
->expects($this->any())
50+
->method('generate');
51+
52+
// Mock image generator factory
53+
$imageGeneratorFactoryMock = $this->getMockBuilder(ImagesGeneratorFactory::class)
3654
->disableOriginalConstructor()
55+
->setMethods(['create'])
3756
->getMock();
3857

58+
$imageGeneratorFactoryMock
59+
->expects($this->once())
60+
->method('create')
61+
->willReturn($imageGeneratorMock);
62+
3963
$this->swatchesGeneratorMock = new SwatchesGenerator(
40-
$filesystemMock,
41-
$mediaConfigMock,
42-
$swatchHelperMock
64+
$swatchHelperMock,
65+
$imageGeneratorFactoryMock
4366
);
4467
}
4568

4669
public function testGenerateSwatchData()
4770
{
4871

49-
$attribute['swatch_input_type'] = Swatch::SWATCH_INPUT_TYPE_VISUAL;
50-
$attribute['swatchvisual']['value'] = array_reduce(
72+
$attributeColorType['swatch_input_type'] = Swatch::SWATCH_INPUT_TYPE_VISUAL;
73+
$attributeColorType['swatchvisual']['value'] = array_reduce(
5174
range(1, 3),
5275
function ($values, $index) {
5376
$values['option_' . $index] = '#' . str_repeat(dechex(255 * $index / 3), 3);
@@ -56,7 +79,7 @@ function ($values, $index) {
5679
[]
5780
);
5881

59-
$attribute['optionvisual']['value'] = array_reduce(
82+
$attributeColorType['optionvisual']['value'] = array_reduce(
6083
range(1, 3),
6184
function ($values, $index) {
6285
$values['option_' . $index] = ['option ' . $index];
@@ -65,9 +88,22 @@ function ($values, $index) {
6588
[]
6689
);
6790

91+
$attributeImageType = $attributeColorType;
92+
$attributeImageType['swatchvisual']['value'] = array_map(
93+
function($item) {
94+
return ltrim($item, '/');
95+
},
96+
$this->imagePathFixture
97+
);
98+
6899
$this->assertEquals(
69-
$attribute,
100+
$attributeColorType,
70101
$this->swatchesGeneratorMock->generateSwatchData(3, 'test', 'color')
71102
);
103+
104+
$this->assertEquals(
105+
$attributeImageType,
106+
$this->swatchesGeneratorMock->generateSwatchData(3, 'test', 'image')
107+
);
72108
}
73109
}

0 commit comments

Comments
 (0)