|
27 | 27 | * @SuppressWarnings(PHPMD.LongVariable)
|
28 | 28 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
29 | 29 | * @SuppressWarnings(PHPMD.TooManyFields)
|
| 30 | + * @codingStandardsIgnoreFile |
30 | 31 | */
|
31 | 32 | class ConfigurableTest extends \PHPUnit\Framework\TestCase
|
32 | 33 | {
|
@@ -154,8 +155,7 @@ protected function setUp()
|
154 | 155 | ->setMethods(['create'])
|
155 | 156 | ->getMock();
|
156 | 157 | $this->productCollectionFactory = $this->getMockBuilder(
|
157 |
| - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory::class |
158 |
| - ) |
| 158 | + \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory::class) |
159 | 159 | ->disableOriginalConstructor()
|
160 | 160 | ->setMethods(['create'])
|
161 | 161 | ->getMock();
|
@@ -197,11 +197,6 @@ protected function setUp()
|
197 | 197 | ->disableOriginalConstructor()
|
198 | 198 | ->getMock();
|
199 | 199 |
|
200 |
| - $this->productFactory = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterfaceFactory::class) |
201 |
| - ->setMethods(['create']) |
202 |
| - ->disableOriginalConstructor() |
203 |
| - ->getMock(); |
204 |
| - |
205 | 200 | $this->salableProcessor = $this->createMock(SalableProcessor::class);
|
206 | 201 |
|
207 | 202 | $this->model = $this->objectHelper->getObject(
|
@@ -287,8 +282,7 @@ public function testSave()
|
287 | 282 | ->method('getData')
|
288 | 283 | ->willReturnMap($dataMap);
|
289 | 284 | $attribute = $this->getMockBuilder(
|
290 |
| - \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class |
291 |
| - ) |
| 285 | + \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class) |
292 | 286 | ->disableOriginalConstructor()
|
293 | 287 | ->setMethods(['addData', 'setStoreId', 'setProductId', 'save', '__wakeup', '__sleep'])
|
294 | 288 | ->getMock();
|
@@ -385,7 +379,7 @@ public function testGetUsedProducts()
|
385 | 379 | ['_cache_instance_used_product_attributes', null, []]
|
386 | 380 | ]
|
387 | 381 | );
|
388 |
| - |
| 382 | + $this->catalogConfig->expects($this->any())->method('getProductAttributes')->willReturn([]); |
389 | 383 | $productCollection->expects($this->atLeastOnce())->method('addAttributeToSelect')->willReturnSelf();
|
390 | 384 | $productCollection->expects($this->once())->method('setProductFilter')->willReturnSelf();
|
391 | 385 | $productCollection->expects($this->atLeastOnce())->method('setFlag')->willReturnSelf();
|
@@ -471,8 +465,7 @@ public function testGetConfigurableAttributesAsArray($productStore)
|
471 | 465 | $eavAttribute->expects($this->atLeastOnce())->method('getStoreLabel')->willReturn('Store Label');
|
472 | 466 |
|
473 | 467 | $attribute = $this->getMockBuilder(
|
474 |
| - \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class |
475 |
| - ) |
| 468 | + \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class) |
476 | 469 | ->disableOriginalConstructor()
|
477 | 470 | ->setMethods(['getProductAttribute', '__wakeup', '__sleep'])
|
478 | 471 | ->getMock();
|
@@ -515,17 +508,34 @@ public function getConfigurableAttributesAsArrayDataProvider()
|
515 | 508 | ];
|
516 | 509 | }
|
517 | 510 |
|
518 |
| - public function testGetConfigurableAttributes() |
| 511 | + public function testGetConfigurableAttributesNewProduct() |
519 | 512 | {
|
520 | 513 | $configurableAttributes = '_cache_instance_configurable_attributes';
|
521 | 514 |
|
522 | 515 | /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */
|
523 | 516 | $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
|
524 |
| - ->setMethods(['getData', 'hasData', 'setData']) |
| 517 | + ->setMethods(['hasData', 'getId']) |
525 | 518 | ->disableOriginalConstructor()
|
526 | 519 | ->getMock();
|
527 | 520 |
|
528 | 521 | $product->expects($this->once())->method('hasData')->with($configurableAttributes)->willReturn(false);
|
| 522 | + $product->expects($this->once())->method('getId')->willReturn(null); |
| 523 | + |
| 524 | + $this->assertEquals([], $this->model->getConfigurableAttributes($product)); |
| 525 | + } |
| 526 | + |
| 527 | + public function testGetConfigurableAttributes() |
| 528 | + { |
| 529 | + $configurableAttributes = '_cache_instance_configurable_attributes'; |
| 530 | + |
| 531 | + /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ |
| 532 | + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) |
| 533 | + ->setMethods(['getData', 'hasData', 'setData', 'getId']) |
| 534 | + ->disableOriginalConstructor() |
| 535 | + ->getMock(); |
| 536 | + |
| 537 | + $product->expects($this->once())->method('hasData')->with($configurableAttributes)->willReturn(false); |
| 538 | + $product->expects($this->once())->method('getId')->willReturn(1); |
529 | 539 |
|
530 | 540 | $attributeCollection = $this->getMockBuilder(Collection::class)
|
531 | 541 | ->setMethods(['setProductFilter', 'orderByPosition', 'load'])
|
@@ -582,8 +592,7 @@ public function testHasOptionsConfigurableAttribute()
|
582 | 592 | ->disableOriginalConstructor()
|
583 | 593 | ->getMock();
|
584 | 594 | $attributeMock = $this->getMockBuilder(
|
585 |
| - \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class |
586 |
| - ) |
| 595 | + \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class) |
587 | 596 | ->disableOriginalConstructor()
|
588 | 597 | ->getMock();
|
589 | 598 |
|
|
0 commit comments