function MatomoBasicTest::testMatomoPageVisibility in Matomo Analytics 7.2
File
- ./
matomo.test, line 66 - Test file for Matomo module.
Class
- MatomoBasicTest
- @file Test file for Matomo module.
Code
function testMatomoPageVisibility() {
$ua_code = '1';
variable_set('matomo_site_id', $ua_code);
variable_get('matomo_url_http', 'http://example.com/matomo/');
variable_get('matomo_url_https', 'https://example.com/matomo/');
// Show tracking on "every page except the listed pages".
variable_set('matomo_visibility_pages', 0);
// Disable tracking one "admin*" pages only.
variable_set('matomo_pages', "admin\nadmin/*");
// Enable tracking only for authenticated users only.
variable_set('matomo_roles', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
// Check tracking code visibility.
$this
->drupalGet('');
$this
->assertRaw('/matomo/matomo.js', '[testMatomoPageVisibility]: Custom tracking script is is displayed for authenticated users.');
$this
->assertRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is displayed for authenticated users.');
// Test whether tracking code is not included on pages to omit.
$this
->drupalGet('admin');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is not displayed on admin page.');
$this
->drupalGet('admin/config/system/matomo');
// Checking for tracking code URI here, as $ua_code is displayed in the form.
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is not displayed on admin subpage.');
// Test whether tracking code display is properly flipped.
variable_set('matomo_visibility_pages', 1);
$this
->drupalGet('admin');
$this
->assertRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is displayed on admin page.');
$this
->drupalGet('admin/config/system/matomo');
// Checking for tracking code URI here, as $ua_code is displayed in the form.
$this
->assertRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is displayed on admin subpage.');
$this
->drupalGet('');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is NOT displayed on front page.');
// Test whether tracking code is not display for anonymous.
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is NOT displayed for anonymous.');
// Switch back to every page except the listed pages.
variable_set('matomo_visibility_pages', 0);
// Enable tracking code for all user roles.
variable_set('matomo_roles', array());
// Test whether 403 forbidden tracking code is shown if user has no access.
$this
->drupalGet('admin');
$this
->assertRaw('403/URL = "', '[testMatomoPageVisibility]: 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 = "', '[testMatomoPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
}