GoogleAnalyticsRolesTest.php in Google Analytics 8.2
File
tests/src/Functional/GoogleAnalyticsRolesTest.php
View source
<?php
namespace Drupal\Tests\google_analytics\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\BrowserTestBase;
class GoogleAnalyticsRolesTest extends BrowserTestBase {
public static $modules = [
'google_analytics',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer google analytics',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
}
public function testGoogleAnalyticsRolesTracking() {
$ua_code = 'UA-123456-4';
$this
->config('google_analytics.settings')
->set('account', $ua_code)
->save();
$this
->config('google_analytics.settings')
->set('visibility.user_role_mode', 0)
->save();
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [])
->save();
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
$this
->drupalGet('admin');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->responseContains('/403.html');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
$this
->drupalGet('admin');
$this
->assertSession()
->responseNotContains($ua_code);
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [
AccountInterface::AUTHENTICATED_ROLE => AccountInterface::AUTHENTICATED_ROLE,
])
->save();
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertSession()
->responseNotContains($ua_code);
$this
->config('google_analytics.settings')
->set('visibility.user_role_mode', 1)
->save();
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [])
->save();
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
$this
->drupalGet('admin');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->responseContains('/403.html');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
$this
->drupalGet('admin');
$this
->assertSession()
->responseNotContains($ua_code);
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [
AccountInterface::AUTHENTICATED_ROLE => AccountInterface::AUTHENTICATED_ROLE,
])
->save();
$this
->drupalGet('');
$this
->assertSession()
->responseNotContains($ua_code);
$this
->drupalGet('admin');
$this
->assertSession()
->responseNotContains($ua_code);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertSession()
->responseContains($ua_code);
}
}