public function ProductDetailViewsTest::testCachability in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 tests/src/Functional/ProductDetailViewsTest.php \Drupal\Tests\commerce_google_tag_manager\Functional\ProductDetailViewsTest::testCachability()
@covers ::trackProductView
Ensure caching of product view don't prevent event to be fired.
File
- tests/
src/ Functional/ ProductDetailViewsTest.php, line 121
Class
- ProductDetailViewsTest
- @coversDefaultClass \Drupal\commerce_google_tag_manager\EventSubscriber\CommerceEventsSubscriber
Namespace
Drupal\Tests\commerce_google_tag_manager\FunctionalCode
public function testCachability() {
// Login as a normal user for cachability.
$normalUser = $this
->drupalCreateUser();
$this
->drupalLogin($normalUser);
// Ensure the storage is empty before any navigation occurs.
$events = $this->tempStore
->get('events');
$this
->assertEmpty($events);
$this
->drupalGet($this->product
->toUrl()
->toString());
$events = $this->tempStore
->get('events');
$this
->assertSame([
'f8e84d8ee071e2fb885d0dc755dd73ab' => [
'event' => 'productDetailViews',
'ecommerce' => [
'detail' => [
'actionField' => [
'list' => '',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '120.00',
'variant' => 'Lorem Ipsum',
],
],
],
],
],
], $events);
// Reset the event storage.
$this->tempStore
->set('events', NULL);
// Reload the same page a second time to ensure the event will be fired.
$this
->drupalGet($this->product
->toUrl()
->toString());
$events = $this->tempStore
->get('events');
$this
->assertSame([
'f8e84d8ee071e2fb885d0dc755dd73ab' => [
'event' => 'productDetailViews',
'ecommerce' => [
'detail' => [
'actionField' => [
'list' => '',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '120.00',
'variant' => 'Lorem Ipsum',
],
],
],
],
],
], $events);
}