Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ApplyTaxBasedOnVatIdTest.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Checkout\Test\Page\CheckoutCart;
15 
36 {
37  /* tags */
38  const MVP = 'no';
39  const TEST_TYPE = '3rd_party_test';
40  /* end tags */
41 
47  protected $checkoutCart;
48 
56  {
57  $this->checkoutCart = $checkoutCart;
58  }
59 
71  public function test(
72  ConfigData $vatConfig,
73  OrderInjectable $order,
74  TaxRule $taxRule,
75  Cart $cart,
77  $customerGroup
78  ) {
79  // Preconditions
80  $this->configData = $configData;
81  $this->customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer();
82  $this->objectManager->create(
83  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
84  ['configData' => $this->configData]
85  )->run();
86 
87  // Prepare data
88  $taxRule->persist();
89  $this->prepareVatConfiguration($vatConfig);
90  $this->prepareCustomer($customerGroup);
91 
92  $products = $order->getEntityId()['products'];
93  $cart = $this->fixtureFactory->createByCode(
94  'cart',
95  ['data' => array_merge($cart->getData(), ['items' => ['products' => $products]])]
96  );
97  $address = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[0];
98 
99  $order->persist();
100  $this->updateCustomer($customerGroup);
101 
102  // Steps
103  $this->objectManager->create(
104  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
105  ['customer' => $this->customer]
106  )->run();
107  $this->objectManager->create(
108  \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class,
109  $order->getEntityId()
110  )->run();
111  $this->checkoutCart->open();
112  $this->checkoutCart->getCartBlock()->waitCartContainerLoading();
113  $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
114  $this->checkoutCart->getCartBlock()->waitCartContainerLoading();
115 
116  return [
117  'customer' => $this->customer,
118  'address' => $address,
119  'orderId' => $order->getId(),
120  'cart' => $cart,
121  'products' => $products
122  ];
123  }
124 
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  ]
146  ];
147  $vatConfig = $this->fixtureFactory->createByCode(
148  'configData',
149  ['data' => array_replace_recursive($vatConfig->getSection(), $groupConfig)]
150  );
151  $vatConfig->persist();
152  }
153 
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 
180  private function updateCustomer($customerGroup)
181  {
182  $customerData = array_merge(
183  $this->customer->getData(),
184  ['group_id' => ['value' => $this->vatGroups[$customerGroup]->getCustomerGroupCode()]]
185  );
186 
187  $this->customer = $this->fixtureFactory->createByCode('customer', ['data' => $customerData]);
188  }
189 
195  public function tearDown()
196  {
197  parent::tearDown();
198  $this->objectManager->create(\Magento\Tax\Test\TestStep\DeleteAllTaxRulesStep::class)->run();
199  }
200 }
$customerData
$order
Definition: order.php:55
test(ConfigData $vatConfig, OrderInjectable $order, TaxRule $taxRule, Cart $cart, $configData, $customerGroup)
$address
Definition: customer.php:38
$taxRule
Definition: tax_rule.php:35