GoogleAnalyticsUserFieldsTest.php in Google Analytics 8.2
File
tests/src/Functional/GoogleAnalyticsUserFieldsTest.php
View source
<?php
namespace Drupal\Tests\google_analytics\Functional;
use Drupal\Tests\BrowserTestBase;
class GoogleAnalyticsUserFieldsTest extends BrowserTestBase {
public static $modules = [
'google_analytics',
'field_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer user form display',
'opt-in or out of google analytics tracking',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->admin_user);
}
public function testGoogleAnalyticsUserFields() {
$ua_code = 'UA-123456-1';
$this
->config('google_analytics.settings')
->set('account', $ua_code)
->save();
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains(t('Google Analytics settings'));
$this
->config('google_analytics.settings')
->set('visibility.user_account_mode', 0)
->save();
$this
->drupalGet('user/' . $this->admin_user
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseNotContains(t('Google Analytics settings'));
$this
->config('google_analytics.settings')
->set('visibility.user_account_mode', 1)
->save();
$this
->drupalGet('user/' . $this->admin_user
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains(t('Users are tracked by default, but you are able to opt out.'));
$this
->config('google_analytics.settings')
->set('visibility.user_account_mode', 2)
->save();
$this
->drupalGet('user/' . $this->admin_user
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains(t('Users are <em>not</em> tracked by default, but you are able to opt in.'));
}
}