You are here

public function EventTrackerServiceTest::testPurchase in Commerce Google Tag Manager 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/EventTrackerServiceTest.php \Drupal\Tests\commerce_google_tag_manager\Unit\EventTrackerServiceTest::testPurchase()

@covers ::purchase

@dataProvider productVariationProvider

File

tests/src/Unit/EventTrackerServiceTest.php, line 286

Class

EventTrackerServiceTest
Tests for the EventTracker service.

Namespace

Drupal\Tests\commerce_google_tag_manager\Unit

Code

public function testPurchase($product_variation, $product_data) {
  $order_item = $this
    ->prohesizeOrderItem($product_variation, new Price('50', 'CHF'), '4.00');
  $order = $this
    ->prohesizeOrder([
    $order_item,
  ], 321, 'My Shop', new Price('50', 'CHF'));
  $this->eventStorage
    ->expects($this
    ->once())
    ->method('addEvent')
    ->with([
    'event' => EventTrackerService::EVENT_PURCHASE,
    'ecommerce' => [
      'purchase' => [
        'actionField' => [
          'id' => '321',
          'affiliation' => 'My Shop',
          'revenue' => '50.00',
          'shipping' => '0.00',
          'tax' => '0',
          'coupon' => '',
        ],
        'products' => [
          array_merge($product_data, [
            'quantity' => 4,
          ]),
        ],
      ],
    ],
  ]);
  $this->eventTracker
    ->purchase($order
    ->reveal());
}