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,164 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Price;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoDbIsolation disabled
*/
class LowestPriceOptionProviderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
protected function setUp(): void
{
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetProductsIfOneOfChildIsDisabled()
{
$configurableProduct = $this->productRepository->get('configurable', false, null, true);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(10, $lowestPriceChildrenProduct->getPrice());
// load full aggregation root
$lowestPriceChildProduct = $this->productRepository->get(
$lowestPriceChildrenProduct->getSku(),
false,
null,
true
);
$lowestPriceChildProduct->setStatus(Status::STATUS_DISABLED);
// update in global scope
$currentStoreId = $this->storeManager->getStore()->getId();
$this->storeManager->setCurrentStore(Store::ADMIN_CODE);
$this->productRepository->save($lowestPriceChildProduct);
$this->storeManager->setCurrentStore($currentStoreId);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(20, $lowestPriceChildrenProduct->getPrice());
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetProductsIfOneOfChildIsDisabledPerStore()
{
$configurableProduct = $this->productRepository->get('configurable', false, null, true);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(10, $lowestPriceChildrenProduct->getPrice());
// load full aggregation root
$lowestPriceChildProduct = $this->productRepository->get(
$lowestPriceChildrenProduct->getSku(),
false,
null,
true
);
$lowestPriceChildProduct->setStatus(Status::STATUS_DISABLED);
// update in default store scope
$currentStoreId = $this->storeManager->getStore()->getId();
$defaultStore = $this->storeManager->getDefaultStoreView();
$this->storeManager->setCurrentStore($defaultStore->getId());
$this->productRepository->save($lowestPriceChildProduct);
$this->storeManager->setCurrentStore($currentStoreId);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(20, $lowestPriceChildrenProduct->getPrice());
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetProductsIfOneOfChildIsOutOfStock()
{
$configurableProduct = $this->productRepository->get('configurable', false, null, true);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(10, $lowestPriceChildrenProduct->getPrice());
// load full aggregation root
$lowestPriceChildProduct = $this->productRepository->get(
$lowestPriceChildrenProduct->getSku(),
false,
null,
true
);
$stockItem = $lowestPriceChildProduct->getExtensionAttributes()->getStockItem();
$stockItem->setIsInStock(0);
$this->productRepository->save($lowestPriceChildProduct);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(20, $lowestPriceChildrenProduct->getPrice());
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDataFixture Magento/Store/_files/website.php
*/
public function testGetProductsIfOneOfChildrenIsAssignedToOtherWebsite()
{
$configurableProduct = $this->productRepository->getById(1, false, null, true);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(10, $lowestPriceChildrenProduct->getPrice());
/** @var \Magento\Store\Api\WebsiteRepositoryInterface $webSiteRepository */
$webSiteRepository = Bootstrap::getObjectManager()->get(\Magento\Store\Api\WebsiteRepositoryInterface::class);
$website = $webSiteRepository->get('test');
$attributes = $lowestPriceChildrenProduct->getExtensionAttributes();
$attributes->setWebsiteIds([$website->getId()]);
$lowestPriceChildrenProduct->setExtensionAttributes($attributes);
$this->productRepository->save($lowestPriceChildrenProduct);
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
self::assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
self::assertEquals(20, $lowestPriceChildrenProduct->getPrice());
}
/**
* As LowestPriceOptionsProviderInterface used multiple times in scope
* of one test we need to always recreate it and prevent internal caching in property
* @return LowestPriceOptionsProviderInterface
*/
private function createLowestPriceOptionsProvider()
{
return Bootstrap::getObjectManager()->create(
LowestPriceOptionsProviderInterface::class
);
}
}
@@ -0,0 +1,103 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Price;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\TestFramework\Helper\Bootstrap;
class SpecialPriceIndexerTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var CollectionFactory
*/
private $productCollectionFactory;
/**
* @var Processor
*/
private $indexerProcessor;
protected function setUp(): void
{
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->productCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
$this->indexerProcessor = Bootstrap::getObjectManager()->get(Processor::class);
}
/**
* Use collection to check data in index
* Do not use magentoDbIsolation because index statement changing "tears" transaction (triggers creating)
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDataFixture Magento/Catalog/_files/enable_price_index_schedule.php
* @magentoDbIsolation disabled
*/
public function testFullReindexIfChildHasSpecialPrice()
{
$specialPrice = 2;
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', $specialPrice);
$this->productRepository->save($childProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product[] $items */
$items = array_values($collection->getItems());
self::assertEquals(10, $items[0]->getData('min_price'));
$this->indexerProcessor->reindexAll();
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product $item */
$item = $collection->getFirstItem();
self::assertEquals($specialPrice, $item->getData('min_price'));
}
/**
* Use collection to check data in index
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDbIsolation disabled
*/
public function testOnSaveIndexationIfChildHasSpecialPrice()
{
$specialPrice = 2;
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', $specialPrice);
$this->productRepository->save($childProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product $item */
$item = $collection->getFirstItem();
self::assertEquals($specialPrice, $item->getData('min_price'));
}
}
@@ -0,0 +1,112 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\ConfigurableProduct\Pricing\Price;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoDbIsolation disabled
* @group indexer_dimension
* @magentoIndexerDimensionMode catalog_product_price website_and_customer_group
*/
class SpecialPriceIndexerWithDimensionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var CollectionFactory
*/
private $productCollectionFactory;
/**
* @var Processor
*/
private $indexerProcessor;
/**
* Set up
*/
protected function setUp(): void
{
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->productCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
$this->indexerProcessor = Bootstrap::getObjectManager()->get(Processor::class);
}
/**
* Use collection to check data in index
* Do not use magentoDbIsolation because index statement changing "tears" transaction (triggers creating)
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDataFixture Magento/Catalog/_files/enable_price_index_schedule.php
*/
public function testFullReindexIfChildHasSpecialPrice()
{
$specialPrice = 2;
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', $specialPrice);
$this->productRepository->save($childProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product[] $items */
$items = array_values($collection->getItems());
self::assertEquals(10, $items[0]->getData('min_price'));
$this->indexerProcessor->reindexAll();
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product $item */
$item = $collection->getFirstItem();
self::assertEquals($specialPrice, $item->getData('min_price'));
}
/**
* Use collection to check data in index
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDbIsolation disabled
*/
public function testOnSaveIndexationIfChildHasSpecialPrice()
{
$specialPrice = 2;
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', $specialPrice);
$this->productRepository->save($childProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->addPriceData()
->addFieldToFilter(ProductInterface::SKU, 'configurable');
/** @var Product $item */
$item = $collection->getFirstItem();
self::assertEquals($specialPrice, $item->getData('min_price'));
}
}
@@ -0,0 +1,115 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Price;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\Data\Collection;
use Magento\TestFramework\Helper\Bootstrap;
class SpecialPriceTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var CollectionFactory
*/
private $productCollectionFactory;
protected function setUp(): void
{
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->productCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDbIsolation disabled
*/
public function testPriceInfoIfChildHasSpecialPrice()
{
$specialPrice = 2;
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', $specialPrice);
$this->productRepository->save($childProduct);
/** @var Product $configurableProduct */
$configurableProduct = $this->productRepository->get('configurable', true);
$priceInfo = $configurableProduct->getPriceInfo();
/** @var FinalPrice $finalPrice */
$finalPrice = $priceInfo->getPrice(FinalPrice::PRICE_CODE);
self::assertEquals($specialPrice, $finalPrice->getMinimalPrice()->getValue());
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_simple_77.php
* @magentoDbIsolation disabled
*/
public function testSortingOfProductsIfChildHasNotSpecialPrice()
{
/** @var Product $simpleProduct */
$simpleProduct = $this->productRepository->get('simple_77', true);
$simpleProduct
->setOptions([])
->setTierPrice([])
->setPrice(5);
$this->productRepository->save($simpleProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->setVisibility([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])
->setOrder(ProductInterface::PRICE, Collection::SORT_ORDER_DESC);
/** @var Product[] $items */
$items = array_values($collection->getItems());
self::assertEquals('configurable', $items[0]->getSku());
self::assertEquals('simple_77', $items[1]->getSku());
}
/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_simple_77.php
* @magentoDbIsolation disabled
*/
public function testSortingOfProductsIfChildHasSpecialPrice()
{
/** @var Product $simpleProduct */
$simpleProduct = $this->productRepository->get('simple_77', true);
$simpleProduct
->setOptions([])
->setTierPrice([])
->setPrice(5);
$this->productRepository->save($simpleProduct);
/** @var Product $childProduct */
$childProduct = $this->productRepository->get('simple_10', true);
$childProduct->setData('special_price', 2);
$this->productRepository->save($childProduct);
/** @var ProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection
->setVisibility([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])
->setOrder(ProductInterface::PRICE, Collection::SORT_ORDER_DESC);
/** @var Product[] $items */
$items = array_values($collection->getItems());
self::assertEquals('simple_77', $items[0]->getSku());
self::assertEquals('configurable', $items[1]->getSku());
}
}
@@ -0,0 +1,146 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Render\FinalPriceBox;
use Magento\Framework\Pricing\Render\Amount;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test price rendering according to is_product_list flag for Configurable product
*/
class RenderingBasedOnIsProductListFlagTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ProductInterface
*/
private $product;
/**
* @var FinalPrice
*/
private $finalPrice;
/**
* @var RendererPool
*/
private $rendererPool;
/**
* @var FinalPriceBox
*/
private $finalPriceBox;
protected function setUp(): void
{
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->product = $productRepository->get('configurable');
$this->finalPrice = Bootstrap::getObjectManager()->create(FinalPrice::class, [
'saleableItem' => $this->product,
'quantity' => null
]);
$this->rendererPool = Bootstrap::getObjectManager()->create(RendererPool::class);
$this->rendererPool->setData(
[
'default' =>
[
'default_amount_render_class' => Amount::class,
'default_amount_render_template' => 'Magento_Catalog::product/price/amount/default.phtml',
],
]
);
$this->finalPriceBox = Bootstrap::getObjectManager()->create(FinalPriceBox::class, [
'saleableItem' => $this->product,
'price' => $this->finalPrice,
'rendererPool' => $this->rendererPool,
]);
$this->finalPriceBox->setTemplate('Magento_ConfigurableProduct::product/price/final_price.phtml');
/** @var Product $childProduct */
$childProduct = $productRepository->get('simple_10', true);
$childProduct->setData('special_price', 5.99);
$productRepository->save($childProduct);
}
/**
* Test when is_product_list flag is not specified. Regular and Special price should be rendered
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoAppArea frontend
* @magentoDbIsolation disabled
*/
public function testRenderingByDefault()
{
$html = $this->finalPriceBox->toHtml();
self::assertStringContainsString('5.99', $html);
$this->assertGreaterThanOrEqual(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"normal-price")]',
$html
)
);
$this->assertGreaterThanOrEqual(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"old-price")]',
$html
)
);
}
/**
* Test when is_product_list flag is specified
*
* Special price should be valid
* FinalPriceBox::hasSpecialPrice should not be call
* Regular price for Configurable product should be rendered for is_product_list = false (product page), but not be
* for for is_product_list = true (list of products)
*
* @param bool $flag
* @param int|bool $count
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoAppArea frontend
* @dataProvider isProductListDataProvider
* @magentoDbIsolation disabled
*/
public function testRenderingAccordingToIsProductListFlag($flag, $count)
{
$this->finalPriceBox->setData('is_product_list', $flag);
$html = $this->finalPriceBox->toHtml();
self::assertStringContainsString('5.99', $html);
$this->assertEquals(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"normal-price")]',
$html
)
);
$this->assertEquals(
$count,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"old-price")]',
$html
)
);
}
/**
* @return array
*/
public function isProductListDataProvider()
{
return [
'is_not_product_list' => [false, 1],
'is_product_list' => [true, 0],
];
}
}
@@ -0,0 +1,154 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Render\FinalPriceBox;
use Magento\Framework\Pricing\Render\Amount;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoDbIsolation disabled
* @magentoIndexerDimensionMode catalog_product_price website_and_customer_group
* @group indexer_dimension
* Test price rendering according to is_product_list flag for Configurable product
*/
class RenderingBasedOnIsProductListFlagWithDimensionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ProductInterface
*/
private $product;
/**
* @var FinalPrice
*/
private $finalPrice;
/**
* @var RendererPool
*/
private $rendererPool;
/**
* @var FinalPriceBox
*/
private $finalPriceBox;
/**
* Set up
*/
protected function setUp(): void
{
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->product = $productRepository->get('configurable');
$this->finalPrice = Bootstrap::getObjectManager()->create(FinalPrice::class, [
'saleableItem' => $this->product,
'quantity' => null
]);
$this->rendererPool = Bootstrap::getObjectManager()->create(RendererPool::class);
$this->rendererPool->setData(
[
'default' =>
[
'default_amount_render_class' => Amount::class,
'default_amount_render_template' => 'Magento_Catalog::product/price/amount/default.phtml',
],
]
);
$this->finalPriceBox = Bootstrap::getObjectManager()->create(FinalPriceBox::class, [
'saleableItem' => $this->product,
'price' => $this->finalPrice,
'rendererPool' => $this->rendererPool,
]);
$this->finalPriceBox->setTemplate('Magento_ConfigurableProduct::product/price/final_price.phtml');
/** @var Product $childProduct */
$childProduct = $productRepository->get('simple_10', true);
$childProduct->setData('special_price', 5.99);
$productRepository->save($childProduct);
}
/**
* Test when is_product_list flag is not specified. Regular and Special price should be rendered
*
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoAppArea frontend
* @magentoDbIsolation disabled
*/
public function testRenderingByDefault()
{
$html = $this->finalPriceBox->toHtml();
self::assertStringContainsString('5.99', $html);
$this->assertGreaterThanOrEqual(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"normal-price")]',
$html
)
);
$this->assertGreaterThanOrEqual(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"old-price")]',
$html
)
);
}
/**
* Test when is_product_list flag is specified
*
* Special price should be valid
* FinalPriceBox::hasSpecialPrice should not be call
* Regular price for Configurable product should be rendered for is_product_list = false (product page), but not be
* for for is_product_list = true (list of products)
*
* @param bool $flag
* @param int|bool $count
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoAppArea frontend
* @dataProvider isProductListDataProvider
* @magentoDbIsolation disabled
*/
public function testRenderingAccordingToIsProductListFlag($flag, $count)
{
$this->finalPriceBox->setData('is_product_list', $flag);
$html = $this->finalPriceBox->toHtml();
self::assertStringContainsString('5.99', $html);
$this->assertEquals(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"normal-price")]',
$html
)
);
$this->assertEquals(
$count,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[contains(@class,"old-price")]',
$html
)
);
}
/**
* @return array
*/
public function isProductListDataProvider()
{
return [
'is_not_product_list' => [false, 1],
'is_product_list' => [true, 0],
];
}
}