You are here

protected function GTMTestBase::verifyNoScriptTag in GoogleTagManager 8

Verify the tag in page response.

1 call to GTMTestBase::verifyNoScriptTag()
GTMTestBase::verifyNoScriptTagInline in tests/src/Functional/GTMTestBase.php
Verify the tag in page response.

File

tests/src/Functional/GTMTestBase.php, line 337

Class

GTMTestBase
Tests the Google Tag Manager.

Namespace

Drupal\Tests\google_tag\Functional

Code

protected function verifyNoScriptTag($realpath, $variables, $cache = '') {

  // The tags are sorted by weight.
  $index = isset($variables->weight) ? $variables->weight - 1 : 0;
  $xpath = '//noscript//iframe';
  $elements = $this
    ->xpath($xpath);
  $contents = $elements[$index]
    ->getAttribute('src');
  $status = strpos($contents, "id={$variables->container_id}") !== FALSE;
  $message = 'Found in noscript tag: container_id';
  parent::assertTrue($status, $message);
  $status = strpos($contents, "gtm_preview={$variables->environment_id}") !== FALSE;
  $message = 'Found in noscript tag: environment_id';
  parent::assertTrue($status, $message);
  $status = strpos($contents, "gtm_auth={$variables->environment_token}") !== FALSE;
  $message = 'Found in noscript tag: environment_token';
  parent::assertTrue($status, $message);
  if ($cache) {
    $message = 'Contents of noscript tag matches cache';
    parent::assertTrue(strpos($cache, $contents) !== FALSE, $message);
  }
}