3 namespace Drupal\Tests\user\Kernel\Views;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Tests\ViewTestData;
9 * Provides a common test base for user views tests.
11 abstract class UserKernelTestBase extends ViewsKernelTestBase {
18 public static $modules = ['user_test_views', 'user', 'system', 'field'];
21 * Users to use during this test.
25 protected $users = [];
28 * The entity storage for roles.
30 * @var \Drupal\user\RoleStorage
32 protected $roleStorage;
35 * The entity storage for users.
37 * @var \Drupal\user\UserStorage
39 protected $userStorage;
41 protected function setUp($import_test_views = TRUE) {
44 ViewTestData::createTestViews(get_class($this), ['user_test_views']);
46 $this->installEntitySchema('user');
48 $entity_manager = $this->container->get('entity.manager');
49 $this->roleStorage = $entity_manager->getStorage('user_role');
50 $this->userStorage = $entity_manager->getStorage('user');
54 * Set some test data for permission related tests.
56 protected function setupPermissionTestData() {
57 // Setup a role without any permission.
58 $this->roleStorage->create(['id' => 'authenticated'])
60 $this->roleStorage->create(['id' => 'no_permission'])
62 // Setup a role with just one permission.
63 $this->roleStorage->create(['id' => 'one_permission'])
65 user_role_grant_permissions('one_permission', ['administer permissions']);
66 // Setup a role with multiple permissions.
67 $this->roleStorage->create(['id' => 'multiple_permissions'])
69 user_role_grant_permissions('multiple_permissions', ['administer permissions', 'administer users', 'access user profiles']);
71 // Setup a user without an extra role.
72 $this->users[] = $account = $this->userStorage->create(['name' => $this->randomString()]);
74 // Setup a user with just the first role (so no permission beside the
75 // ones from the authenticated role).
76 $this->users[] = $account = $this->userStorage->create(['name' => 'first_role']);
77 $account->addRole('no_permission');
79 // Setup a user with just the second role (so one additional permission).
80 $this->users[] = $account = $this->userStorage->create(['name' => 'second_role']);
81 $account->addRole('one_permission');
83 // Setup a user with both the second and the third role.
84 $this->users[] = $account = $this->userStorage->create(['name' => 'second_third_role']);
85 $account->addRole('one_permission');
86 $account->addRole('multiple_permissions');