14
14
use Magento \Framework \Config \View ;
15
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
16
16
use Magento \Framework \View \ConfigInterface ;
17
+ use Magento \Framework \View \Design \Theme \FlyweightFactory ;
18
+ use Magento \Framework \View \Design \ThemeInterface ;
19
+ use Magento \Framework \View \DesignInterface ;
17
20
use Magento \Store \Model \ScopeInterface ;
18
21
use PHPUnit \Framework \TestCase ;
19
22
@@ -41,6 +44,12 @@ class ParamsBuilderTest extends TestCase
41
44
*/
42
45
private $ scopeConfigData = [];
43
46
47
+ private $ design ;
48
+
49
+ private $ themeFactory ;
50
+
51
+ private $ theme ;
52
+
44
53
/**
45
54
* @inheritDoc
46
55
*/
@@ -49,11 +58,19 @@ protected function setUp(): void
49
58
$ objectManager = new ObjectManager ($ this );
50
59
$ this ->scopeConfig = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
51
60
$ this ->viewConfig = $ this ->getMockForAbstractClass (ConfigInterface::class);
61
+ $ this ->design = $ this ->getMockBuilder (DesignInterface::class)
62
+ ->disableOriginalConstructor ()
63
+ ->getMockForAbstractClass ();
64
+ $ this ->themeFactory = $ this ->createMock (FlyweightFactory::class);
65
+ $ this ->theme = $ this ->getMockForAbstractClass (ThemeInterface::class);
66
+
52
67
$ this ->model = $ objectManager ->getObject (
53
68
ParamsBuilder::class,
54
69
[
55
70
'scopeConfig ' => $ this ->scopeConfig ,
56
71
'viewConfig ' => $ this ->viewConfig ,
72
+ 'design ' => $ this ->design ,
73
+ 'themeFactory ' => $ this ->themeFactory
57
74
]
58
75
);
59
76
$ this ->scopeConfigData = [];
@@ -69,13 +86,21 @@ function ($path, $scopeType, $scopeCode) {
69
86
* Test build() with different parameters and config values
70
87
*
71
88
* @param int $scopeId
89
+ * @param string $themeId
90
+ * @param bool $keepFrame
72
91
* @param array $config
73
92
* @param array $imageArguments
74
93
* @param array $expected
75
94
* @dataProvider buildDataProvider
76
95
*/
77
- public function testBuild (int $ scopeId , array $ config , array $ imageArguments , array $ expected )
78
- {
96
+ public function testBuild (
97
+ int $ scopeId ,
98
+ string $ themeId ,
99
+ bool $ keepFrame ,
100
+ array $ config ,
101
+ array $ imageArguments ,
102
+ array $ expected
103
+ ) {
79
104
$ this ->scopeConfigData [Image::XML_PATH_JPEG_QUALITY ][ScopeConfigInterface::SCOPE_TYPE_DEFAULT ][null ] = 80 ;
80
105
foreach ($ config as $ path => $ value ) {
81
106
$ this ->scopeConfigData [$ path ][ScopeInterface::SCOPE_STORE ][$ scopeId ] = $ value ;
@@ -88,15 +113,23 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
88
113
'background ' => [110 , 64 , 224 ]
89
114
];
90
115
116
+ $ this ->design ->expects ($ this ->once ())
117
+ ->method ('getConfigurationDesignTheme ' )
118
+ ->willReturn ($ themeId );
119
+ $ this ->themeFactory ->expects ($ this ->once ())
120
+ ->method ('create ' )
121
+ ->with ($ themeId )
122
+ ->willReturn ($ this ->theme );
123
+
91
124
$ viewMock = $ this ->createMock (View::class);
92
125
$ viewMock ->expects ($ this ->once ())
93
126
->method ('getVarValue ' )
94
127
->with ('Magento_Catalog ' , 'product_image_white_borders ' )
95
- ->willReturn (true );
128
+ ->willReturn ($ keepFrame );
96
129
97
130
$ this ->viewConfig ->expects ($ this ->once ())
98
131
->method ('getViewConfig ' )
99
- ->with (['area ' => Area::AREA_FRONTEND ])
132
+ ->with (['area ' => Area::AREA_FRONTEND , ' themeModel ' => $ this -> theme ])
100
133
->willReturn ($ viewMock );
101
134
102
135
$ actual = $ this ->model ->build ($ imageArguments , $ scopeId );
@@ -106,7 +139,6 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
106
139
'angle ' => $ imageArguments ['angle ' ],
107
140
'quality ' => 80 ,
108
141
'keep_aspect_ratio ' => true ,
109
- 'keep_frame ' => true ,
110
142
'keep_transparency ' => true ,
111
143
'constrain_only ' => true ,
112
144
'image_height ' => $ imageArguments ['height ' ],
@@ -129,6 +161,8 @@ public function buildDataProvider()
129
161
return [
130
162
'watermark config ' => [
131
163
1 ,
164
+ '1 ' ,
165
+ true ,
132
166
[
133
167
'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
134
168
'design/watermark/small_image_size ' => '60x40 ' ,
@@ -144,10 +178,32 @@ public function buildDataProvider()
144
178
'watermark_position ' => 'bottom-right ' ,
145
179
'watermark_width ' => '60 ' ,
146
180
'watermark_height ' => '40 ' ,
181
+ 'keep_frame ' => true
147
182
]
148
183
],
149
184
'watermark config empty ' => [
150
185
1 ,
186
+ '1 ' ,
187
+ true ,
188
+ [
189
+ 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
190
+ ],
191
+ [
192
+ 'type ' => 'small_image '
193
+ ],
194
+ [
195
+ 'watermark_file ' => 'stores/1/magento-logo.png ' ,
196
+ 'watermark_image_opacity ' => null ,
197
+ 'watermark_position ' => null ,
198
+ 'watermark_width ' => null ,
199
+ 'watermark_height ' => null ,
200
+ 'keep_frame ' => true
201
+ ]
202
+ ],
203
+ 'watermark empty with no border ' => [
204
+ 2 ,
205
+ '2 ' ,
206
+ false ,
151
207
[
152
208
'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
153
209
],
@@ -160,6 +216,7 @@ public function buildDataProvider()
160
216
'watermark_position ' => null ,
161
217
'watermark_width ' => null ,
162
218
'watermark_height ' => null ,
219
+ 'keep_frame ' => false
163
220
]
164
221
]
165
222
];
0 commit comments