function PiwikBasicTest::testPiwikPageVisibility in Piwik Web Analytics 6.2
Same name and namespace in other branches
- 7.2 piwik.test \PiwikBasicTest::testPiwikPageVisibility()
File
- ./
piwik.test, line 66 - Test file for Piwik module.
Class
- PiwikBasicTest
- @file Test file for Piwik module.
Code
function testPiwikPageVisibility() {
$ua_code = '1';
variable_set('piwik_site_id', $ua_code);
variable_get('piwik_url_http', 'http://example.com/piwik/');
variable_get('piwik_url_https', 'https://example.com/piwik/');
// Show tracking on "every page except the listed pages".
variable_set('piwik_visibility_pages', 0);
// Disable tracking one "admin*" pages only.
variable_set('piwik_pages', "admin\nadmin/*");
// Enable tracking only for authenticated users only.
variable_set('piwik_roles', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
// Check tracking code visibility.
$this
->drupalGet('');
$this
->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed for authenticated users.');
// Test whether tracking code is not included on pages to omit.
$this
->drupalGet('admin');
$this
->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin page.');
$this
->drupalGet('admin/settings/piwik');
// Checking for tracking code URI here, as $ua_code is displayed in the form.
$this
->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin subpage.');
// Test whether tracking code display is properly flipped.
variable_set('piwik_visibility_pages', 1);
$this
->drupalGet('admin');
$this
->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin page.');
$this
->drupalGet('admin/settings/piwik');
// Checking for tracking code URI here, as $ua_code is displayed in the form.
$this
->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin subpage.');
$this
->drupalGet('');
$this
->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed on front page.');
// Test whether tracking code is not display for anonymous.
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed for anonymous.');
// Switch back to every page except the listed pages.
variable_set('piwik_visibility_pages', 0);
// Enable tracking code for all user roles.
variable_set('piwik_roles', array());
// Test whether 403 forbidden tracking code is shown if user has no access.
//$this->drupalGet('admin');
//$this->assertRaw('"403/URL = "', '[testPiwikPageVisibility]: 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/URL = "', '[testPiwikPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
}