function MatomoBasicTest::testMatomoTrackingCode in Matomo Analytics 7.2
File
- ./matomo.test, line 120
- Test file for Matomo module.
Class
- MatomoBasicTest
- @file
Test file for Matomo module.
Code
function testMatomoTrackingCode() {
$ua_code = '2';
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_roles', array());
variable_set('matomo_cache', 0);
$this
->drupalGet('');
$this
->assertRaw('u+"matomo.php"', '[testMatomoTrackingCode]: Latest tracking code used.');
variable_set('matomo_trackuserid', 1);
$this
->drupalGet('');
$this
->assertRaw('_paq.push(["setUserId", ', '[testMatomoTrackingCode]: Tracking code for User ID is enabled.');
variable_set('matomo_trackuserid', 0);
$this
->drupalGet('');
$this
->assertNoRaw('_paq.push(["setUserId", ', '[testMatomoTrackingCode]: Tracking code for User ID is disabled.');
$this
->drupalGet('');
$this
->assertNoRaw('_paq.push(["setCookieDomain"', '[testMatomoTrackingCode]: Single domain tracking is active.');
variable_set('matomo_domain_mode', 1);
$this
->drupalGet('');
global $cookie_domain;
if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
$this
->assertRaw('_paq.push(["setCookieDomain"', '[testMatomoTrackingCode]: One domain with multiple subdomains is active on real host.');
}
else {
$this
->assertNoRaw('_paq.push(["setCookieDomain"', '[testMatomoTrackingCode]: One domain with multiple subdomains may be active on localhost (test result is not reliable).');
}
variable_set('matomo_codesnippet_before', '_paq.push(["setLinkTrackingTimer", 250]);');
variable_set('matomo_codesnippet_after', '_paq.push(["t2.setSiteId", 2]);_gaq.push(["t2.trackPageView"]);');
$this
->drupalGet('');
$this
->assertRaw('setLinkTrackingTimer', '[testMatomoTrackingCode]: Before codesnippet has been found with "setLinkTrackingTimer" set.');
$this
->assertRaw('t2.trackPageView', '[testMatomoTrackingCode]: After codesnippet with "t2" tracker has been found.');
}