View source
<?php
namespace Drupal\Tests\google_analytics\Functional;
use Drupal\Tests\BrowserTestBase;
class GoogleAnalyticsStatusMessagesTest extends BrowserTestBase {
public static $modules = [
'google_analytics',
'google_analytics_test',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer google analytics',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
}
public function testGoogleAnalyticsStatusMessages() {
$ua_code = 'UA-123456-4';
$this
->config('google_analytics.settings')
->set('account', $ua_code)
->save();
$this
->config('google_analytics.settings')
->set('track.messages', [
'error' => 'error',
])
->save();
$this
->drupalPostForm('user/login', [], t('Log in'));
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Username field is required.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Password field is required.");');
$this
->drupalGet('google-analytics-test/drupal-messenger-add-message');
$this
->assertSession()
->responseNotContains('ga("send", "event", "Messages", "Status message", "Example status message.");');
$this
->assertSession()
->responseNotContains('ga("send", "event", "Messages", "Warning message", "Example warning message.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Example error message.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Example error message with html tags and link.");');
$this
->config('google_analytics.settings')
->set('track.messages', [
'status' => 'status',
'warning' => 'warning',
'error' => 'error',
])
->save();
$this
->drupalGet('google-analytics-test/drupal-messenger-add-message');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Status message", "Example status message.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Warning message", "Example warning message.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Example error message.");');
$this
->assertSession()
->responseContains('ga("send", "event", "Messages", "Error message", "Example error message with html tags and link.");');
}
}