6
6
7
7
namespace Magento \Setup \Test \Unit \Fixtures \AttributeSet ;
8
8
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 ;
11
11
use Magento \Setup \Fixtures \AttributeSet \SwatchesGenerator ;
12
12
use Magento \Swatches \Helper \Media ;
13
13
use Magento \Swatches \Model \Swatch ;
@@ -19,35 +19,58 @@ class SwatchesGeneratorTest extends \PHPUnit_Framework_TestCase
19
19
*/
20
20
private $ swatchesGeneratorMock ;
21
21
22
+ /**
23
+ * @var array
24
+ */
25
+ private $ imagePathFixture = [
26
+ 'option_1 ' => '/<-o-> ' ,
27
+ 'option_2 ' => '/>o< ' ,
28
+ 'option_3 ' => '/|o| '
29
+ ];
30
+
22
31
public function setUp ()
23
32
{
24
- // Mock Filesystem
25
- $ filesystemMock = $ this ->getMockBuilder (Filesystem ::class)
33
+ // Mock Swatch Media Helper
34
+ $ swatchHelperMock = $ this ->getMockBuilder (Media ::class)
26
35
->disableOriginalConstructor ()
27
36
->getMock ();
28
37
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)
31
45
->disableOriginalConstructor ()
32
46
->getMock ();
33
47
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)
36
54
->disableOriginalConstructor ()
55
+ ->setMethods (['create ' ])
37
56
->getMock ();
38
57
58
+ $ imageGeneratorFactoryMock
59
+ ->expects ($ this ->once ())
60
+ ->method ('create ' )
61
+ ->willReturn ($ imageGeneratorMock );
62
+
39
63
$ this ->swatchesGeneratorMock = new SwatchesGenerator (
40
- $ filesystemMock ,
41
- $ mediaConfigMock ,
42
- $ swatchHelperMock
64
+ $ swatchHelperMock ,
65
+ $ imageGeneratorFactoryMock
43
66
);
44
67
}
45
68
46
69
public function testGenerateSwatchData ()
47
70
{
48
71
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 (
51
74
range (1 , 3 ),
52
75
function ($ values , $ index ) {
53
76
$ values ['option_ ' . $ index ] = '# ' . str_repeat (dechex (255 * $ index / 3 ), 3 );
@@ -56,7 +79,7 @@ function ($values, $index) {
56
79
[]
57
80
);
58
81
59
- $ attribute ['optionvisual ' ]['value ' ] = array_reduce (
82
+ $ attributeColorType ['optionvisual ' ]['value ' ] = array_reduce (
60
83
range (1 , 3 ),
61
84
function ($ values , $ index ) {
62
85
$ values ['option_ ' . $ index ] = ['option ' . $ index ];
@@ -65,9 +88,22 @@ function ($values, $index) {
65
88
[]
66
89
);
67
90
91
+ $ attributeImageType = $ attributeColorType ;
92
+ $ attributeImageType ['swatchvisual ' ]['value ' ] = array_map (
93
+ function ($ item ) {
94
+ return ltrim ($ item , '/ ' );
95
+ },
96
+ $ this ->imagePathFixture
97
+ );
98
+
68
99
$ this ->assertEquals (
69
- $ attribute ,
100
+ $ attributeColorType ,
70
101
$ this ->swatchesGeneratorMock ->generateSwatchData (3 , 'test ' , 'color ' )
71
102
);
103
+
104
+ $ this ->assertEquals (
105
+ $ attributeImageType ,
106
+ $ this ->swatchesGeneratorMock ->generateSwatchData (3 , 'test ' , 'image ' )
107
+ );
72
108
}
73
109
}
0 commit comments