1414use Magento \Framework \Config \View ;
1515use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1616use 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 ;
1720use Magento \Store \Model \ScopeInterface ;
1821use PHPUnit \Framework \TestCase ;
1922
@@ -41,6 +44,12 @@ class ParamsBuilderTest extends TestCase
4144 */
4245 private $ scopeConfigData = [];
4346
47+ private $ design ;
48+
49+ private $ themeFactory ;
50+
51+ private $ theme ;
52+
4453 /**
4554 * @inheritDoc
4655 */
@@ -49,11 +58,19 @@ protected function setUp(): void
4958 $ objectManager = new ObjectManager ($ this );
5059 $ this ->scopeConfig = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
5160 $ 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+
5267 $ this ->model = $ objectManager ->getObject (
5368 ParamsBuilder::class,
5469 [
5570 'scopeConfig ' => $ this ->scopeConfig ,
5671 'viewConfig ' => $ this ->viewConfig ,
72+ 'design ' => $ this ->design ,
73+ 'themeFactory ' => $ this ->themeFactory
5774 ]
5875 );
5976 $ this ->scopeConfigData = [];
@@ -69,13 +86,21 @@ function ($path, $scopeType, $scopeCode) {
6986 * Test build() with different parameters and config values
7087 *
7188 * @param int $scopeId
89+ * @param string $themeId
90+ * @param bool $keepFrame
7291 * @param array $config
7392 * @param array $imageArguments
7493 * @param array $expected
7594 * @dataProvider buildDataProvider
7695 */
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+ ) {
79104 $ this ->scopeConfigData [Image::XML_PATH_JPEG_QUALITY ][ScopeConfigInterface::SCOPE_TYPE_DEFAULT ][null ] = 80 ;
80105 foreach ($ config as $ path => $ value ) {
81106 $ this ->scopeConfigData [$ path ][ScopeInterface::SCOPE_STORE ][$ scopeId ] = $ value ;
@@ -88,15 +113,23 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
88113 'background ' => [110 , 64 , 224 ]
89114 ];
90115
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+
91124 $ viewMock = $ this ->createMock (View::class);
92125 $ viewMock ->expects ($ this ->once ())
93126 ->method ('getVarValue ' )
94127 ->with ('Magento_Catalog ' , 'product_image_white_borders ' )
95- ->willReturn (true );
128+ ->willReturn ($ keepFrame );
96129
97130 $ this ->viewConfig ->expects ($ this ->once ())
98131 ->method ('getViewConfig ' )
99- ->with (['area ' => Area::AREA_FRONTEND ])
132+ ->with (['area ' => Area::AREA_FRONTEND , ' themeModel ' => $ this -> theme ])
100133 ->willReturn ($ viewMock );
101134
102135 $ actual = $ this ->model ->build ($ imageArguments , $ scopeId );
@@ -106,7 +139,6 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
106139 'angle ' => $ imageArguments ['angle ' ],
107140 'quality ' => 80 ,
108141 'keep_aspect_ratio ' => true ,
109- 'keep_frame ' => true ,
110142 'keep_transparency ' => true ,
111143 'constrain_only ' => true ,
112144 'image_height ' => $ imageArguments ['height ' ],
@@ -129,6 +161,8 @@ public function buildDataProvider()
129161 return [
130162 'watermark config ' => [
131163 1 ,
164+ '1 ' ,
165+ true ,
132166 [
133167 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
134168 'design/watermark/small_image_size ' => '60x40 ' ,
@@ -144,10 +178,32 @@ public function buildDataProvider()
144178 'watermark_position ' => 'bottom-right ' ,
145179 'watermark_width ' => '60 ' ,
146180 'watermark_height ' => '40 ' ,
181+ 'keep_frame ' => true
147182 ]
148183 ],
149184 'watermark config empty ' => [
150185 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 ,
151207 [
152208 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
153209 ],
@@ -160,6 +216,7 @@ public function buildDataProvider()
160216 'watermark_position ' => null ,
161217 'watermark_width ' => null ,
162218 'watermark_height ' => null ,
219+ 'keep_frame ' => false
163220 ]
164221 ]
165222 ];
0 commit comments