3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Test \Unit \Controller \Adminhtml \Product \Initialization \Helper ;
7
8
8
9
use Magento \Catalog \Controller \Adminhtml \Product \Initialization \Helper \AttributeFilter ;
@@ -44,15 +45,25 @@ public function testPrepareProductAttributes(
44
45
$ expectedProductData ,
45
46
$ initialProductData
46
47
) {
48
+ /** @var \PHPUnit_Framework_MockObject_MockObject | Product $productMockMap */
47
49
$ productMockMap = $ this ->getMockBuilder (Product::class)
48
50
->disableOriginalConstructor ()
49
- ->setMethods (['getData ' ])
51
+ ->setMethods (['getData ' , ' getAttributes ' ])
50
52
->getMock ();
51
53
52
54
if (!empty ($ initialProductData )) {
53
55
$ productMockMap ->expects ($ this ->any ())->method ('getData ' )->willReturnMap ($ initialProductData );
54
56
}
55
57
58
+ if ($ useDefaults ) {
59
+ $ productMockMap
60
+ ->expects ($ this ->once ())
61
+ ->method ('getAttributes ' )
62
+ ->willReturn (
63
+ $ this ->getProductAttributesMock ($ useDefaults )
64
+ );
65
+ }
66
+
56
67
$ actualProductData = $ this ->model ->prepareProductAttributes ($ productMockMap , $ requestProductData , $ useDefaults );
57
68
$ this ->assertEquals ($ expectedProductData , $ actualProductData );
58
69
}
@@ -169,7 +180,7 @@ public function setupInputDataProvider()
169
180
'description ' => 'descr modified '
170
181
],
171
182
'initialProductData ' => [
172
- ['name ' , null ,'testName2 ' ],
183
+ ['name ' , null , 'testName2 ' ],
173
184
['sku ' , null , 'testSku2 ' ],
174
185
['price ' , null , '101 ' ],
175
186
['description ' , null , 'descr text ' ]
@@ -180,7 +191,8 @@ public function setupInputDataProvider()
180
191
'name ' => 'testName3 ' ,
181
192
'sku ' => 'testSku3 ' ,
182
193
'price ' => '103 ' ,
183
- 'special_price ' => '100 '
194
+ 'special_price ' => '100 ' ,
195
+ 'description ' => 'descr modified ' ,
184
196
],
185
197
'useDefaults ' => [
186
198
'description ' => '1 '
@@ -190,14 +202,38 @@ public function setupInputDataProvider()
190
202
'sku ' => 'testSku3 ' ,
191
203
'price ' => '103 ' ,
192
204
'special_price ' => '100 ' ,
205
+ 'description ' => false
193
206
],
194
207
'initialProductData ' => [
195
- ['name ' , null ,'testName2 ' ],
208
+ ['name ' , null , 'testName2 ' ],
196
209
['sku ' , null , 'testSku2 ' ],
197
210
['price ' , null , '101 ' ],
198
211
['description ' , null , 'descr text ' ]
199
212
]
200
213
],
201
214
];
202
215
}
216
+
217
+ /**
218
+ * @param array $useDefaults
219
+ * @return array
220
+ */
221
+ private function getProductAttributesMock (array $ useDefaults ): array
222
+ {
223
+ $ returnArray = [];
224
+ foreach ($ useDefaults as $ attributecode => $ isDefault ) {
225
+ if ($ isDefault === '1 ' ) {
226
+ /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute | \PHPUnit_Framework_MockObject_MockObject $attribute */
227
+ $ attribute = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class)
228
+ ->disableOriginalConstructor ()
229
+ ->getMock ();
230
+ $ attribute ->expects ($ this ->any ())
231
+ ->method ('getBackendType ' )
232
+ ->willReturn ('varchar ' );
233
+
234
+ $ returnArray [$ attributecode ] = $ attribute ;
235
+ }
236
+ }
237
+ return $ returnArray ;
238
+ }
203
239
}
0 commit comments