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/');
variable_set('matomo_visibility_pages', 0);
variable_set('matomo_pages', "admin\nadmin/*");
variable_set('matomo_roles', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
$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.');
$this
->drupalGet('admin');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is not displayed on admin page.');
$this
->drupalGet('admin/config/system/matomo');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is not displayed on admin subpage.');
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');
$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.');
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoRaw('u+"matomo.php"', '[testMatomoPageVisibility]: Tracking code is NOT displayed for anonymous.');
variable_set('matomo_visibility_pages', 0);
variable_set('matomo_roles', array());
$this
->drupalGet('admin');
$this
->assertRaw('403/URL = "', '[testMatomoPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
$this
->drupalGet($this
->randomName(64));
$this
->assertRaw('404/URL = "', '[testMatomoPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
}