Skip to content

Commit 3b22449

Browse files
committed
Add integration tests for frontend product and identities extender plugins.
1 parent c0d6730 commit 3b22449

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Bundle\Model\Plugin\Frontend;
10+
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Interception\PluginList;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test bundle fronted product plugin adds children products ids to bundle product identities.
18+
*/
19+
class ProductTest extends TestCase
20+
{
21+
/**
22+
* Check, product plugin is registered for storefront.
23+
*
24+
* @magentoAppArea frontend
25+
* @return void
26+
*/
27+
public function testProductIsRegistered(): void
28+
{
29+
$pluginInfo = Bootstrap::getObjectManager()->get(PluginList::class)
30+
->get(\Magento\Catalog\Model\Product::class, []);
31+
$this->assertSame(Product::class, $pluginInfo['bundle']['instance']);
32+
}
33+
34+
/**
35+
* Check plugin will add children ids to bundle product identities on storefront.
36+
*
37+
* @magentoDataFixture Magento/Bundle/_files/product.php
38+
* @magentoAppArea frontend
39+
* @return void
40+
*/
41+
public function testGetIdentitiesForBundleProductOnStorefront(): void
42+
{
43+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
44+
$bundleProduct = $productRepository->get('bundle-product');
45+
$simpleProduct = $productRepository->get('simple');
46+
$expectedIdentities = [
47+
'cat_p_' . $bundleProduct->getId(),
48+
'cat_p',
49+
'cat_p_' . $simpleProduct->getId(),
50+
51+
];
52+
$this->assertEquals($expectedIdentities, $bundleProduct->getIdentities());
53+
}
54+
55+
/**
56+
* Check plugin won't add children ids to bundle product identities in admin area.
57+
*
58+
* @magentoDataFixture Magento/Bundle/_files/product.php
59+
* @magentoAppArea adminhtml
60+
* @return void
61+
*/
62+
public function testGetIdentitiesForBundleProductInAdminArea(): void
63+
{
64+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
65+
$bundleProduct = $productRepository->get('bundle-product');
66+
$expectedIdentities = [
67+
'cat_p_' . $bundleProduct->getId(),
68+
];
69+
$this->assertEquals($expectedIdentities, $bundleProduct->getIdentities());
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\ConfigurableProduct\Model\Plugin\Frontend;
10+
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Interception\PluginList;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test configurable fronted product plugin will add children products ids to configurable product identities.
18+
*/
19+
class ProductIdentitiesExtenderTest extends TestCase
20+
{
21+
/**
22+
* Check, product identities extender plugin is registered for storefront.
23+
*
24+
* @magentoAppArea frontend
25+
* @return void
26+
*/
27+
public function testIdentitiesExtenderIsRegistered(): void
28+
{
29+
$pluginInfo = Bootstrap::getObjectManager()->get(PluginList::class)
30+
->get(\Magento\Catalog\Model\Product::class, []);
31+
$this->assertSame(ProductIdentitiesExtender::class, $pluginInfo['product_identities_extender']['instance']);
32+
}
33+
34+
/**
35+
* Check plugin will add children ids to configurable product identities on storefront.
36+
*
37+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
38+
* @magentoAppArea frontend
39+
* @return void
40+
*/
41+
public function testGetIdentitiesForConfigurableProductOnStorefront(): void
42+
{
43+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
44+
$configurableProduct = $productRepository->get('configurable');
45+
$simpleProduct1 = $productRepository->get('simple_10');
46+
$simpleProduct2 = $productRepository->get('simple_20');
47+
$expectedIdentities = [
48+
'cat_p_' . $configurableProduct->getId(),
49+
'cat_p',
50+
'cat_p_' . $simpleProduct1->getId(),
51+
'cat_p_' . $simpleProduct2->getId(),
52+
53+
];
54+
$this->assertEquals($expectedIdentities, $configurableProduct->getIdentities());
55+
}
56+
57+
/**
58+
* Check plugin won't add children ids to configurable product identities in admin area.
59+
*
60+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
61+
* @magentoAppArea adminhtml
62+
* @return void
63+
*/
64+
public function testGetIdentitiesForConfigurableProductInAdminArea(): void
65+
{
66+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
67+
$configurableProduct = $productRepository->get('configurable');
68+
$expectedIdentities = [
69+
'cat_p_' . $configurableProduct->getId(),
70+
];
71+
$this->assertEquals($expectedIdentities, $configurableProduct->getIdentities());
72+
}
73+
}

0 commit comments

Comments
 (0)