security update for contrib modules
This commit is contained in:
@@ -6,6 +6,13 @@
|
||||
*/
|
||||
class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* User without permissions to edit snippets.
|
||||
*
|
||||
* @var \StdClass
|
||||
*/
|
||||
protected $noSnippetUser;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Google Analytics basic tests',
|
||||
@@ -25,6 +32,8 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
);
|
||||
|
||||
// User to set up google_analytics.
|
||||
$this->noSnippetUser = $this->drupalCreateUser($permissions);
|
||||
$permissions[] = 'add JS snippets for google analytics';
|
||||
$this->admin_user = $this->drupalCreateUser($permissions);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
}
|
||||
@@ -48,13 +57,33 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
$edit['googleanalytics_account'] = $this->randomName(2);
|
||||
$this->drupalPost('admin/config/system/googleanalytics', $edit, t('Save configuration'));
|
||||
$this->assertRaw(t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'), '[testGoogleAnalyticsConfiguration]: Invalid Web Property ID number validated.');
|
||||
|
||||
// User should have access to code snippets.
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_create');
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_before');
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_after');
|
||||
$this->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
|
||||
$this->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
|
||||
$this->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is enabled.');
|
||||
|
||||
// Login as user without JS permissions.
|
||||
$this->drupalLogin($this->noSnippetUser);
|
||||
$this->drupalGet('admin/config/system/googleanalytics');
|
||||
|
||||
// User should *not* have access to snippets, but create fields.
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_create');
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_before');
|
||||
$this->assertFieldByName('googleanalytics_codesnippet_after');
|
||||
$this->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
|
||||
$this->assertFieldByXPath("//textarea[@name='googleanalytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
|
||||
$this->assertFieldByXPath("//textarea[@name='googleanalytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
|
||||
}
|
||||
|
||||
function testGoogleAnalyticsPageVisibility() {
|
||||
// Verify that no tracking code is embedded into the webpage; if there is
|
||||
// only the module installed, but UA code not configured. See #2246991.
|
||||
$this->drupalGet('');
|
||||
$this->assertNoRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed without UA code configured.');
|
||||
$this->assertNoRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed without UA code configured.');
|
||||
|
||||
$ua_code = 'UA-123456-1';
|
||||
variable_set('googleanalytics_account', $ua_code);
|
||||
@@ -75,7 +104,7 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
$this->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin page.');
|
||||
$this->drupalGet('admin/config/system/googleanalytics');
|
||||
// Checking for tracking code URI here, as $ua_code is displayed in the form.
|
||||
$this->assertNoRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin subpage.');
|
||||
$this->assertNoRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin subpage.');
|
||||
|
||||
// Test whether tracking code display is properly flipped.
|
||||
variable_set('googleanalytics_visibility_pages', 1);
|
||||
@@ -83,7 +112,7 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
$this->assertRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin page.');
|
||||
$this->drupalGet('admin/config/system/googleanalytics');
|
||||
// Checking for tracking code URI here, as $ua_code is displayed in the form.
|
||||
$this->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin subpage.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin subpage.');
|
||||
$this->drupalGet('');
|
||||
$this->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is NOT displayed on front page.');
|
||||
|
||||
@@ -97,13 +126,15 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
// Enable tracking code for all user roles.
|
||||
variable_set('googleanalytics_roles', array());
|
||||
|
||||
$base_path = base_path();
|
||||
|
||||
// Test whether 403 forbidden tracking code is shown if user has no access.
|
||||
$this->drupalGet('admin');
|
||||
$this->assertRaw('/403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
|
||||
$this->assertRaw($base_path . '403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
|
||||
|
||||
// Test whether 404 not found tracking code is shown on non-existent pages.
|
||||
$this->drupalGet($this->randomName(64));
|
||||
$this->assertRaw('/404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
|
||||
$this->assertRaw($base_path . '404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
|
||||
|
||||
// DNT Tests:
|
||||
// Enable system internal page cache for anonymous users.
|
||||
@@ -139,7 +170,7 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
(function(q,u,i,c,k){window['GoogleAnalyticsObject']=q;
|
||||
window[q]=window[q]||function(){(window[q].q=window[q].q||[]).push(arguments)},
|
||||
window[q].l=1*new Date();c=i.createElement(u),k=i.getElementsByTagName(u)[0];
|
||||
c.async=true;c.src='//www.google-analytics.com/analytics.js';
|
||||
c.async=true;c.src='https://www.google-analytics.com/analytics.js';
|
||||
k.parentNode.insertBefore(c,k)})('ga','script',document);
|
||||
ga('create', 'UA-123456-7');
|
||||
ga('send', 'pageview');
|
||||
@@ -150,7 +181,7 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
// Test whether tracking code uses latest JS.
|
||||
variable_set('googleanalytics_cache', 0);
|
||||
$this->drupalGet('');
|
||||
$this->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsTrackingCode]: Latest tracking code used.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsTrackingCode]: Latest tracking code used.');
|
||||
|
||||
// Test whether anonymize visitors IP address feature has been enabled.
|
||||
variable_set('googleanalytics_tracker_anonymizeip', 0);
|
||||
@@ -227,13 +258,14 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
$this->assertRaw('ga("create", "' . $ua_code . '", {"cookieDomain":"auto","allowLinker":true', '[testGoogleAnalyticsTrackingCode]: "allowLinker" has been found. Cross domain tracking is active.');
|
||||
$this->assertRaw('ga("require", "linker");', '[testGoogleAnalyticsTrackingCode]: Require linker has been found. Cross domain tracking is active.');
|
||||
$this->assertRaw('ga("linker:autoLink", ["www.example.com","www.example.net"]);', '[testGoogleAnalyticsTrackingCode]: "linker:autoLink" has been found. Cross domain tracking is active.');
|
||||
$this->assertRaw('"trackDomainMode":2,', '[testGoogleAnalyticsTrackingCode]: Domain mode value is of type integer.');
|
||||
$this->assertRaw('"trackCrossDomains":["www.example.com","www.example.net"]', '[testGoogleAnalyticsTrackingCode]: Cross domain tracking with www.example.com and www.example.net is active.');
|
||||
variable_set('googleanalytics_domain_mode', 0);
|
||||
|
||||
// Test whether debugging script has been enabled.
|
||||
variable_set('googleanalytics_debug', 1);
|
||||
$this->drupalGet('');
|
||||
$this->assertRaw('//www.google-analytics.com/analytics_debug.js', '[testGoogleAnalyticsTrackingCode]: Google debugging script has been enabled.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics_debug.js', '[testGoogleAnalyticsTrackingCode]: Google debugging script has been enabled.');
|
||||
|
||||
// Check if text and link is shown on 'Status Reports' page.
|
||||
// Requires 'administer site configuration' permission.
|
||||
@@ -243,7 +275,7 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
|
||||
// Test whether debugging script has been disabled.
|
||||
variable_set('googleanalytics_debug', 0);
|
||||
$this->drupalGet('');
|
||||
$this->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsTrackingCode]: Google debugging script has been disabled.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsTrackingCode]: Google debugging script has been disabled.');
|
||||
|
||||
// Test whether the CREATE and BEFORE and AFTER code is added to the tracker.
|
||||
$codesnippet_create = array(
|
||||
@@ -284,6 +316,7 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends DrupalWebTestCase {
|
||||
|
||||
// User to set up google_analytics.
|
||||
$this->admin_user = $this->drupalCreateUser($permissions);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
}
|
||||
|
||||
function testGoogleAnalyticsCustomDimensions() {
|
||||
@@ -362,34 +395,30 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends DrupalWebTestCase {
|
||||
1 => array(
|
||||
'index' => 1,
|
||||
'value' => '6',
|
||||
'value_expected' => 6,
|
||||
),
|
||||
2 => array(
|
||||
'index' => 2,
|
||||
'value' => '8000',
|
||||
'value_expected' => 8000,
|
||||
),
|
||||
3 => array(
|
||||
'index' => 3,
|
||||
'value' => '7.8654',
|
||||
'value_expected' => 7.8654,
|
||||
),
|
||||
4 => array(
|
||||
'index' => 4,
|
||||
'value' => '1123.4',
|
||||
'value_expected' => 1123.4,
|
||||
),
|
||||
5 => array(
|
||||
'index' => 5,
|
||||
'value' => '5,67',
|
||||
'value_expected' => 5,
|
||||
),
|
||||
);
|
||||
|
||||
variable_set('googleanalytics_custom_metric', $googleanalytics_custom_metric);
|
||||
$this->drupalGet('');
|
||||
|
||||
foreach ($googleanalytics_custom_metric as $metric) {
|
||||
$this->assertRaw('ga("set", ' . drupal_json_encode('metric' . $metric['index']) . ', ' . drupal_json_encode($metric['value_expected']) . ');', '[testGoogleAnalyticsCustomDimensionsAndMetrics]: Metric #' . $metric['index'] . ' is shown.');
|
||||
$this->assertRaw('ga("set", ' . drupal_json_encode('metric' . $metric['index']) . ', ' . drupal_json_encode((float) $metric['value']) . ');', '[testGoogleAnalyticsCustomDimensionsAndMetrics]: Metric #' . $metric['index'] . ' is shown.');
|
||||
}
|
||||
|
||||
// Test whether tokens are replaced in custom metric values.
|
||||
@@ -421,6 +450,75 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends DrupalWebTestCase {
|
||||
$this->assertNoRaw('ga("set", ' . drupal_json_encode('metric3') . ', ' . drupal_json_encode('') . ');', '[testGoogleAnalyticsCustomDimensionsAndMetrics]: Empty value is not shown.');
|
||||
$this->assertRaw('ga("set", ' . drupal_json_encode('metric4') . ', ' . drupal_json_encode(0) . ');', '[testGoogleAnalyticsCustomDimensionsAndMetrics]: Value 0 is shown.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if Custom Dimensions token form validation works.
|
||||
*/
|
||||
public function testGoogleAnalyticsCustomDimensionsTokenFormValidation() {
|
||||
$ua_code = 'UA-123456-1';
|
||||
|
||||
// Check form validation.
|
||||
$edit['googleanalytics_account'] = $ua_code;
|
||||
$edit['googleanalytics_custom_dimension[indexes][1][value]'] = '[current-user:name]';
|
||||
$edit['googleanalytics_custom_dimension[indexes][2][value]'] = '[current-user:edit-url]';
|
||||
$edit['googleanalytics_custom_dimension[indexes][3][value]'] = '[user:name]';
|
||||
$edit['googleanalytics_custom_dimension[indexes][4][value]'] = '[term:name]';
|
||||
$edit['googleanalytics_custom_dimension[indexes][5][value]'] = '[term:tid]';
|
||||
|
||||
$this->drupalPost('admin/config/system/googleanalytics', $edit, t('Save configuration'));
|
||||
|
||||
$this->assertRaw(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array('%element-title' => t('Custom dimension value #@index', array('@index' => 1)), '@invalid-tokens' => implode(', ', array('[current-user:name]')))));
|
||||
$this->assertRaw(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array('%element-title' => t('Custom dimension value #@index', array('@index' => 2)), '@invalid-tokens' => implode(', ', array('[current-user:edit-url]')))));
|
||||
$this->assertRaw(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array('%element-title' => t('Custom dimension value #@index', array('@index' => 3)), '@invalid-tokens' => implode(', ', array('[user:name]')))));
|
||||
// BUG #2037595
|
||||
//$this->assertNoRaw(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array('%element-title' => t('Custom dimension value #@index', array('@index' => 4)), '@invalid-tokens' => implode(', ', array('[term:name]')))));
|
||||
//$this->assertNoRaw(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array('%element-title' => t('Custom dimension value #@index', array('@index' => 5)), '@invalid-tokens' => implode(', ', array('[term:tid]')))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test custom url functionality of Google Analytics module.
|
||||
*/
|
||||
class GoogleAnalyticsCustomUrls extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Google Analytics custom url tests',
|
||||
'description' => 'Test custom url functionality of Google Analytics module.',
|
||||
'group' => 'Google Analytics',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('googleanalytics');
|
||||
|
||||
$permissions = array(
|
||||
'access administration pages',
|
||||
'administer google analytics',
|
||||
);
|
||||
|
||||
// User to set up google_analytics.
|
||||
$this->admin_user = $this->drupalCreateUser($permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if user password page urls are overridden.
|
||||
*/
|
||||
public function testGoogleAnalyticsUserPasswordPage() {
|
||||
$base_path = base_path();
|
||||
$ua_code = 'UA-123456-4';
|
||||
variable_set('googleanalytics_account', $ua_code);
|
||||
|
||||
$this->drupalGet('user/password', array('query' => array('name' => 'foo')));
|
||||
$this->assertRaw('ga("set", "page", "' . $base_path . 'user/password"');
|
||||
|
||||
$this->drupalGet('user/password', array('query' => array('name' => 'foo@example.com')));
|
||||
$this->assertRaw('ga("set", "page", "' . $base_path . 'user/password"');
|
||||
|
||||
$this->drupalGet('user/password');
|
||||
$this->assertNoRaw('ga("set", "page",', '[testGoogleAnalyticsCustomUrls]: Custom url not set.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class GoogleAnalyticsStatusMessagesTest extends DrupalWebTestCase {
|
||||
@@ -460,7 +558,7 @@ class GoogleAnalyticsStatusMessagesTest extends DrupalWebTestCase {
|
||||
//drupal_set_message('Example status message.', 'status');
|
||||
//drupal_set_message('Example warning message.', 'warning');
|
||||
//drupal_set_message('Example error message.', 'error');
|
||||
//drupal_set_message('Example error <em>message</em> with html tags and <a href="http://example.com/">link</a>.', 'error');
|
||||
//drupal_set_message('Example error <em>message</em> with html tags and <a href="https://example.com/">link</a>.', 'error');
|
||||
//$this->drupalGet('');
|
||||
//$this->assertNoRaw('ga("send", "event", "Messages", "Status message", "Example status message.");', '[testGoogleAnalyticsStatusMessages]: Example status message is not enabled for tracking.');
|
||||
//$this->assertNoRaw('ga("send", "event", "Messages", "Warning message", "Example warning message.");', '[testGoogleAnalyticsStatusMessages]: Example warning message is not enabled for tracking.');
|
||||
@@ -684,13 +782,13 @@ class GoogleAnalyticsPhpFilterTest extends DrupalWebTestCase {
|
||||
// Check tracking code visibility.
|
||||
variable_set('googleanalytics_pages', '<?php return TRUE; ?>');
|
||||
$this->drupalGet('');
|
||||
$this->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on frontpage page.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on frontpage page.');
|
||||
$this->drupalGet('admin');
|
||||
$this->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on admin page.');
|
||||
$this->assertRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on admin page.');
|
||||
|
||||
variable_set('googleanalytics_pages', '<?php return FALSE; ?>');
|
||||
$this->drupalGet('');
|
||||
$this->assertNoRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is not displayed on frontpage page.');
|
||||
$this->assertNoRaw('https://www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is not displayed on frontpage page.');
|
||||
|
||||
// Test administration form.
|
||||
variable_set('googleanalytics_pages', '<?php return TRUE; ?>');
|
||||
|
||||
Reference in New Issue
Block a user