You are here

protected function GTMRealmTestCase::createData in GoogleTagManager 7

Same name and namespace in other branches
  1. 7.2 tests/google_tag.realm.test \GTMRealmTestCase::createData()

Create test data: configuration variables and snippet files.

Overrides GTMBaseTestCase::createData

File

tests/google_tag.realm.test, line 29

Class

GTMRealmTestCase
Tests the Google Tag Manager for a site with realms.

Code

protected function createData() {

  // variable_realm_add() calls $store->variable_add($name, $value)
  // this sets the value in the in-memory variable store
  //
  // variable_realm_set() calls $store->variable_set($name, $value)
  // this sets the value in the in-memory variable store AND the database
  // the global store calls variable_set($name, $value) which updates the
  // database AND $GLOBALS['conf']
  //
  // for testing purposes, variable_realm_add() is sufficient except for the
  // global store which needs to update $GLOBALS['conf']
  //
  // variable_realm_add(,,,, TRUE) sets
  //   $GLOBALS['conf'] = _variable_realm_build()
  // _variable_realm_build() loops on realms
  //   foreach (variable_realm_current() as $realm_controller)
  //     $variables = array_merge($variables, $values);
  //   return $variables;
  // so the last realm wins which is gtm_test:secondary
  // so pass FALSE for the $rebuild parameter
  // Set variables for global:default.
  // These values are acceptable for testing but do not reflect actual site
  // operation. The global:default realm values are not fixed but reflect the
  // main realm:key in effect on a given page response. For example, on a site
  // with a language realm, the global:default values will be those for the
  // language of the current page response.
  $this->variables['default'] = (object) ($variables = array(
    'google_tag_container_id' => 'GTM-default',
    'google_tag_environment_id' => 'env-7',
    'google_tag_environment_token' => 'ddddddddddddddddddddd',
    'google_tag_include_environment' => '1',
  ));
  variable_realm_add('global', 'default', $variables, NULL, FALSE);
  array_walk($variables, function ($value, $key) {
    variable_set($key, $value);
  });

  // Set variables for gtm_test:primary.
  $this->variables['primary'] = (object) ($variables = array(
    'google_tag_container_id' => 'GTM-primary',
    'google_tag_environment_id' => 'env-1',
    'google_tag_environment_token' => 'ppppppppppppppppppppp',
  ));
  variable_realm_add('gtm_test', 'primary', $variables, NULL, FALSE);

  // Set variables for gtm_test:secondary.
  $this->variables['secondary'] = (object) ($variables = array(
    'google_tag_container_id' => 'GTM-secondary',
    'google_tag_environment_id' => 'env-2',
    'google_tag_environment_token' => 'sssssssssssssssssssss',
  ));
  variable_realm_add('gtm_test', 'secondary', $variables, NULL, FALSE);

  /*
      $this->setRealmVariables();
  */

  // Create snippet files.
  google_tag_assets_create();
}