RealTimeNotificationsTest.php in TMGMT Translator Smartling 8.4
File
tests/src/Functional/RealTimeNotificationsTest.php
View source
<?php
namespace Drupal\Tests\tmgmt_smartling\Functional;
class RealTimeNotificationsTest extends SmartlingTestBase {
public function testScriptsAreIncludedIfUserHasPermission() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this
->loginAsAdmin();
$output = $this
->drupalGet('/admin/tmgmt/translators');
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-app.js') === FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-auth.js') === FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-database.js') === FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/js/notifications.js') === FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/css/notifications.css') === FALSE);
$this
->drupalLogout();
$this
->loginAsAdmin([
'see smartling messages',
]);
$output = $this
->drupalGet('/admin/tmgmt/translators');
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-app.js') !== FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-auth.js') !== FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-database.js') !== FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/js/notifications.js') !== FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/css/notifications.css') !== FALSE);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testScriptsAreNotIncludedIfUserHasPermissionAndFeatureIsDisabled() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this->smartlingPluginProviderSettings['settings[enable_notifications]'] = FALSE;
$this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this
->loginAsAdmin([
'see smartling messages',
]);
$output = $this
->drupalGet('/admin/tmgmt/translators');
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-app.js') === FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-auth.js') === FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-database.js') === FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/js/notifications.js') === FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/css/notifications.css') === FALSE);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testScriptsAreIncludedIfUserHasPermissionAndAtLeastOneProviderHasDisabledFeature() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this->smartlingPluginProviderSettings['settings[enable_notifications]'] = FALSE;
$this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this->smartlingPluginProviderSettings['settings[enable_notifications]'] = TRUE;
$this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this
->loginAsAdmin([
'see smartling messages',
]);
$output = $this
->drupalGet('/admin/tmgmt/translators');
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-app.js') !== FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-auth.js') !== FALSE);
$this
->assertTrue(strpos($output, 'https://www.gstatic.com/firebasejs/5.2.0/firebase-database.js') !== FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/js/notifications.js') !== FALSE);
$this
->assertTrue(strpos($output, '/modules/contrib/tmgmt_smartling/css/notifications.css') !== FALSE);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
}