public function EventTrackerServicePurchaseTest::testPurchaseOrder in Commerce Google Tag Manager 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EventTrackerServicePurchaseTest.php \Drupal\Tests\commerce_google_tag_manager\Kernel\EventTrackerServicePurchaseTest::testPurchaseOrder()
@covers ::purchase
File
- tests/
src/ Kernel/ EventTrackerServicePurchaseTest.php, line 163
Class
- EventTrackerServicePurchaseTest
- @coversDefaultClass \Drupal\commerce_google_tag_manager\EventTrackerService
Namespace
Drupal\Tests\commerce_google_tag_manager\KernelCode
public function testPurchaseOrder() {
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'CH',
],
]);
$profile
->save();
$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();
$this
->assertEquals(new Price('11.00', 'USD'), $this->orderItem
->getAdjustedTotalPrice());
$this
->assertEquals(new Price('11.00', 'USD'), $this->orderItem
->getAdjustedUnitPrice());
$this
->assertEquals(new Price('11.00', 'USD'), $order
->getTotalPrice());
$this
->assertEquals(new Price('11.00', 'USD'), $order
->getSubtotalPrice());
$order
->recalculateTotalPrice();
$this
->assertEquals(new Price('11.00', 'USD'), $order
->getTotalPrice());
$this
->assertEquals(new Price('11.00', 'USD'), $order
->getSubtotalPrice());
$this
->invokeMethod($this->eventTracker, 'purchase', [
$order,
]);
$data = $this->tempStore
->get('events');
$this
->assertSame([
'fee6d54a92c4d3feab9fd1bc7af8943e' => [
'event' => 'purchase',
'ecommerce' => [
'purchase' => [
'actionField' => [
'id' => '6',
'affiliation' => 'Default store',
'revenue' => '11.00',
'shipping' => '0',
'tax' => '0',
'coupon' => '',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.00',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
], $data);
}