Skip to content

Commit 754742e

Browse files
committed
MAGETWO-83204: "Hide from Product Page" option does not work for child of configurable product
1 parent bc35941 commit 754742e

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin;
7+
8+
use Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender;
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product;
12+
13+
/**
14+
* Class ProductIdentitiesExtenderTest
15+
*/
16+
class ProductIdentitiesExtenderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject|Configurable
20+
*/
21+
private $configurableTypeMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject|ProductRepositoryInterface
25+
*/
26+
private $productRepositoryMock;
27+
28+
/**
29+
* @var ProductIdentitiesExtender
30+
*/
31+
private $plugin;
32+
33+
protected function setUp()
34+
{
35+
$this->configurableTypeMock = $this->getMockBuilder(Configurable::class)
36+
->disableOriginalConstructor()
37+
->getMock();
38+
$this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
39+
->getMock();
40+
41+
$this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock);
42+
}
43+
44+
public function testAroundGetIdentities()
45+
{
46+
$productIdentity = 'cache_tag_1';
47+
$productMock = $this->getMockBuilder(Product::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
$proceed = function () use ($productIdentity) {
51+
return [$productIdentity];
52+
};
53+
54+
$productId = 1;
55+
$parentProductId = 2;
56+
$parentProductIdentity = 'cache_tag_2';
57+
$productMock->expects($this->once())
58+
->method('getId')
59+
->willReturn($productId);
60+
$this->configurableTypeMock->expects($this->once())
61+
->method('getParentIdsByChild')
62+
->with($productId)
63+
->willReturn([$parentProductId]);
64+
$parentProductMock = $this->getMockBuilder(Product::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$this->productRepositoryMock->expects($this->once())
68+
->method('getById')
69+
->with($parentProductId)
70+
->willReturn($parentProductMock);
71+
$parentProductMock->expects($this->once())
72+
->method('getIdentities')
73+
->willReturn([$parentProductIdentity]);
74+
75+
$productIdentities = $this->plugin->aroundGetIdentities($productMock, $proceed);
76+
$this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities);
77+
}
78+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Model;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
11+
class ProductTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
15+
*/
16+
public function testGetIdentities()
17+
{
18+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
19+
$confProduct = $productRepository->get('configurable');
20+
$simple10Product = $productRepository->get('simple_10');
21+
$simple20Product = $productRepository->get('simple_20');
22+
23+
$this->assertEmpty(array_diff($confProduct->getIdentities(), $simple10Product->getIdentities()));
24+
$this->assertEmpty(array_diff($confProduct->getIdentities(), $simple20Product->getIdentities()));
25+
}
26+
}

0 commit comments

Comments
 (0)