protected function GTMTestBase::verifyScriptTagInline in GoogleTagManager 8
Verify the tag in page response.
File
- tests/
src/ Functional/ GTMTestBase.php, line 306
Class
- GTMTestBase
- Tests the Google Tag Manager.
Namespace
Drupal\Tests\google_tag\FunctionalCode
protected function verifyScriptTagInline($variables, $cache) {
$id = $variables->container_id;
$xpath = "//script[contains(text(), '{$id}')]";
$elements = $this
->xpath($xpath);
if (!is_array($elements) || count($elements) > 1) {
$message = 'Found only one script tag';
parent::assertFalse($status, $message);
return;
}
$contents = $elements[0]
->getHtml();
$status = strpos($contents, "(window,document,'script','dataLayer','{$id}')") !== FALSE;
$message = 'Found in script tag: container_id and data data_layer';
parent::assertTrue($status, $message);
$status = strpos($contents, "gtm_preview={$variables->environment_id}") !== FALSE;
$message = 'Found in script tag: environment_id';
parent::assertTrue($status, $message);
$status = strpos($contents, "gtm_auth={$variables->environment_token}") !== FALSE;
$message = 'Found in script tag: environment_token';
parent::assertTrue($status, $message);
$message = 'Contents of script tag matches cache';
parent::assertTrue($contents == $cache, $message);
}