You are here

protected function UserKernelTestBase::setupPermissionTestData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/Views/UserKernelTestBase.php \Drupal\user\Tests\Views\UserKernelTestBase::setupPermissionTestData()

Set some test data for permission related tests.

2 calls to UserKernelTestBase::setupPermissionTestData()
HandlerFieldPermissionTest::testFieldPermission in core/modules/user/src/Tests/Views/HandlerFieldPermissionTest.php
Tests the permission field handler output.
HandlerFilterPermissionTest::testFilterPermission in core/modules/user/src/Tests/Views/HandlerFilterPermissionTest.php
Tests the permission filter handler.

File

core/modules/user/src/Tests/Views/UserKernelTestBase.php, line 61
Contains \Drupal\user\Tests\Views\UserKernelTestBase.

Class

UserKernelTestBase
Provides a common test base for user views tests.

Namespace

Drupal\user\Tests\Views

Code

protected function setupPermissionTestData() {

  // Setup a role without any permission.
  $this->roleStorage
    ->create(array(
    'id' => 'authenticated',
  ))
    ->save();
  $this->roleStorage
    ->create(array(
    'id' => 'no_permission',
  ))
    ->save();

  // Setup a role with just one permission.
  $this->roleStorage
    ->create(array(
    'id' => 'one_permission',
  ))
    ->save();
  user_role_grant_permissions('one_permission', array(
    'administer permissions',
  ));

  // Setup a role with multiple permissions.
  $this->roleStorage
    ->create(array(
    'id' => 'multiple_permissions',
  ))
    ->save();
  user_role_grant_permissions('multiple_permissions', array(
    'administer permissions',
    'administer users',
    'access user profiles',
  ));

  // Setup a user without an extra role.
  $this->users[] = $account = $this->userStorage
    ->create([
    'name' => $this
      ->randomString(),
  ]);
  $account
    ->save();

  // Setup a user with just the first role (so no permission beside the
  // ones from the authenticated role).
  $this->users[] = $account = $this->userStorage
    ->create(array(
    'name' => 'first_role',
  ));
  $account
    ->addRole('no_permission');
  $account
    ->save();

  // Setup a user with just the second role (so one additional permission).
  $this->users[] = $account = $this->userStorage
    ->create(array(
    'name' => 'second_role',
  ));
  $account
    ->addRole('one_permission');
  $account
    ->save();

  // Setup a user with both the second and the third role.
  $this->users[] = $account = $this->userStorage
    ->create(array(
    'name' => 'second_third_role',
  ));
  $account
    ->addRole('one_permission');
  $account
    ->addRole('multiple_permissions');
  $account
    ->save();
}