This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,127 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Model\ResourceModel\Indexer;
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Indexer\Product\Price;
use Magento\Customer\Model\Group;
use Magento\Framework\Indexer\ActionInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\TestFramework\Catalog\Model\Product\Price\GetPriceIndexDataByProductId;
use Magento\CatalogInventory\Model\Indexer\Stock;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
class PriceTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var ActionInterface
*/
private $indexer;
/**
* @var GetPriceIndexDataByProductId
*/
private $getPriceIndexDataByProductId;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var WebsiteRepositoryInterface
*/
private $websiteRepository;
/**
* @var Stock
*/
private $stockIndexer;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->indexer = $this->objectManager->get(Price::class);
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->getPriceIndexDataByProductId = $this->objectManager->get(GetPriceIndexDataByProductId::class);
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
$this->stockIndexer = $this->objectManager->get(Stock::class);
}
/**
* Test get bundle index price if enabled show out off stock
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_dynamic_price.php
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
*
* @return void
*/
public function testExecuteRowWithShowOutOfStock(): void
{
$expectedPrices = [
'price' => 0,
'final_price' => 0,
'min_price' => 15.99,
'max_price' => 15.99,
'tier_price' => null
];
$product = $this->productRepository->get('simple1');
$product->setStockData(['qty' => 0]);
$this->productRepository->save($product);
$this->stockIndexer->executeRow($product->getId());
$bundleProduct = $this->productRepository->get('bundle_product_with_dynamic_price');
$this->indexer->executeRow($bundleProduct->getId());
$this->assertIndexTableData($bundleProduct->getId(), $expectedPrices);
}
#[
DataFixture(
BundleProductFixture::class,
['sku' => 'bundle1', 'extension_attributes' => ['website_ids' => []]]
),
]
public function testExecuteForBundleWithoutWebsites(): void
{
$bundleProduct = $this->productRepository->get('bundle1');
$this->indexer->executeRow($bundleProduct->getId());
}
/**
* Asserts price data in index table.
*
* @param int $productId
* @param array $expectedPrices
* @return void
*/
private function assertIndexTableData(int $productId, array $expectedPrices): void
{
$data = $this->getPriceIndexDataByProductId->execute(
$productId,
Group::NOT_LOGGED_IN_ID,
(int)$this->websiteRepository->get('base')->getId()
);
$data = reset($data);
foreach ($expectedPrices as $column => $price) {
$this->assertEquals($price, $data[$column]);
}
}
}
@@ -0,0 +1,201 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Model\ResourceModel\Indexer;
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status as StockStatusResource;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Helper\Bootstrap;
class StockTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
*/
protected $processor;
protected function setUp(): void
{
$this->processor = Bootstrap::getObjectManager()->get(
\Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
);
}
/**
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Bundle/_files/product_in_category.php
*/
public function testReindexAll()
{
$this->processor->reindexAll();
$categoryFactory = Bootstrap::getObjectManager()->get(
\Magento\Catalog\Model\CategoryFactory::class
);
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
$listProduct = Bootstrap::getObjectManager()->get(
\Magento\Catalog\Block\Product\ListProduct::class
);
$category = $categoryFactory->create()->load(2);
$layer = $listProduct->getLayer();
$layer->setCurrentCategory($category);
$productCollection = $layer->getProductCollection();
$productCollection->joinField(
'qty',
'cataloginventory_stock_status',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
$this->assertCount(3, $productCollection);
$expectedResult = [
'Simple Product' => 22,
'Custom Design Simple Product' => 24,
'Bundle Product' => 0
];
/** @var $product \Magento\Catalog\Model\Product */
foreach ($productCollection as $product) {
$this->assertEquals($expectedResult[$product->getName()], $product->getQty());
}
}
#[
DataFixture(
ProductFixture::class,
['sku' => 'simple1', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
's1'
),
DataFixture(
ProductFixture::class,
['sku' => 'simple2', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
's2'
),
DataFixture(
ProductFixture::class,
['sku' => 'simple3', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
's3'
),
DataFixture(
ProductFixture::class,
['sku' => 'simple4', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
's4'
),
DataFixture(
BundleSelectionFixture::class,
['sku' => '$s1.sku$', 'qty' => 2, 'can_change_quantity' => 0],
'link1'
),
DataFixture(
BundleSelectionFixture::class,
['sku' => '$s2.sku$', 'qty' => 2, 'can_change_quantity' => 0],
'link2'
),
DataFixture(
BundleSelectionFixture::class,
['sku' => '$s3.sku$', 'qty' => 2, 'can_change_quantity' => 1],
'link3'
),
DataFixture(
BundleSelectionFixture::class,
['sku' => '$s4.sku$', 'qty' => 2, 'can_change_quantity' => 0],
'link4'
),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link3$']], 'opt2'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link4$'], 'required' => false], 'opt3'),
DataFixture(BundleProductFixture::class, ['sku' => 'bundle1', '_options' => ['$opt1$', '$opt2$', '$opt3$']]),
]
/**
* @dataProvider reindexRowDataProvider
* @param array $stockItems
* @param bool $expectedStockStatus
* @return void
*/
public function testReindexRow(array $stockItems, bool $expectedStockStatus): void
{
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
foreach ($stockItems as $sku => $stockItem) {
$child = $productRepository->get($sku);
$child->setStockData($stockItem);
$productRepository->save($child);
}
$bundle = $productRepository->get('bundle1');
$this->processor->reindexRow($bundle->getId());
$stockStatusResource = Bootstrap::getObjectManager()->get(StockStatusResource::class);
$stockStatus = $stockStatusResource->getProductsStockStatuses($bundle->getId(), 0);
self::assertEquals($expectedStockStatus, (bool) $stockStatus[$bundle->getId()]);
}
public function reindexRowDataProvider(): array
{
return [
[
[
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
'simple2' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
],
true,
],
[
[
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
],
true,
],
[
[
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
'simple2' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
],
false,
],
[
[
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 0],
],
false,
],
[
[
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 0],
],
true,
],
[
[
'simple1' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
'simple2' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
'simple3' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
],
true,
],
[
[
'simple1' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
'simple2' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
'simple3' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
],
true,
],
];
}
}
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Model\ResourceModel\Option;
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
use Magento\Store\Test\Fixture\Store as StoreFixture;
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DbIsolation;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
class AreBundleOptionsSalableTest extends TestCase
{
/**
* @var AreBundleOptionsSalable
*/
private $areBundleOptionsSalable;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var StoreRepositoryInterface
*/
private $storeRepository;
protected function setUp(): void
{
$this->areBundleOptionsSalable = Bootstrap::getObjectManager()->create(AreBundleOptionsSalable::class);
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->storeRepository = Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class);
}
#[
DbIsolation(false),
DataFixture(WebsiteFixture::class, as: 'website2'),
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'group2'),
DataFixture(StoreFixture::class, ['store_group_id' => '$group2.id$', 'code' => 'store2'], 'store2'),
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'website_ids' => [1, '$website2.id']], 's1'),
DataFixture(ProductFixture::class, ['sku' => 'simple2', 'website_ids' => [1, '$website2.id']], 's2'),
DataFixture(ProductFixture::class, ['sku' => 'simple3', 'website_ids' => [1, '$website2.id']], 's3'),
DataFixture(BundleSelectionFixture::class, ['sku' => '$s1.sku$'], 'link1'),
DataFixture(BundleSelectionFixture::class, ['sku' => '$s2.sku$'], 'link2'),
DataFixture(BundleSelectionFixture::class, ['sku' => '$s3.sku$'], 'link3'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link3$'], 'required' => false], 'opt2'),
DataFixture(
BundleProductFixture::class,
['sku' => 'bundle1', '_options' => ['$opt1$', '$opt2$'], 'website_ids' => [1, '$website2.id']]
),
]
/**
* @dataProvider executeDataProvider
* @param string $storeCodeForChange
* @param array $disabledChildren
* @param string $storeCodeForCheck
* @param bool $expectedResult
* @return void
*/
public function testExecute(
string $storeCodeForChange,
array $disabledChildren,
string $storeCodeForCheck,
bool $expectedResult
): void {
$storeForChange = $this->storeRepository->get($storeCodeForChange);
foreach ($disabledChildren as $childSku) {
$child = $this->productRepository->get($childSku, true, $storeForChange->getId(), true);
$child->setStatus(ProductStatus::STATUS_DISABLED);
$this->productRepository->save($child);
}
$bundle = $this->productRepository->get('bundle1');
$storeForCheck = $this->storeRepository->get($storeCodeForCheck);
$result = $this->areBundleOptionsSalable->execute((int) $bundle->getId(), (int) $storeForCheck->getId());
self::assertEquals($expectedResult, $result);
}
public function executeDataProvider(): array
{
return [
['default', ['simple1'], 'default', true],
['default', ['simple3'], 'default', true],
['default', ['simple1', 'simple2'], 'default', false],
['default', ['simple1', 'simple2'], 'store2', true],
['store2', ['simple1', 'simple2', 'simple3'], 'store2', false],
['store2', ['simple1', 'simple2', 'simple3'], 'default', true],
['admin', ['simple1', 'simple2'], 'default', false],
['admin', ['simple1', 'simple2'], 'store2', false],
];
}
}
@@ -0,0 +1,98 @@
<?php
/**
* Copyright 2023 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento\Bundle\Model\ResourceModel\Selection;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
class CollectionTest extends \Magento\Bundle\Model\Product\BundlePriceAbstract
{
/**
* @var CollectionFactory
*/
protected $collectionFactory;
protected function setUp(): void
{
parent::setUp();
$this->collectionFactory = Bootstrap::getObjectManager()->create(CollectionFactory::class);
}
/**
* @magentoIndexerDimensionMode catalog_product_price website
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
* @magentoAppIsolation enabled
* @magentoDbIsolation disabled
* @group indexer_dimension
* @dataProvider getTestCases
*/
public function testAddPriceDataWithIndexerDimensionMode(array $strategy, int $expectedCount)
{
$this->prepareFixture($strategy, 'bundle_product');
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$product = $productRepository->get('bundle_product', false, null, true);
/** @var Collection $collection */
$collection = $this->collectionFactory->create();
$collection->setStoreId(0);
$collection->addPriceFilter($product, true);
$items = $collection->getItems();
$this->assertCount($expectedCount, $items);
}
public function getTestCases()
{
return [
'Dynamic bundle product with three Simple products' => [
'variation' => $this->getBundleConfiguration(),
'expectedCount' => 1
]
];
}
private function getBundleConfiguration()
{
$optionsData = [
[
'title' => 'op1',
'required' => true,
'type' => 'checkbox',
'links' => [
[
'sku' => 'simple1',
'qty' => 3,
'price' => 100,
'price_type' => 0,
],
[
'sku' => 'simple2',
'qty' => 2,
'price' => 100,
'price_type' => 0,
],
[
'sku' => 'simple3',
'qty' => 1,
'price' => 100,
'price_type' => 0,
],
]
]
];
return [
[
'modifierName' => 'addSimpleProduct',
'data' => [$optionsData]
],
];
}
}