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,21 @@ class ParamsBuilderTest extends TestCase
4144 */
4245 private $ scopeConfigData = [];
4346
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+
4462 /**
4563 * @inheritDoc
4664 */
@@ -49,11 +67,19 @@ protected function setUp(): void
4967 $ objectManager = new ObjectManager ($ this );
5068 $ this ->scopeConfig = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
5169 $ 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+
5276 $ this ->model = $ objectManager ->getObject (
5377 ParamsBuilder::class,
5478 [
5579 'scopeConfig ' => $ this ->scopeConfig ,
5680 'viewConfig ' => $ this ->viewConfig ,
81+ 'design ' => $ this ->design ,
82+ 'themeFactory ' => $ this ->themeFactory
5783 ]
5884 );
5985 $ this ->scopeConfigData = [];
@@ -69,13 +95,21 @@ function ($path, $scopeType, $scopeCode) {
6995 * Test build() with different parameters and config values
7096 *
7197 * @param int $scopeId
98+ * @param string $themeId
99+ * @param bool $keepFrame
72100 * @param array $config
73101 * @param array $imageArguments
74102 * @param array $expected
75103 * @dataProvider buildDataProvider
76104 */
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+ ) {
79113 $ this ->scopeConfigData [Image::XML_PATH_JPEG_QUALITY ][ScopeConfigInterface::SCOPE_TYPE_DEFAULT ][null ] = 80 ;
80114 foreach ($ config as $ path => $ value ) {
81115 $ this ->scopeConfigData [$ path ][ScopeInterface::SCOPE_STORE ][$ scopeId ] = $ value ;
@@ -88,15 +122,23 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
88122 'background ' => [110 , 64 , 224 ]
89123 ];
90124
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+
91133 $ viewMock = $ this ->createMock (View::class);
92134 $ viewMock ->expects ($ this ->once ())
93135 ->method ('getVarValue ' )
94136 ->with ('Magento_Catalog ' , 'product_image_white_borders ' )
95- ->willReturn (true );
137+ ->willReturn ($ keepFrame );
96138
97139 $ this ->viewConfig ->expects ($ this ->once ())
98140 ->method ('getViewConfig ' )
99- ->with (['area ' => Area::AREA_FRONTEND ])
141+ ->with (['area ' => Area::AREA_FRONTEND , ' themeModel ' => $ this -> theme ])
100142 ->willReturn ($ viewMock );
101143
102144 $ actual = $ this ->model ->build ($ imageArguments , $ scopeId );
@@ -106,7 +148,6 @@ public function testBuild(int $scopeId, array $config, array $imageArguments, ar
106148 'angle ' => $ imageArguments ['angle ' ],
107149 'quality ' => 80 ,
108150 'keep_aspect_ratio ' => true ,
109- 'keep_frame ' => true ,
110151 'keep_transparency ' => true ,
111152 'constrain_only ' => true ,
112153 'image_height ' => $ imageArguments ['height ' ],
@@ -129,6 +170,8 @@ public function buildDataProvider()
129170 return [
130171 'watermark config ' => [
131172 1 ,
173+ '1 ' ,
174+ true ,
132175 [
133176 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
134177 'design/watermark/small_image_size ' => '60x40 ' ,
@@ -144,10 +187,32 @@ public function buildDataProvider()
144187 'watermark_position ' => 'bottom-right ' ,
145188 'watermark_width ' => '60 ' ,
146189 'watermark_height ' => '40 ' ,
190+ 'keep_frame ' => true
147191 ]
148192 ],
149193 'watermark config empty ' => [
150194 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 ,
151216 [
152217 'design/watermark/small_image_image ' => 'stores/1/magento-logo.png ' ,
153218 ],
@@ -160,6 +225,7 @@ public function buildDataProvider()
160225 'watermark_position ' => null ,
161226 'watermark_width ' => null ,
162227 'watermark_height ' => null ,
228+ 'keep_frame ' => false
163229 ]
164230 ]
165231 ];
0 commit comments