function GoogleAnalyticsBasicTest::testGoogleAnalyticsPageVisibility in Google Analytics 7
Same name and namespace in other branches
- 6.4 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsPageVisibility()
- 6.3 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsPageVisibility()
- 7.2 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsPageVisibility()
File
- ./googleanalytics.test, line 41
- Test file for Google Analytics module.
Class
- GoogleAnalyticsBasicTest
- @file
Test file for Google Analytics module.
Code
function testGoogleAnalyticsPageVisibility() {
$ua_code = 'UA-123456-1';
variable_set('googleanalytics_account', $ua_code);
variable_set('googleanalytics_visibility_pages', 0);
variable_set('googleanalytics_pages', "admin\nadmin/*");
variable_set('googleanalytics_roles', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
$this
->drupalGet('');
$this
->assertRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed for authenticated users.');
$this
->drupalGet('admin');
$this
->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin page.');
$this
->drupalGet('admin/config/system/googleanalytics');
$this
->assertNoRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin subpage.');
variable_set('googleanalytics_visibility_pages', 1);
$this
->drupalGet('admin');
$this
->assertRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin page.');
$this
->drupalGet('admin/config/system/googleanalytics');
$this
->assertRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin subpage.');
$this
->drupalGet('');
$this
->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is NOT displayed on front page.');
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is NOT displayed for anonymous.');
variable_set('googleanalytics_visibility_pages', 0);
variable_set('googleanalytics_roles', array());
$this
->drupalGet('admin');
$this
->assertRaw('/403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
$this
->drupalGet($this
->randomName(64));
$this
->assertRaw('/404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
variable_set('cache', 1);
$this
->drupalGet('', array(), array(
'DNT: 1',
));
$this
->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT header send from client, but page caching is enabled and tracker cannot removed.');
variable_set('cache', 0);
$this
->drupalGet('');
$this
->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: Tracking is enabled without DNT header.');
$this
->drupalGet('', array(), array(
'DNT: 1',
));
$this
->assertNoRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT header received from client. Tracking has been disabled by browser.');
variable_set('googleanalytics_privacy_donottrack', 0);
$this
->drupalGet('', array(), array(
'DNT: 1',
));
$this
->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT feature is disabled, DNT header from browser has been ignored.');
}