View source
<?php
class GTMRealmTestCase extends GTMBaseTestCase {
public static function getInfo() {
return array(
'name' => 'Google Tag Manager :: Realm',
'description' => 'Tests the Google Tag Manager with variable realm',
'group' => 'Google tag',
);
}
protected function setUp() {
parent::setUp(array(
'google_tag',
'gtm_test',
'variable_realm',
'variable_store',
));
}
protected function createData() {
$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);
});
$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);
$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);
google_tag_assets_create();
}
protected function setRealmVariables__DEP() {
foreach ($this->variables as $key => $variables) {
$realm = $key == 'default' ? 'global' : 'gtm_test';
foreach ($variables as $name => $value) {
variable_realm_set($realm, $key, $name, $value, $rebuild = FALSE);
}
}
}
protected function checkSnippetFiles() {
$realms = variable_realm_list();
foreach ($realms as $realm_name => $realm_title) {
$keys = variable_realm_keys($realm_name);
foreach ($keys as $key_name => $key_title) {
$message = format_string('realm:key = @realm:@key', array(
'@realm' => $realm_name,
'@key' => $key_name,
));
$this
->pass($message, $this->group);
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[$key_name]);
}
}
}
}
protected function checkPageResponse() {
parent::checkPageResponse();
$realms = variable_realm_list();
unset($realms['global']);
foreach ($realms as $realm_name => $realm_title) {
$keys = variable_realm_keys($realm_name);
foreach ($keys as $key_name => $key_title) {
$this
->drupalGet('', $options = array(
'query' => array(
'name' => $realm_name,
'key' => $key_name,
),
));
$message = format_string('realm:key = @realm:@key', array(
'@realm' => $realm_name,
'@key' => $key_name,
));
$this
->pass($message, $this->group);
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[$key_name]);
}
else {
}
}
}
}
}
}