You are here

public function EventsControllerTest::testGetEvents in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/EventsControllerTest.php \Drupal\Tests\commerce_google_tag_manager\Functional\EventsControllerTest::testGetEvents()

@covers ::getEvents

File

tests/src/Functional/EventsControllerTest.php, line 73

Class

EventsControllerTest
@coversDefaultClass \Drupal\commerce_google_tag_manager\Controller\EventsController

Namespace

Drupal\Tests\commerce_google_tag_manager\Functional

Code

public function testGetEvents() {

  // Go to a product page to fire a EVENT_PRODUCT_DETAIL_VIEWS event.
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert the previous event has been stored.
  $url = Url::fromRoute('commerce_google_tag_manager.events');
  $content = $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSame('[{"event":"productDetailViews","ecommerce":{"detail":{"actionField":{"list":""},"products":[{"name":"Lorem Ipsum","id":"1","price":"120.00","variant":"Lorem Ipsum"}]}}}]', (string) $content);

  // Assert stored events are flush after first fetch.
  $content = $this
    ->drupalGet($url);
  $this
    ->assertSame('[]', (string) $content);
}