Skip to content

Commit 1dc7081

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'MC-29755-2' of https://github.com/magento-tango/magento2ce into MC-29755-2.4.1
� Conflicts: � app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/Frontend/ProductIdentitiesExtenderTest.php
2 parents 9fa16c7 + 520590a commit 1dc7081

File tree

5 files changed

+27
-205
lines changed

5 files changed

+27
-205
lines changed

app/code/Magento/ConfigurableProduct/Model/Plugin/Frontend/ProductIdentitiesExtender.php

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +0,0 @@
1-
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
declare(strict_types=1);
7-
8-
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin\Frontend;
9-
10-
use Magento\Catalog\Model\Product;
11-
use Magento\ConfigurableProduct\Model\Plugin\Frontend\ProductIdentitiesExtender;
12-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
13-
use PHPUnit\Framework\TestCase;
14-
15-
class ProductIdentitiesExtenderTest extends TestCase
16-
{
17-
/**
18-
* @var \PHPUnit\Framework\MockObject\MockObject|Configurable
19-
*/
20-
private $configurableTypeMock;
21-
22-
/**
23-
* @var ProductIdentitiesExtender
24-
*/
25-
private $plugin;
26-
27-
/** @var MockObject|Product */
28-
private $product;
29-
30-
protected function setUp(): void
31-
{
32-
$this->product = $this->getMockBuilder(Product::class)
33-
->disableOriginalConstructor()
34-
->setMethods(['getId'])
35-
->getMock();
36-
37-
$this->configurableTypeMock = $this->getMockBuilder(Configurable::class)
38-
->disableOriginalConstructor()
39-
->getMock();
40-
41-
$this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock);
42-
}
43-
44-
public function testAfterGetIdentities()
45-
{
46-
$identities = [
47-
'SomeCacheId',
48-
'AnotherCacheId',
49-
];
50-
$productId = 12345;
51-
$childIdentities = [
52-
0 => [1, 2, 5, 100500]
53-
];
54-
$expectedIdentities = [
55-
'SomeCacheId',
56-
'AnotherCacheId',
57-
Product::CACHE_TAG . '_' . 1,
58-
Product::CACHE_TAG . '_' . 2,
59-
Product::CACHE_TAG . '_' . 5,
60-
Product::CACHE_TAG . '_' . 100500,
61-
];
62-
63-
$this->product->expects($this->once())
64-
->method('getId')
65-
->willReturn($productId);
66-
67-
$this->configurableTypeMock->expects($this->once())
68-
->method('getChildrenIds')
69-
->with($productId)
70-
->willReturn($childIdentities);
71-
72-
$productIdentities = $this->plugin->afterGetIdentities($this->product, $identities);
73-
$this->assertEquals($expectedIdentities, $productIdentities);
74-
}
75-
}

app/code/Magento/ConfigurableProduct/etc/frontend/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
1111
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder" type="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder"/>
1212
</type>
13-
<type name="Magento\Catalog\Model\Product">
14-
<plugin name="product_identities_extender" type="Magento\ConfigurableProduct\Model\Plugin\Frontend\ProductIdentitiesExtender" />
15-
</type>
1613
<type name="Magento\ConfigurableProduct\Model\Product\Type\Configurable">
1714
<plugin name="used_products_cache" type="Magento\ConfigurableProduct\Model\Plugin\Frontend\UsedProductsCache" />
1815
</type>

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Plugin/Frontend/ProductIdentitiesExtenderTest.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ProductTest.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,37 @@
1313
class ProductTest extends \PHPUnit\Framework\TestCase
1414
{
1515
/**
16+
* Check that no children identities are added to the parent product in frontend area
17+
*
1618
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
19+
* @magentoAppArea frontend
20+
* @return void
1721
*/
18-
public function testGetIdentities()
22+
public function testGetIdentitiesForConfigurableProductOnStorefront(): void
1923
{
2024
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
21-
$confProduct = $productRepository->get('configurable');
22-
$simple10Product = $productRepository->get('simple_10');
23-
$simple20Product = $productRepository->get('simple_20');
25+
$configurableProduct = $productRepository->get('configurable');
26+
$expectedIdentities = [
27+
'cat_p_' . $configurableProduct->getId(),
28+
'cat_p'
29+
];
30+
$this->assertEquals($expectedIdentities, $configurableProduct->getIdentities());
31+
}
2432

25-
$this->assertEmpty(array_diff($confProduct->getIdentities(), $simple10Product->getIdentities()));
26-
$this->assertEmpty(array_diff($confProduct->getIdentities(), $simple20Product->getIdentities()));
33+
/**
34+
* Check that no children identities are added to the parent product in frontend area
35+
*
36+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
37+
* @magentoAppArea adminhtml
38+
* @return void
39+
*/
40+
public function testGetIdentitiesForConfigurableProductInAdminArea(): void
41+
{
42+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
43+
$configurableProduct = $productRepository->get('configurable');
44+
$expectedIdentities = [
45+
'cat_p_' . $configurableProduct->getId(),
46+
];
47+
$this->assertEquals($expectedIdentities, $configurableProduct->getIdentities());
2748
}
2849
}

0 commit comments

Comments
 (0)