15
15
use Magento \CatalogRule \Api \Data \RuleInterface ;
16
16
use Magento \CatalogRule \Api \Data \RuleInterfaceFactory ;
17
17
use Magento \CatalogRule \Model \Indexer \IndexBuilder ;
18
- use Magento \CatalogRule \Model \ResourceModel \Rule \Product \Price ;
19
18
use Magento \Customer \Model \Group ;
20
19
use Magento \Customer \Model \Session ;
21
20
use Magento \Framework \Registry ;
@@ -60,11 +59,6 @@ class CombinationWithDifferentTypePricesTest extends TestCase
60
59
*/
61
60
private $ customerSession ;
62
61
63
- /**
64
- * @var RuleInterface[]
65
- */
66
- private $ createdRules = [];
67
-
68
62
/**
69
63
* @var WebsiteRepositoryInterface
70
64
*/
@@ -90,11 +84,6 @@ class CombinationWithDifferentTypePricesTest extends TestCase
90
84
*/
91
85
private $ productTierPriceFactory ;
92
86
93
- /**
94
- * @var Price
95
- */
96
- private $ catalogRuleProductPriceResource ;
97
-
98
87
/**
99
88
* @var ProductTierPriceExtensionFactory
100
89
*/
@@ -116,7 +105,6 @@ protected function setUp()
116
105
$ this ->catalogRuleFactory = $ this ->objectManager ->get (RuleInterfaceFactory::class);
117
106
$ this ->catalogRuleRepository = $ this ->objectManager ->get (CatalogRuleRepositoryInterface::class);
118
107
$ this ->productTierPriceFactory = $ this ->objectManager ->get (ProductTierPriceInterfaceFactory::class);
119
- $ this ->catalogRuleProductPriceResource = $ this ->objectManager ->get (Price::class);
120
108
$ this ->productTierPriceExtensionFactory = $ this ->objectManager ->get (ProductTierPriceExtensionFactory::class);
121
109
$ this ->productRepository ->cleanCache ();
122
110
}
@@ -128,7 +116,6 @@ protected function tearDown()
128
116
{
129
117
parent ::tearDown ();
130
118
$ this ->registry ->unregister ('product ' );
131
- $ this ->cleanCatalogRuleData ();
132
119
}
133
120
134
121
/**
@@ -145,13 +132,13 @@ protected function tearDown()
145
132
* @param array|null $tierMessageConfig
146
133
* @return void
147
134
*/
148
- public function testRenderSpecialPriceWithCombinationWithTierPrice (
135
+ public function testRenderSpecialPriceInCombinationWithTierPrice (
149
136
float $ specialPrice ,
150
137
float $ regularPrice ,
151
138
array $ tierPrices ,
152
139
?array $ tierMessageConfig
153
140
): void {
154
- $ this ->processCheckRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
141
+ $ this ->assertRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
155
142
}
156
143
157
144
/**
@@ -222,15 +209,15 @@ public function tierPricesForAllCustomerGroupsDataProvider(): array
222
209
* @param array|null $tierMessageConfig
223
210
* @return void
224
211
*/
225
- public function testRenderSpecialPriceWithCombinationWithTierPriceWithLoggedUser (
212
+ public function testRenderSpecialPriceInCombinationWithTierPriceForLoggedInUser (
226
213
float $ specialPrice ,
227
214
float $ regularPrice ,
228
215
array $ tierPrices ,
229
216
?array $ tierMessageConfig
230
217
): void {
231
218
try {
232
219
$ this ->customerSession ->setCustomerId (1 );
233
- $ this ->processCheckRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
220
+ $ this ->assertRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
234
221
} finally {
235
222
$ this ->customerSession ->setCustomerId (null );
236
223
}
@@ -268,6 +255,7 @@ public function tierPricesForLoggedCustomerGroupDataProvider(): array
268
255
* product has catalog rule price with different type of prices.
269
256
*
270
257
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
258
+ * @magentoDataFixture Magento/CatalogRule/_files/delete_catalog_rule_data.php
271
259
*
272
260
* @dataProvider catalogRulesDataProvider
273
261
*
@@ -278,7 +266,7 @@ public function tierPricesForLoggedCustomerGroupDataProvider(): array
278
266
* @param array|null $tierMessageConfig
279
267
* @return void
280
268
*/
281
- public function testRenderCatalogRulePriceWithCombinationWithDifferentTypePrices (
269
+ public function testRenderCatalogRulePriceInCombinationWithDifferentPriceTypes (
282
270
float $ specialPrice ,
283
271
float $ regularPrice ,
284
272
array $ catalogRules ,
@@ -287,7 +275,7 @@ public function testRenderCatalogRulePriceWithCombinationWithDifferentTypePrices
287
275
): void {
288
276
$ this ->createCatalogRulesForProduct ($ catalogRules );
289
277
$ this ->indexBuilder ->reindexFull ();
290
- $ this ->processCheckRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
278
+ $ this ->assertRenderedPrices ($ specialPrice , $ regularPrice , $ tierPrices , $ tierMessageConfig );
291
279
}
292
280
293
281
/**
@@ -409,7 +397,7 @@ private function checkPrices(string $priceHtml, float $specialPrice, float $regu
409
397
}
410
398
411
399
/**
412
- * Assert that tier price message.
400
+ * Assert that tier price message.
413
401
*
414
402
* @param string $priceHtml
415
403
* @param array $tierMessageConfig
@@ -505,9 +493,9 @@ private function createTierPricesForProduct(ProductInterface $product, array $ti
505
493
private function getSpecialPriceXpath (float $ specialPrice ): string
506
494
{
507
495
$ 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 ),
511
499
];
512
500
513
501
return implode ('' , $ pathsForSearch );
@@ -520,10 +508,10 @@ private function getSpecialPriceXpath(float $specialPrice): string
520
508
private function getRegularPriceXpath (float $ regularPrice ): string
521
509
{
522
510
$ 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') ] " ,
525
513
"//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 ),
527
515
];
528
516
529
517
return implode ('' , $ pathsForSearch );
@@ -535,8 +523,8 @@ private function getRegularPriceXpath(float $regularPrice): string
535
523
private function getRegularPriceLabelXpath (): string
536
524
{
537
525
$ 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') ] " ,
540
528
"//span[contains(@class, 'price-container')] " ,
541
529
"//span[text()='Regular Price'] " ,
542
530
];
@@ -555,12 +543,15 @@ private function getTierPriceMessageXpath(array $expectedMessage): string
555
543
{
556
544
[$ qty , $ price , $ percent ] = array_values ($ expectedMessage );
557
545
$ 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 ),
560
548
"//span[contains(@class, 'percent') and contains(text(), ' {$ percent }')] " ,
561
549
];
562
550
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
+ );
564
555
}
565
556
566
557
/**
@@ -572,7 +563,7 @@ private function getTierPriceMessageXpath(array $expectedMessage): string
572
563
* @param array|null $tierMessageConfig
573
564
* @return void
574
565
*/
575
- private function processCheckRenderedPrices (
566
+ private function assertRenderedPrices (
576
567
float $ specialPrice ,
577
568
float $ regularPrice ,
578
569
array $ tierPrices ,
@@ -611,21 +602,7 @@ private function createCatalogRulesForProduct(array $catalogRules): void
611
602
foreach ($ catalogRules as $ catalogRule ) {
612
603
$ catalogRule = array_replace ($ staticRuleData , $ catalogRule );
613
604
$ 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 );
627
606
}
628
- $ this ->catalogRuleProductPriceResource ->getConnection ()
629
- ->delete ($ this ->catalogRuleProductPriceResource ->getMainTable ());
630
607
}
631
608
}
0 commit comments