public function CounterTest::testCounterCodeRolesSettings in Yandex.Metrics 8.3
Test Yandex.Metrics role specific settings.
File
- tests/
src/ Functional/ CounterTest.php, line 184 - Contains \Drupal\yandex_metrics\Tests\CounterTest.
Class
- CounterTest
- Tests of functionality and settings of Yandex.Metrics Counter module.
Namespace
Drupal\Tests\yandex_metrics\FunctionalCode
public function testCounterCodeRolesSettings() {
// Login as administrator.
$this
->drupalLogin($this->admin_user);
// Add Yandex.Metrica counter code only for anonymous users.
$edit = array();
$edit["counter_code"] = $this->yandex_metrics_code;
$edit['roles[' . AccountInterface::ANONYMOUS_ROLE . ']'] = AccountInterface::ANONYMOUS_ROLE;
$this
->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));
// Check if counter doesn't exist for admin.
$this
->drupalGet('node');
$this
->checkNoCounter();
// Check if counter exists for anonymous user.
$this
->drupalLogout();
$this
->drupalGet('node');
$this
->checkCounter();
// Check if counter doesn't exist for normal user.
$this
->drupalLogin($this->regular_user);
$this
->drupalGet('node');
$this
->checkNoCounter();
// Add Yandex.Metrics counter code for all roles except administrators.
$this
->drupalLogin($this->admin_user);
$admin_role_name = array_values(array_diff($this->admin_user
->getRoles(), array(
AccountInterface::ANONYMOUS_ROLE,
AccountInterface::AUTHENTICATED_ROLE,
)))[0];
$edit = array();
$edit['visibility_roles'] = 1;
$edit['roles[' . $admin_role_name . ']'] = $admin_role_name;
// Unset previous setting for anonymous role.
$edit['roles[' . AccountInterface::ANONYMOUS_ROLE . ']'] = FALSE;
$this
->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));
// Check if counter doesn't exist for admin.
$this
->drupalGet('node');
$this
->checkNoCounter();
// Check if counter exists for anonymous user.
$this
->drupalLogout();
$this
->drupalGet('node');
$this
->checkCounter();
// Check if counter exists for normal user.
$this
->drupalLogin($this->regular_user);
$this
->drupalGet('node');
$this
->checkCounter();
}