Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b69ee1d

Browse files
committed
MAGETWO-86063: Add/modify tests for pricing structure
- added teardown
1 parent acb8fdf commit b69ee1d

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Tax/ProductViewTest.php

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\TestFramework\ObjectManager;
1212
use Magento\TestFramework\TestCase\GraphQlAbstract;
1313
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\Framework\App\Config\ScopeConfigInterface;
1516
use Magento\Tax\Model\Config;
1617

@@ -29,6 +30,12 @@ class ProductViewTest extends GraphQlAbstract
2930
*/
3031
private $productRepository;
3132

33+
/** @var \Magento\Tax\Model\Calculation\Rate[] */
34+
private $fixtureTaxRates;
35+
36+
/** @var \Magento\Tax\Model\Calculation\Rule[] */
37+
private $fixtureTaxRules;
38+
3239
/**
3340
* @var StoreManagerInterface
3441
*/
@@ -57,6 +64,8 @@ protected function setUp()
5764
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
5865
1
5966
);
67+
$this->getFixtureTaxRates();
68+
$this->getFixtureTaxRules();
6069

6170
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
6271
$config = $this->objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
@@ -82,6 +91,16 @@ public function tearDown()
8291
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
8392
1
8493
);
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+
}
85104

86105
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
87106
$config = $this->objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
@@ -167,15 +186,7 @@ public function testQueryAllFieldsSimpleProduct()
167186
}
168187
QUERY;
169188

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);
179190

180191
/** @var \Magento\Catalog\Model\Product $product */
181192
$product = $this->productRepository->get($productSku, false, null, true);
@@ -186,6 +197,49 @@ public function testQueryAllFieldsSimpleProduct()
186197
$this->assertBaseFields($product, $response['products']['items'][0]);
187198
}
188199

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+
189243
/**
190244
* @param ProductInterface $product
191245
* @param array $actualResponse

0 commit comments

Comments
 (0)