public function CounterTest::testCounterCodeRolesSettings in Yandex.Metrics 8.2
Test Yandex.Metrics role specific settings.
File
- src/
Tests/ CounterTest.php, line 189 - Contains \Drupal\yandex_metrics\Tests\CounterTest.
Class
- CounterTest
- Tests of functionality and settings of Yandex.Metrics Counter module.
Namespace
Drupal\yandex_metrics\TestsCode
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[' . DRUPAL_ANONYMOUS_RID . ']'] = TRUE;
$this
->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));
// Check if counter doesn't exist for admin.
$this
->drupalGet('');
$this
->checkNoCounter();
// Check if counter exists for anonymous user.
$this
->drupalLogout();
$this
->drupalGet('');
$this
->checkCounter();
// Check if counter doesn't exist for normal user.
$this
->drupalLogin($this->regular_user);
$this
->drupalGet('');
$this
->checkNoCounter();
// Add Yandex.Metrics counter code for all roles except administrators.
$this
->drupalLogin($this->admin_user);
$admin_role_id = array_values(array_diff($this->admin_user
->getRoles(), array(
DRUPAL_AUTHENTICATED_RID,
)))[0];
$edit = array();
$edit['visibility_roles'] = 1;
$edit['roles[' . $admin_role_id . ']'] = $admin_role_id;
// Unset previous setting for anonymous role.
$edit['roles[' . DRUPAL_ANONYMOUS_RID . ']'] = FALSE;
$this
->drupalPostForm('admin/config/system/yandex_metrics', $edit, t('Save configuration'));
// Check if counter doesn't exist for admin.
$this
->drupalGet('');
$this
->checkNoCounter();
// Check if counter exists for anonymous user.
$this
->drupalLogout();
$this
->drupalGet('');
$this
->checkCounter();
// Check if counter exists for normal user.
$this
->drupalLogin($this->regular_user);
$this
->drupalGet('');
$this
->checkCounter();
}