|
| 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