@@ -33,6 +33,13 @@ class ProductPriceWithFPTTest extends GraphQlAbstract
33
33
/** @var ScopeConfigInterface */
34
34
private $ scopeConfig ;
35
35
36
+
37
+ /** @var \Magento\Tax\Model\Calculation\Rate[] */
38
+ private $ fixtureTaxRates ;
39
+
40
+ /** @var \Magento\Tax\Model\Calculation\Rule[] */
41
+ private $ fixtureTaxRules ;
42
+
36
43
/**
37
44
* @inheritdoc
38
45
*/
@@ -52,18 +59,46 @@ protected function setUp(): void
52
59
'tax/calculation/price_includes_tax '
53
60
];
54
61
62
+
63
+ $ this ->getFixtureTaxRates ();
64
+ $ this ->getFixtureTaxRules ();
65
+ $ taxRules = $ this ->getFixtureTaxRules ();
66
+ if (count ($ taxRules )) {
67
+ $ taxRates = $ this ->getFixtureTaxRates ();
68
+ foreach ($ taxRules as $ taxRule ) {
69
+ $ taxRule ->delete ();
70
+ }
71
+ foreach ($ taxRates as $ taxRate ) {
72
+ $ taxRate ->delete ();
73
+ }
74
+ }
75
+
55
76
foreach ($ currentSettingsArray as $ configPath ) {
56
77
$ this ->initialConfig [$ configPath ] = $ this ->scopeConfig ->getValue (
57
78
$ configPath
58
79
);
59
80
}
81
+ /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
82
+ $ config = $ this ->objectManager ->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
83
+ $ config ->reinit ();
60
84
}
61
85
62
86
/**
63
87
* @inheritdoc
64
88
*/
65
89
protected function tearDown (): void
66
90
{
91
+ $ taxRules = $ this ->getFixtureTaxRules ();
92
+ if (count ($ taxRules )) {
93
+ $ taxRates = $ this ->getFixtureTaxRates ();
94
+ foreach ($ taxRules as $ taxRule ) {
95
+ $ taxRule ->delete ();
96
+ }
97
+ foreach ($ taxRates as $ taxRate ) {
98
+ $ taxRate ->delete ();
99
+ }
100
+ }
101
+
67
102
$ this ->writeConfig ($ this ->initialConfig );
68
103
}
69
104
@@ -727,4 +762,47 @@ private function getProductQuery(array $skus): string
727
762
}
728
763
QUERY ;
729
764
}
765
+
766
+ /**
767
+ * Get tax rates created in Magento\Tax\_files\tax_rule_region_1_al.php
768
+ *
769
+ * @return \Magento\Tax\Model\Calculation\Rate[]
770
+ */
771
+ private function getFixtureTaxRates ()
772
+ {
773
+ if ($ this ->fixtureTaxRates === null ) {
774
+ $ this ->fixtureTaxRates = [];
775
+ if ($ this ->getFixtureTaxRules ()) {
776
+ $ taxRateIds = (array )$ this ->getFixtureTaxRules ()[0 ]->getRates ();
777
+ foreach ($ taxRateIds as $ taxRateId ) {
778
+ /** @var \Magento\Tax\Model\Calculation\Rate $taxRate */
779
+ $ taxRate = Bootstrap::getObjectManager ()->create (\Magento \Tax \Model \Calculation \Rate::class);
780
+ $ this ->fixtureTaxRates [] = $ taxRate ->load ($ taxRateId );
781
+ }
782
+ }
783
+ }
784
+ return $ this ->fixtureTaxRates ;
785
+ }
786
+
787
+ /**
788
+ * Get tax rule created in Magento\Tax\_files\tax_rule_region_1_al.php
789
+ *
790
+ * @return \Magento\Tax\Model\Calculation\Rule[]
791
+ */
792
+ private function getFixtureTaxRules ()
793
+ {
794
+ if ($ this ->fixtureTaxRules === null ) {
795
+ $ this ->fixtureTaxRules = [];
796
+ $ taxRuleCodes = ['AL Test Rule ' ];
797
+ foreach ($ taxRuleCodes as $ taxRuleCode ) {
798
+ /** @var \Magento\Tax\Model\Calculation\Rule $taxRule */
799
+ $ taxRule = Bootstrap::getObjectManager ()->create (\Magento \Tax \Model \Calculation \Rule::class);
800
+ $ taxRule ->load ($ taxRuleCode , 'code ' );
801
+ if ($ taxRule ->getId ()) {
802
+ $ this ->fixtureTaxRules [] = $ taxRule ;
803
+ }
804
+ }
805
+ }
806
+ return $ this ->fixtureTaxRules ;
807
+ }
730
808
}
0 commit comments