@@ -83,6 +83,11 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
83
83
*/
84
84
protected $ _objectHelper ;
85
85
86
+ /**
87
+ * @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
88
+ */
89
+ protected $ extensionAttributesJoinProcessorMock ;
90
+
86
91
/**
87
92
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
88
93
*/
@@ -169,6 +174,14 @@ protected function setUp()
169
174
'' ,
170
175
false
171
176
);
177
+ $ this ->extensionAttributesJoinProcessorMock = $ this ->getMock (
178
+ 'Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface ' ,
179
+ [],
180
+ [],
181
+ '' ,
182
+ false
183
+ );
184
+
172
185
$ this ->_model = $ this ->_objectHelper ->getObject (
173
186
'Magento\ConfigurableProduct\Model\Product\Type\Configurable ' ,
174
187
[
@@ -186,7 +199,8 @@ protected function setUp()
186
199
'filesystem ' => $ filesystem ,
187
200
'coreRegistry ' => $ coreRegistry ,
188
201
'logger ' => $ logger ,
189
- 'stockConfiguration ' => $ this ->_stockConfiguration
202
+ 'stockConfiguration ' => $ this ->_stockConfiguration ,
203
+ 'extensionAttributesJoinProcessor ' => $ this ->extensionAttributesJoinProcessorMock
190
204
]
191
205
);
192
206
}
@@ -202,9 +216,20 @@ public function testHasWeightTrue()
202
216
public function testSave ()
203
217
{
204
218
$ product = $ this ->getMockBuilder ('\Magento\Catalog\Model\Product ' )
205
- ->setMethods (['getIsDuplicate ' , 'dataHasChangedFor ' , 'getConfigurableAttributesData ' , 'getStoreId ' ,
206
- 'getId ' , 'getData ' , 'hasData ' , 'getAssociatedProductIds ' , '__wakeup ' , '__sleep ' ,
207
- ])->disableOriginalConstructor ()
219
+ ->setMethods (
220
+ [
221
+ 'getIsDuplicate ' ,
222
+ 'dataHasChangedFor ' ,
223
+ 'getConfigurableAttributesData ' ,
224
+ 'getStoreId ' ,
225
+ 'getId ' ,
226
+ 'getData ' ,
227
+ 'hasData ' ,
228
+ 'getAssociatedProductIds ' ,
229
+ '__wakeup ' ,
230
+ '__sleep ' ,
231
+ ]
232
+ )->disableOriginalConstructor ()
208
233
->getMock ();
209
234
$ product ->expects ($ this ->any ())->method ('dataHasChangedFor ' )->will ($ this ->returnValue ('false ' ));
210
235
$ product ->expects ($ this ->any ())->method ('getConfigurableAttributesData ' )
@@ -297,28 +322,48 @@ public function testGetUsedProducts()
297
322
$ this ->_attributeCollectionFactory ->expects ($ this ->any ())->method ('create ' )
298
323
->will ($ this ->returnValue ($ attributeCollection ));
299
324
$ product = $ this ->getMockBuilder ('\Magento\Catalog\Model\Product ' )
300
- ->setMethods (['dataHasChangedFor ' , 'getConfigurableAttributesData ' , 'getStoreId ' ,
301
- 'getId ' , 'getData ' , 'hasData ' , 'getAssociatedProductIds ' , '__wakeup ' , '__sleep ' ,
302
- ])->disableOriginalConstructor ()
325
+ ->setMethods (
326
+ [
327
+ 'dataHasChangedFor ' ,
328
+ 'getConfigurableAttributesData ' ,
329
+ 'getStoreId ' ,
330
+ 'getId ' ,
331
+ 'getData ' ,
332
+ 'hasData ' ,
333
+ 'getAssociatedProductIds ' ,
334
+ '__wakeup ' ,
335
+ '__sleep ' ,
336
+ ]
337
+ )->disableOriginalConstructor ()
303
338
->getMock ();
304
339
$ product ->expects ($ this ->any ())->method ('getConfigurableAttributesData ' )
305
340
->will ($ this ->returnValue ($ this ->attributeData ));
306
341
$ product ->expects ($ this ->any ())->method ('getStoreId ' )->will ($ this ->returnValue (5 ));
307
342
$ product ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (1 ));
308
343
$ product ->expects ($ this ->any ())->method ('getAssociatedProductIds ' )->will ($ this ->returnValue ([2 ]));
309
344
$ product ->expects ($ this ->any ())->method ('hasData ' )
310
- ->will ($ this ->returnValueMap ([
311
- ['_cache_instance_used_product_attribute_ids ' , 1 ],
312
- ['_cache_instance_products ' , 0 ],
313
- ['_cache_instance_configurable_attributes ' , 1 ],
314
- ]));
345
+ ->will (
346
+ $ this ->returnValueMap (
347
+ [
348
+ ['_cache_instance_used_product_attribute_ids ' , 1 ],
349
+ ['_cache_instance_products ' , 0 ],
350
+ ['_cache_instance_configurable_attributes ' , 1 ],
351
+ ]
352
+ )
353
+ );
315
354
$ product ->expects ($ this ->any ())->method ('getData ' )
316
355
->will ($ this ->returnValue (1 ));
317
356
$ productCollection = $ this ->getMockBuilder (
318
357
'Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Product\Collection '
319
358
)->setMethods (
320
- ['setFlag ' , 'setProductFilter ' , 'addStoreFilter ' , 'addAttributeToSelect ' , 'addFilterByRequiredOptions ' ,
321
- 'setStoreId ' , ]
359
+ [
360
+ 'setFlag ' ,
361
+ 'setProductFilter ' ,
362
+ 'addStoreFilter ' ,
363
+ 'addAttributeToSelect ' ,
364
+ 'addFilterByRequiredOptions ' ,
365
+ 'setStoreId ' ,
366
+ ]
322
367
)->disableOriginalConstructor ()
323
368
->getMock ();
324
369
$ productCollection ->expects ($ this ->any ())->method ('addAttributeToSelect ' )->will ($ this ->returnSelf ());
@@ -385,13 +430,21 @@ public function testGetConfigurableAttributesAsArray($productStore, $attributeSt
385
430
->getMock ();
386
431
$ product ->expects ($ this ->any ())->method ('getStoreId ' )->will ($ this ->returnValue ($ productStore ));
387
432
$ product ->expects ($ this ->any ())->method ('hasData ' )
388
- ->will ($ this ->returnValueMap ([
389
- ['_cache_instance_configurable_attributes ' , 1 ],
390
- ]));
433
+ ->will (
434
+ $ this ->returnValueMap (
435
+ [
436
+ ['_cache_instance_configurable_attributes ' , 1 ],
437
+ ]
438
+ )
439
+ );
391
440
$ product ->expects ($ this ->any ())->method ('getData ' )
392
- ->will ($ this ->returnValueMap ([
393
- ['_cache_instance_configurable_attributes ' , null , [$ attribute ]],
394
- ]));
441
+ ->will (
442
+ $ this ->returnValueMap (
443
+ [
444
+ ['_cache_instance_configurable_attributes ' , null , [$ attribute ]],
445
+ ]
446
+ )
447
+ );
395
448
396
449
$ result = $ this ->_model ->getConfigurableAttributesAsArray ($ product );
397
450
$ this ->assertCount (1 , $ result );
@@ -408,6 +461,41 @@ public function getConfigurableAttributesAsArrayDataProvider()
408
461
];
409
462
}
410
463
464
+ public function testGetConfigurableAttributes ()
465
+ {
466
+ $ expectedData = [1 ];
467
+ $ configurableAttributes = '_cache_instance_configurable_attributes ' ;
468
+
469
+ /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */
470
+ $ product = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
471
+ ->setMethods (['getData ' , 'hasData ' , 'setData ' ])
472
+ ->disableOriginalConstructor ()
473
+ ->getMock ();
474
+ $ product ->expects ($ this ->once ())->method ('hasData ' )->with ($ configurableAttributes )->willReturn (false );
475
+ $ product ->expects ($ this ->once ())->method ('setData ' )->willReturnSelf ();
476
+ $ product ->expects ($ this ->once ())->method ('getData ' )->with ($ configurableAttributes )->willReturn ($ expectedData );
477
+
478
+ $ attributeCollection = $ this ->getMockBuilder (
479
+ 'Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Attribute\Collection '
480
+ )
481
+ ->setMethods (['setProductFilter ' , 'orderByPosition ' , 'load ' ])
482
+ ->disableOriginalConstructor ()
483
+ ->getMock ();
484
+ $ attributeCollection ->expects ($ this ->any ())->method ('setProductFilter ' )->will ($ this ->returnSelf ());
485
+ $ attributeCollection ->expects ($ this ->any ())->method ('orderByPosition ' )->will ($ this ->returnSelf ());
486
+ $ this ->_attributeCollectionFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ attributeCollection );
487
+
488
+ $ this ->extensionAttributesJoinProcessorMock ->expects ($ this ->once ())
489
+ ->method ('process ' )
490
+ ->with (
491
+ $ this ->isInstanceOf (
492
+ 'Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Attribute\Collection '
493
+ )
494
+ );
495
+
496
+ $ this ->assertEquals ($ expectedData , $ this ->_model ->getConfigurableAttributes ($ product ));
497
+ }
498
+
411
499
public function testResetConfigurableAttributes ()
412
500
{
413
501
$ product = $ this ->getMockBuilder ('\Magento\Catalog\Model\Product ' )
0 commit comments