public function EventTrackerServicePurchaseTest::testPurchaseOrderTaxExemptPrices in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/EventTrackerServicePurchaseTest.php \Drupal\Tests\commerce_google_tag_manager\Kernel\EventTrackerServicePurchaseTest::testPurchaseOrderTaxExemptPrices()
@covers ::purchase
Tests the handling of tax-exempt customers with tax-inclusive prices.
See also
Drupal\Tests\commerce_tax\Kernel\OrderIntegrationTest::testTaxExemptPrices
File
- tests/
src/ Kernel/ EventTrackerServicePurchaseTest.php, line 357
Class
- EventTrackerServicePurchaseTest
- @coversDefaultClass \Drupal\commerce_google_tag_manager\EventTrackerService
Namespace
Drupal\Tests\commerce_google_tag_manager\KernelCode
public function testPurchaseOrderTaxExemptPrices() {
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'CH',
],
]);
$profile
->save();
$this->store
->set('prices_include_tax', TRUE);
$this->store
->save();
$this
->assertEquals(new Price('11.00', 'USD'), $this->orderItem
->getAdjustedTotalPrice());
$this
->assertEquals(new Price('11.00', 'USD'), $this->orderItem
->getAdjustedUnitPrice());
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = Order::create([
'type' => 'default',
'state' => 'draft',
'mail' => $this->user
->getEmail(),
'uid' => $this->user
->id(),
'ip_address' => '127.0.0.1',
'order_number' => '6',
'billing_profile' => $profile,
'store_id' => $this->store
->id(),
'order_items' => [
$this->orderItem,
],
]);
$order
->save();
// No taxes should be applied, but the price will be lower based on the
// store billing zone (as so the default tax will be lower from the price).
$this
->assertEmpty($order
->collectAdjustments());
$this
->assertEquals(new Price('9.17', 'USD'), $order
->getTotalPrice());
$this
->assertEquals(new Price('9.17', 'USD'), $order
->getSubtotalPrice());
$order
->recalculateTotalPrice();
$this
->assertEquals(new Price('9.17', 'USD'), $order
->getTotalPrice());
$this
->assertEquals(new Price('9.17', 'USD'), $order
->getSubtotalPrice());
$this
->invokeMethod($this->eventTracker, 'purchase', [
$order,
]);
$data = $this->tempStore
->get('events');
$this
->assertSame([
'8d7902747750b6d8ba873ebdd6122300' => [
'event' => 'purchase',
'ecommerce' => [
'purchase' => [
'actionField' => [
'id' => '6',
'affiliation' => 'Default store',
'revenue' => '9.17',
'shipping' => '0',
'tax' => '0',
'coupon' => '',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
// @todo Maybe we should rework the price resolver of product.
// For now, it use the Commerce Price Resolver, but here we want
// the order price (the lowered price) instead of field price.
'price' => '11.00',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
], $data);
}