11
11
use Magento \TestFramework \ObjectManager ;
12
12
use Magento \TestFramework \TestCase \GraphQlAbstract ;
13
13
use Magento \Store \Model \StoreManagerInterface ;
14
+ use Magento \TestFramework \Helper \Bootstrap ;
14
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
16
use Magento \Tax \Model \Config ;
16
17
@@ -29,6 +30,12 @@ class ProductViewTest extends GraphQlAbstract
29
30
*/
30
31
private $ productRepository ;
31
32
33
+ /** @var \Magento\Tax\Model\Calculation\Rate[] */
34
+ private $ fixtureTaxRates ;
35
+
36
+ /** @var \Magento\Tax\Model\Calculation\Rule[] */
37
+ private $ fixtureTaxRules ;
38
+
32
39
/**
33
40
* @var StoreManagerInterface
34
41
*/
@@ -57,6 +64,8 @@ protected function setUp()
57
64
ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
58
65
1
59
66
);
67
+ $ this ->getFixtureTaxRates ();
68
+ $ this ->getFixtureTaxRules ();
60
69
61
70
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
62
71
$ config = $ this ->objectManager ->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
@@ -82,6 +91,16 @@ public function tearDown()
82
91
ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
83
92
1
84
93
);
94
+ $ taxRules = $ this ->getFixtureTaxRules ();
95
+ if (count ($ taxRules )) {
96
+ $ taxRates = $ this ->getFixtureTaxRates ();
97
+ foreach ($ taxRules as $ taxRule ) {
98
+ $ taxRule ->delete ();
99
+ }
100
+ foreach ($ taxRates as $ taxRate ) {
101
+ $ taxRate ->delete ();
102
+ }
103
+ }
85
104
86
105
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
87
106
$ config = $ this ->objectManager ->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
@@ -167,15 +186,7 @@ public function testQueryAllFieldsSimpleProduct()
167
186
}
168
187
QUERY ;
169
188
170
- // get customer ID token
171
- /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
172
- $ customerTokenService = $ this ->objectManager ->create (
173
- \Magento \Integration \Api \CustomerTokenServiceInterface::class
174
- );
175
- $ customerToken =
$ customerTokenService->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
176
-
177
- $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
178
- $ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
189
+ $ response = $ this ->graphQlQuery ($ query );
179
190
180
191
/** @var \Magento\Catalog\Model\Product $product */
181
192
$ product = $ this ->productRepository ->get ($ productSku , false , null , true );
@@ -186,6 +197,49 @@ public function testQueryAllFieldsSimpleProduct()
186
197
$ this ->assertBaseFields ($ product , $ response ['products ' ]['items ' ][0 ]);
187
198
}
188
199
200
+ /**
201
+ * Get tax rates created in Magento\Tax\_files\tax_rule_region_1_al.php
202
+ *
203
+ * @return \Magento\Tax\Model\Calculation\Rate[]
204
+ */
205
+ private function getFixtureTaxRates ()
206
+ {
207
+ if ($ this ->fixtureTaxRates === null ) {
208
+ $ this ->fixtureTaxRates = [];
209
+ if ($ this ->getFixtureTaxRules ()) {
210
+ $ taxRateIds = (array )$ this ->getFixtureTaxRules ()[0 ]->getRates ();
211
+ foreach ($ taxRateIds as $ taxRateId ) {
212
+ /** @var \Magento\Tax\Model\Calculation\Rate $taxRate */
213
+ $ taxRate = Bootstrap::getObjectManager ()->create (\Magento \Tax \Model \Calculation \Rate::class);
214
+ $ this ->fixtureTaxRates [] = $ taxRate ->load ($ taxRateId );
215
+ }
216
+ }
217
+ }
218
+ return $ this ->fixtureTaxRates ;
219
+ }
220
+
221
+ /**
222
+ * Get tax rule created in Magento\Tax\_files\tax_rule_region_1_al.php
223
+ *
224
+ * @return \Magento\Tax\Model\Calculation\Rule[]
225
+ */
226
+ private function getFixtureTaxRules ()
227
+ {
228
+ if ($ this ->fixtureTaxRules === null ) {
229
+ $ this ->fixtureTaxRules = [];
230
+ $ taxRuleCodes = ['AL Test Rule ' ];
231
+ foreach ($ taxRuleCodes as $ taxRuleCode ) {
232
+ /** @var \Magento\Tax\Model\Calculation\Rule $taxRule */
233
+ $ taxRule = Bootstrap::getObjectManager ()->create (\Magento \Tax \Model \Calculation \Rule::class);
234
+ $ taxRule ->load ($ taxRuleCode , 'code ' );
235
+ if ($ taxRule ->getId ()) {
236
+ $ this ->fixtureTaxRules [] = $ taxRule ;
237
+ }
238
+ }
239
+ }
240
+ return $ this ->fixtureTaxRules ;
241
+ }
242
+
189
243
/**
190
244
* @param ProductInterface $product
191
245
* @param array $actualResponse
0 commit comments