You are here

public function AdministerusersbyroleTest::setUp in Administer Users by Role 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/AdministerusersbyroleTest.php \Drupal\Tests\administerusersbyrole\Functional\AdministerusersbyroleTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/AdministerusersbyroleTest.php, line 21

Class

AdministerusersbyroleTest
Testing for administerusersbyrole module

Namespace

Drupal\Tests\administerusersbyrole\Functional

Code

public function setUp() {
  parent::setUp();
  $this
    ->createUserWithRole('noroles', array());
  $this
    ->createRolesAndUsers('alpha', FALSE);
  $this
    ->createRolesAndUsers('beta', TRUE);
  $this
    ->createUserWithRole('alphabeta', array(
    'alpha',
    'beta',
  ));

  // alphabeta_ed
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string($this->roles['alpha'], 'edit'),
    _administerusersbyrole_build_perm_string($this->roles['beta'], 'edit'),
  );
  $this->roles['alphabeta_ed'] = $this
    ->drupalCreateRole($perms, 'alphabeta_ed');
  $this
    ->createUserWithRole('alphabeta_ed', array(
    'alphabeta_ed',
  ));

  // all_editor
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string(AccountInterface::AUTHENTICATED_ROLE, 'edit'),
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($this->roles[$roleName], 'edit');
  }
  $this->roles['all_editor'] = $this
    ->drupalCreateRole($perms, 'all_editor');
  $this
    ->createUserWithRole('all_editor', array(
    'all_editor',
  ));

  // all_deletor
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string(AccountInterface::AUTHENTICATED_ROLE, 'cancel'),
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($roleID, 'cancel');
  }
  $this->roles['all_deletor'] = $this
    ->drupalCreateRole($perms, 'all_deletor');
  $this
    ->createUserWithRole('all_deletor', array(
    'all_deletor',
  ));

  // creator
  $perms = array(
    'access content',
    'create users',
  );
  $this->roles['creator'] = $this
    ->drupalCreateRole($perms, 'creator');
  $this
    ->createUserWithRole('creator', array(
    'creator',
  ));
}