GoogleAnalyticsRolesTest.php in Google Analytics 8.3
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 $adminUser;
protected function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer google analytics',
];
$this->adminUser = $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
->assertRaw($ua_code);
$this
->drupalGet('admin');
$this
->assertResponse(403);
$this
->assertRaw('/403.html');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('');
$this
->assertRaw($ua_code);
$this
->drupalGet('admin');
$this
->assertNoRaw($ua_code);
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [
AccountInterface::AUTHENTICATED_ROLE => AccountInterface::AUTHENTICATED_ROLE,
])
->save();
$this
->drupalGet('');
$this
->assertRaw($ua_code);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoRaw($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
->assertRaw($ua_code);
$this
->drupalGet('admin');
$this
->assertResponse(403);
$this
->assertRaw('/403.html');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('');
$this
->assertRaw($ua_code);
$this
->drupalGet('admin');
$this
->assertNoRaw($ua_code);
$this
->config('google_analytics.settings')
->set('visibility.user_role_roles', [
AccountInterface::AUTHENTICATED_ROLE => AccountInterface::AUTHENTICATED_ROLE,
])
->save();
$this
->drupalGet('');
$this
->assertNoRaw($ua_code);
$this
->drupalGet('admin');
$this
->assertNoRaw($ua_code);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertRaw($ua_code);
}
}