Skip to content

Commit 90152d1

Browse files
author
Oleksandr Osadchyi
committed
MAGETWO-54322: ApplyTaxBasedOnVatIdTest test fails on Functional 3rd Party Tests plan
1 parent d902e08 commit 90152d1

File tree

2 files changed

+85
-13
lines changed

2 files changed

+85
-13
lines changed

dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Webapi.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,14 @@ protected function prepareCustomAttributes(array $data)
150150
*/
151151
protected function getCustomerGroup(Customer $customer)
152152
{
153-
return $customer->hasData('group_id')
154-
? $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()->getCustomerGroupId()
155-
: self::GENERAL_GROUP;
153+
if ($customer->hasData('group_id')) {
154+
if ($customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()) {
155+
return $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()->getCustomerGroupId();
156+
}
157+
return $customer->getData('group_id');
158+
} else {
159+
return self::GENERAL_GROUP;
160+
}
156161
}
157162

158163
/**

dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/ApplyTaxBasedOnVatIdTest.php

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
use Magento\Tax\Test\Fixture\TaxRule;
1010
use Magento\Checkout\Test\Fixture\Cart;
11-
use Magento\Customer\Test\Fixture\Customer;
1211
use Magento\Config\Test\Fixture\ConfigData;
1312
use Magento\Checkout\Test\Page\CheckoutCart;
1413
use Magento\Sales\Test\Fixture\OrderInjectable;
15-
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1614
use Magento\Customer\Test\TestCase\AbstractApplyVatIdTest;
1715

1816
/**
@@ -80,23 +78,28 @@ public function test(
8078
) {
8179
// Preconditions
8280
$this->configData = $configData;
81+
$this->customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer();
8382
$this->objectManager->create(
8483
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
8584
['configData' => $this->configData]
8685
)->run();
87-
$taxRule->persist();
86+
8887
// Prepare data
89-
$this->customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer();
90-
$address = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[0];
91-
$this->prepareVatConfig($vatConfig, $customerGroup);
92-
$poducts = $order->getEntityId()['products'];
88+
$taxRule->persist();
89+
$this->prepareVatConfiguration($vatConfig);
90+
$this->prepareCustomer($customerGroup);
91+
92+
$products = $order->getEntityId()['products'];
9393
$cart = $this->fixtureFactory->createByCode(
9494
'cart',
95-
['data' => array_merge($cart->getData(), ['items' => ['products' => $poducts]])]
95+
['data' => array_merge($cart->getData(), ['items' => ['products' => $products]])]
9696
);
97+
$address = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[0];
9798

98-
// Steps
9999
$order->persist();
100+
$this->updateCustomer($customerGroup);
101+
102+
// Steps
100103
$this->objectManager->create(
101104
\Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
102105
['customer' => $this->customer]
@@ -115,8 +118,72 @@ public function test(
115118
'address' => $address,
116119
'orderId' => $order->getId(),
117120
'cart' => $cart,
118-
'products' => $poducts
121+
'products' => $products
122+
];
123+
}
124+
125+
/**
126+
* Persist vat configuration
127+
*
128+
* @param string $vatConfig
129+
* @return void
130+
*/
131+
private function prepareVatConfiguration($vatConfig)
132+
{
133+
$groupConfig = [
134+
'customer/create_account/viv_domestic_group' => [
135+
'value' => $this->vatGroups['valid_domestic_group']->getCustomerGroupId()
136+
],
137+
'customer/create_account/viv_intra_union_group' => [
138+
'value' => $this->vatGroups['valid_intra_union_group']->getCustomerGroupId()
139+
],
140+
'customer/create_account/viv_invalid_group' => [
141+
'value' => $this->vatGroups['invalid_group']->getCustomerGroupId()
142+
],
143+
'customer/create_account/viv_error_group' => [
144+
'value' => $this->vatGroups['error_group']->getCustomerGroupId()
145+
]
119146
];
147+
$vatConfig = $this->fixtureFactory->createByCode(
148+
'configData',
149+
['data' => array_replace_recursive($vatConfig->getSection(), $groupConfig)]
150+
);
151+
$vatConfig->persist();
152+
}
153+
154+
/**
155+
* Persist customer with valid customer group
156+
*
157+
* @param string $customerGroup
158+
* @return void
159+
*/
160+
private function prepareCustomer($customerGroup)
161+
{
162+
$customerData = array_merge(
163+
$this->customer->getData(),
164+
['group_id' => ['value' => $this->vatGroups[$customerGroup]->getCustomerGroupId()]],
165+
['address' => ['addresses' => $this->customer->getDataFieldConfig('address')['source']->getAddresses()]],
166+
['email' => 'JohnDoe%isolation%@example.com']
167+
);
168+
169+
unset($customerData['id']);
170+
$this->customer = $this->fixtureFactory->createByCode('customer', ['data' => $customerData]);
171+
$this->customer->persist();
172+
}
173+
174+
/**
175+
* Update customer with customer group code for assert
176+
*
177+
* @param string $customerGroup
178+
* @return void
179+
*/
180+
private function updateCustomer($customerGroup){
181+
$customerData = array_merge(
182+
$this->customer->getData(),
183+
['group_id' => ['value' => $this->vatGroups[$customerGroup]->getCustomerGroupCode()]]
184+
);
185+
186+
$this->customer = $this->fixtureFactory->createByCode('customer', ['data' => $customerData]);
120187
}
121188

122189
/**

0 commit comments

Comments
 (0)