Skip to content

Commit 358af37

Browse files
committed
MC-22959: Combination with different type prices
1 parent 8fa79d8 commit 358af37

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Pricing/Render/CombinationWithDifferentTypePricesTest.php

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\CatalogRule\Api\Data\RuleInterface;
1616
use Magento\CatalogRule\Api\Data\RuleInterfaceFactory;
1717
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
18-
use Magento\CatalogRule\Model\ResourceModel\Rule\Product\Price;
1918
use Magento\Customer\Model\Group;
2019
use Magento\Customer\Model\Session;
2120
use Magento\Framework\Registry;
@@ -60,11 +59,6 @@ class CombinationWithDifferentTypePricesTest extends TestCase
6059
*/
6160
private $customerSession;
6261

63-
/**
64-
* @var RuleInterface[]
65-
*/
66-
private $createdRules = [];
67-
6862
/**
6963
* @var WebsiteRepositoryInterface
7064
*/
@@ -90,11 +84,6 @@ class CombinationWithDifferentTypePricesTest extends TestCase
9084
*/
9185
private $productTierPriceFactory;
9286

93-
/**
94-
* @var Price
95-
*/
96-
private $catalogRuleProductPriceResource;
97-
9887
/**
9988
* @var ProductTierPriceExtensionFactory
10089
*/
@@ -116,7 +105,6 @@ protected function setUp()
116105
$this->catalogRuleFactory = $this->objectManager->get(RuleInterfaceFactory::class);
117106
$this->catalogRuleRepository = $this->objectManager->get(CatalogRuleRepositoryInterface::class);
118107
$this->productTierPriceFactory = $this->objectManager->get(ProductTierPriceInterfaceFactory::class);
119-
$this->catalogRuleProductPriceResource = $this->objectManager->get(Price::class);
120108
$this->productTierPriceExtensionFactory = $this->objectManager->get(ProductTierPriceExtensionFactory::class);
121109
$this->productRepository->cleanCache();
122110
}
@@ -128,7 +116,6 @@ protected function tearDown()
128116
{
129117
parent::tearDown();
130118
$this->registry->unregister('product');
131-
$this->cleanCatalogRuleData();
132119
}
133120

134121
/**
@@ -145,13 +132,13 @@ protected function tearDown()
145132
* @param array|null $tierMessageConfig
146133
* @return void
147134
*/
148-
public function testRenderSpecialPriceWithCombinationWithTierPrice(
135+
public function testRenderSpecialPriceInCombinationWithTierPrice(
149136
float $specialPrice,
150137
float $regularPrice,
151138
array $tierPrices,
152139
?array $tierMessageConfig
153140
): void {
154-
$this->processCheckRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
141+
$this->assertRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
155142
}
156143

157144
/**
@@ -222,15 +209,15 @@ public function tierPricesForAllCustomerGroupsDataProvider(): array
222209
* @param array|null $tierMessageConfig
223210
* @return void
224211
*/
225-
public function testRenderSpecialPriceWithCombinationWithTierPriceWithLoggedUser(
212+
public function testRenderSpecialPriceInCombinationWithTierPriceForLoggedInUser(
226213
float $specialPrice,
227214
float $regularPrice,
228215
array $tierPrices,
229216
?array $tierMessageConfig
230217
): void {
231218
try {
232219
$this->customerSession->setCustomerId(1);
233-
$this->processCheckRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
220+
$this->assertRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
234221
} finally {
235222
$this->customerSession->setCustomerId(null);
236223
}
@@ -268,6 +255,7 @@ public function tierPricesForLoggedCustomerGroupDataProvider(): array
268255
* product has catalog rule price with different type of prices.
269256
*
270257
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
258+
* @magentoDataFixture Magento/CatalogRule/_files/delete_catalog_rule_data.php
271259
*
272260
* @dataProvider catalogRulesDataProvider
273261
*
@@ -278,7 +266,7 @@ public function tierPricesForLoggedCustomerGroupDataProvider(): array
278266
* @param array|null $tierMessageConfig
279267
* @return void
280268
*/
281-
public function testRenderCatalogRulePriceWithCombinationWithDifferentTypePrices(
269+
public function testRenderCatalogRulePriceInCombinationWithDifferentPriceTypes(
282270
float $specialPrice,
283271
float $regularPrice,
284272
array $catalogRules,
@@ -287,7 +275,7 @@ public function testRenderCatalogRulePriceWithCombinationWithDifferentTypePrices
287275
): void {
288276
$this->createCatalogRulesForProduct($catalogRules);
289277
$this->indexBuilder->reindexFull();
290-
$this->processCheckRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
278+
$this->assertRenderedPrices($specialPrice, $regularPrice, $tierPrices, $tierMessageConfig);
291279
}
292280

293281
/**
@@ -409,7 +397,7 @@ private function checkPrices(string $priceHtml, float $specialPrice, float $regu
409397
}
410398

411399
/**
412-
* Assert that tier price message.
400+
* Assert that tier price message.
413401
*
414402
* @param string $priceHtml
415403
* @param array $tierMessageConfig
@@ -505,9 +493,9 @@ private function createTierPricesForProduct(ProductInterface $product, array $ti
505493
private function getSpecialPriceXpath(float $specialPrice): string
506494
{
507495
$pathsForSearch = [
508-
"//div[@class='price-box price-final_price']",
509-
"//span[@class='special-price']",
510-
sprintf("//span[@class='price' and text()='$%01.2f']", $specialPrice),
496+
"//div[contains(@class, 'price-box') and contains(@class, 'price-final_price')]",
497+
"//span[contains(@class, 'special-price')]",
498+
sprintf("//span[contains(@class, 'price') and text()='$%01.2f']", $specialPrice),
511499
];
512500

513501
return implode('', $pathsForSearch);
@@ -520,10 +508,10 @@ private function getSpecialPriceXpath(float $specialPrice): string
520508
private function getRegularPriceXpath(float $regularPrice): string
521509
{
522510
$pathsForSearch = [
523-
"//div[@class='price-box price-final_price']",
524-
"//span[@class='old-price']",
511+
"//div[contains(@class, 'price-box') and contains(@class, 'price-final_price')]",
512+
"//span[contains(@class, 'old-price')]",
525513
"//span[contains(@class, 'price-container')]",
526-
sprintf("//span[@class='price' and text()='$%01.2f']", $regularPrice),
514+
sprintf("//span[contains(@class, 'price') and text()='$%01.2f']", $regularPrice),
527515
];
528516

529517
return implode('', $pathsForSearch);
@@ -535,8 +523,8 @@ private function getRegularPriceXpath(float $regularPrice): string
535523
private function getRegularPriceLabelXpath(): string
536524
{
537525
$pathsForSearch = [
538-
"//div[@class='price-box price-final_price']",
539-
"//span[@class='old-price']",
526+
"//div[contains(@class, 'price-box') and contains(@class, 'price-final_price')]",
527+
"//span[contains(@class, 'old-price')]",
540528
"//span[contains(@class, 'price-container')]",
541529
"//span[text()='Regular Price']",
542530
];
@@ -555,12 +543,15 @@ private function getTierPriceMessageXpath(array $expectedMessage): string
555543
{
556544
[$qty, $price, $percent] = array_values($expectedMessage);
557545
$liPaths = [
558-
"@class='item' and contains(text(), 'Buy {$qty} for')",
559-
sprintf("//span[@class='price' and text()='$%01.2f']", $price),
546+
"contains(@class, 'item') and contains(text(), 'Buy {$qty} for')",
547+
sprintf("//span[contains(@class, 'price') and text()='$%01.2f']", $price),
560548
"//span[contains(@class, 'percent') and contains(text(), '{$percent}')]",
561549
];
562550

563-
return sprintf("//ul[@class='prices-tier items']//li[%s]", implode(' and ', $liPaths));
551+
return sprintf(
552+
"//ul[contains(@class, 'prices-tier') and contains(@class, 'items')]//li[%s]",
553+
implode(' and ', $liPaths)
554+
);
564555
}
565556

566557
/**
@@ -572,7 +563,7 @@ private function getTierPriceMessageXpath(array $expectedMessage): string
572563
* @param array|null $tierMessageConfig
573564
* @return void
574565
*/
575-
private function processCheckRenderedPrices(
566+
private function assertRenderedPrices(
576567
float $specialPrice,
577568
float $regularPrice,
578569
array $tierPrices,
@@ -611,21 +602,7 @@ private function createCatalogRulesForProduct(array $catalogRules): void
611602
foreach ($catalogRules as $catalogRule) {
612603
$catalogRule = array_replace($staticRuleData, $catalogRule);
613604
$catalogRule = $this->catalogRuleFactory->create(['data' => $catalogRule]);
614-
$this->createdRules[] = $this->catalogRuleRepository->save($catalogRule);
615-
}
616-
}
617-
618-
/**
619-
* Clean data in DB which created during catalog rule create.
620-
*
621-
* @return void
622-
*/
623-
private function cleanCatalogRuleData(): void
624-
{
625-
foreach ($this->createdRules as $createdRule) {
626-
$this->catalogRuleRepository->delete($createdRule);
605+
$this->catalogRuleRepository->save($catalogRule);
627606
}
628-
$this->catalogRuleProductPriceResource->getConnection()
629-
->delete($this->catalogRuleProductPriceResource->getMainTable());
630607
}
631608
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
9+
use Magento\CatalogRule\Api\Data\RuleInterface;
10+
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
11+
use Magento\CatalogRule\Model\ResourceModel\Rule\Product\Price;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var CollectionFactory $catalogRuleCollectionFactory */
16+
$catalogRuleCollectionFactory = $objectManager->get(CollectionFactory::class);
17+
/** @var CatalogRuleRepositoryInterface $catalogRuleRepository */
18+
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
19+
/** @var Price $catalogRuleProductPriceResource */
20+
$catalogRuleProductPriceResource = $objectManager->get(Price::class);
21+
$catalogRuleCollection = $catalogRuleCollectionFactory->create();
22+
/** @var RuleInterface $catalogRule */
23+
foreach ($catalogRuleCollection->getItems() as $catalogRule) {
24+
$catalogRuleRepository->delete($catalogRule);
25+
}
26+
$catalogRuleProductPriceResource->getConnection()->delete($catalogRuleProductPriceResource->getMainTable());

0 commit comments

Comments
 (0)