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,21 @@ class ParamsBuilderTest extends TestCase
41
44
*/
42
45
private $ scopeConfigData = [];
43
46
47
+ /**
48
+ * @var DesignInterface
49
+ */
50
+ private $ design ;
51
+
52
+ /**
53
+ * @var FlyweightFactory
54
+ */
55
+ private $ themeFactory ;
56
+
57
+ /**
58
+ * @var ThemeInterface
59
+ */
60
+ private $ theme ;
61
+
44
62
/**
45
63
* @inheritDoc
46
64
*/
@@ -49,11 +67,19 @@ protected function setUp(): void
49
67
$ objectManager = new ObjectManager ($ this );
50
68
$ this ->scopeConfig = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
51
69
$ this ->viewConfig = $ this ->getMockForAbstractClass (ConfigInterface::class);
70
+ $ this ->design = $ this ->getMockBuilder (DesignInterface::class)
71
+ ->disableOriginalConstructor ()
72
+ ->getMockForAbstractClass ();
73
+ $ this ->themeFactory = $ this ->createMock (FlyweightFactory::class);
74
+ $ this ->theme = $ this ->getMockForAbstractClass (ThemeInterface::class);
75
+
52
76
$ this ->model = $ objectManager ->getObject (
53
77
ParamsBuilder::class,
54
78
[
55
79
'scopeConfig ' => $ this ->scopeConfig ,
56
80
'viewConfig ' => $ this ->viewConfig ,
81
+ 'design ' => $ this ->design ,
82
+ 'themeFactory ' => $ this ->themeFactory
57
83
]
58
84
);
59
85
$ this ->scopeConfigData = [];
@@ -69,13 +95,21 @@ function ($path, $scopeType, $scopeCode) {
69
95
* Test build() with different parameters and config values
70
96
*
71
97
* @param int $scopeId
98
+ * @param string $themeId
99
+ * @param bool $keepFrame
72
100
* @param array $config
73
101
* @param array $imageArguments
74
102
* @param array $expected
75
103
* @dataProvider buildDataProvider
76
104
*/
77
- public function testBuild (int $ scopeId , array $ config , array $ imageArguments , array $ expected )
78
- {
105
+ public function testBuild (
106
+ int $ scopeId ,
107
+ string $ themeId ,
108
+ bool $ keepFrame ,
109
+ array $ config ,
110
+ array $ imageArguments ,
111
+ array $ expected
112
+ ) {
79
113
$ this ->scopeConfigData [Image::XML_PATH_JPEG_QUALITY ][ScopeConfigInterface::SCOPE_TYPE_DEFAULT ][null ] = 80 ;
80
114
foreach ($ config as $ path => $ value ) {
81
115
$ this ->scopeConfigData [$ path ][ScopeInterface::SCOPE_STORE ][$ scopeId ] = $ value ;
@@ -88,15 +122,23 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
88
122
'background ' => [110 , 64 , 224 ]
89
123
];
90
124
125
+ $ this ->design ->expects ($ this ->once ())
126
+ ->method ('getConfigurationDesignTheme ' )
127
+ ->willReturn ($ themeId );
128
+ $ this ->themeFactory ->expects ($ this ->once ())
129
+ ->method ('create ' )
130
+ ->with ($ themeId )
131
+ ->willReturn ($ this ->theme );
132
+
91
133
$ viewMock = $ this ->createMock (View::class);
92
134
$ viewMock ->expects ($ this ->once ())
93
135
->method ('getVarValue ' )
94
136
->with ('Magento_Catalog ' , 'product_image_white_borders ' )
95
- ->willReturn (true );
137
+ ->willReturn ($ keepFrame );
96
138
97
139
$ this ->viewConfig ->expects ($ this ->once ())
98
140
->method ('getViewConfig ' )
99
- ->with (['area ' => Area::AREA_FRONTEND ])
141
+ ->with (['area ' => Area::AREA_FRONTEND , ' themeModel ' => $ this -> theme ])
100
142
->willReturn ($ viewMock );
101
143
102
144
$ actual = $ this ->model ->build ($ imageArguments , $ scopeId );
@@ -106,7 +148,6 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
106
148
'angle ' => $ imageArguments ['angle ' ],
107
149
'quality ' => 80 ,
108
150
'keep_aspect_ratio ' => true ,
109
- 'keep_frame ' => true ,
110
151
'keep_transparency ' => true ,
111
152
'constrain_only ' => true ,
112
153
'image_height ' => $ imageArguments ['height ' ],
@@ -129,6 +170,8 @@ public function buildDataProvider()
129
170
return [
130
171
'watermark config ' => [
131
172
1 ,
173
+ '1 ' ,
174
+ true ,
132
175
[
133
176
'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
134
177
'design/watermark/small_image_size ' => '60x40 ' ,
@@ -144,10 +187,32 @@ public function buildDataProvider()
144
187
'watermark_position ' => 'bottom-right ' ,
145
188
'watermark_width ' => '60 ' ,
146
189
'watermark_height ' => '40 ' ,
190
+ 'keep_frame ' => true
147
191
]
148
192
],
149
193
'watermark config empty ' => [
150
194
1 ,
195
+ '1 ' ,
196
+ true ,
197
+ [
198
+ 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
199
+ ],
200
+ [
201
+ 'type ' => 'small_image '
202
+ ],
203
+ [
204
+ 'watermark_file ' => 'stores/1/magento-logo.png ' ,
205
+ 'watermark_image_opacity ' => null ,
206
+ 'watermark_position ' => null ,
207
+ 'watermark_width ' => null ,
208
+ 'watermark_height ' => null ,
209
+ 'keep_frame ' => true
210
+ ]
211
+ ],
212
+ 'watermark empty with no border ' => [
213
+ 2 ,
214
+ '2 ' ,
215
+ false ,
151
216
[
152
217
'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
153
218
],
@@ -160,6 +225,7 @@ public function buildDataProvider()
160
225
'watermark_position ' => null ,
161
226
'watermark_width ' => null ,
162
227
'watermark_height ' => null ,
228
+ 'keep_frame ' => false
163
229
]
164
230
]
165
231
];
0 commit comments