diff --git a/tests/src/Functional/ProductDetailViewsTest.php b/tests/src/Functional/ProductDetailViewsTest.php new file mode 100644 index 0000000..20341e4 --- /dev/null +++ b/tests/src/Functional/ProductDetailViewsTest.php @@ -0,0 +1,90 @@ + 'default', + 'sku' => 'lorem-ipsum-120', + 'title' => 'Lorem Ipsum', + 'price' => new Price('120.00', 'USD'), + 'status' => TRUE, + ]); + + $this->product = Product::create([ + 'type' => 'default', + 'title' => 'Lorem Ipsum', + ]); + $this->product->save(); + $this->product->addVariation($variation)->save(); + + } + + /** + * Cover commerce_google_tag_manager_commerce_product_view. + */ + public function testProductDetailViews() { + $this->tempStore = $this->container->get('tempstore.private')->get('commerce_google_tag_manager'); + + $this->drupalGet($this->product->toUrl()->toString()); + $this->assertResponse(200); + + $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); + } + +}