public function GoogleAnalyticsCustomUrls::testGoogleAnalyticsCustomUrls in Google Analytics 4.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/GoogleAnalyticsCustomUrls.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsCustomUrls::testGoogleAnalyticsCustomUrls()
Tests if user password page urls are overridden.
File
- tests/
src/ Functional/ GoogleAnalyticsCustomUrls.php, line 56
Class
- GoogleAnalyticsCustomUrls
- Test custom url functionality of Google Analytics module.
Namespace
Drupal\Tests\google_analytics\FunctionalCode
public function testGoogleAnalyticsCustomUrls() {
$base_path = base_path();
$ua_code = 'UA-123456-1';
$this
->config('google_analytics.settings')
->set('account', $ua_code)
->set('privacy.anonymizeip', 0)
->set('track.displayfeatures', 1)
->save();
$this
->drupalGet('user/password', [
'query' => [
'name' => 'foo',
],
]);
$this
->assertRaw('gtag("config", ' . Json::encode($ua_code) . ', {"groups":"default","page_path":"' . $base_path . 'user/password"});');
$this
->drupalGet('user/password', [
'query' => [
'name' => 'foo@example.com',
],
]);
$this
->assertRaw('gtag("config", ' . Json::encode($ua_code) . ', {"groups":"default","page_path":"' . $base_path . 'user/password"});');
$this
->drupalGet('user/password');
$this
->assertNoRaw('"page_path":"' . $base_path . 'user/password"});');
// Test whether 403 forbidden tracking code is shown if user has no access.
$this
->drupalGet('admin');
$this
->assertResponse(403);
$this
->assertRaw($base_path . '403.html');
// Test whether 404 not found tracking code is shown on non-existent pages.
$this
->drupalGet($this
->randomMachineName(64));
$this
->assertResponse(404);
$this
->assertRaw($base_path . '404.html');
}