You are here

google_tag.norealm.test in GoogleTagManager 7

Same filename and directory in other branches
  1. 7.2 tests/google_tag.norealm.test

File

tests/google_tag.norealm.test
View source
<?php

/**
 * Tests the Google Tag Manager for a site with no realms.
 */
class GTMNoRealmTestCase extends GTMBaseTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Google Tag Manager :: Standard',
      'description' => 'Tests the Google Tag Manager with no variable realm',
      'group' => 'Google tag',
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp(array(
      'google_tag',
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function createData() {
    $this->variables = (object) ($variables = array(
      'google_tag_container_id' => 'GTM-norealm',
      'google_tag_environment_id' => 'env-6',
      'google_tag_environment_token' => 'nnnnnnnnnnnnnnnnnnnnn',
      'google_tag_include_environment' => '1',
    ));
    array_walk($variables, function ($value, $key) {
      variable_set($key, $value);
    });
    google_tag_assets_create();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkSnippetFiles() {
    $realm_name = $key_name = '';
    foreach ($this->types as $type) {
      $url = "{$this->basePath}/google_tag/{$realm_name}google_tag.{$key_name}{$type}.js";
      $contents = @file_get_contents($url);
      $function = "verify{$type}Snippet";
      $this
        ->{$function}($contents, $this->variables);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function checkPageResponse() {
    parent::checkPageResponse();
    $this
      ->drupalGet('');
    $realm_name = $key_name = '';
    foreach ($this->types as $type) {
      $uri = "{$this->basePath}/google_tag/{$realm_name}google_tag.{$key_name}{$type}.js";
      if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {
        $realpath = $wrapper
          ->getExternalUrl($uri);
        $function = "verify{$type}Tag";
        $this
          ->{$function}($realpath, $this->variables);
      }
      else {

        // @todo
      }
    }
  }

}

Classes

Namesort descending Description
GTMNoRealmTestCase Tests the Google Tag Manager for a site with no realms.