UserKernelTestBase.php in Drupal 10
File
core/modules/user/tests/src/Kernel/Views/UserKernelTestBase.php
View source
<?php
namespace Drupal\Tests\user\Kernel\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
abstract class UserKernelTestBase extends ViewsKernelTestBase {
protected static $modules = [
'user_test_views',
'user',
'system',
'field',
];
protected $users = [];
protected $roleStorage;
protected $userStorage;
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
ViewTestData::createTestViews(static::class, [
'user_test_views',
]);
$this
->installEntitySchema('user');
$entity_type_manager = $this->container
->get('entity_type.manager');
$this->roleStorage = $entity_type_manager
->getStorage('user_role');
$this->userStorage = $entity_type_manager
->getStorage('user');
}
protected function setupPermissionTestData() {
$this->roleStorage
->create([
'id' => 'authenticated',
'label' => 'Authenticated',
])
->save();
$this->roleStorage
->create([
'id' => 'no_permission',
'label' => 'No permission',
])
->save();
$this->roleStorage
->create([
'id' => 'one_permission',
'label' => '1 permission',
])
->save();
user_role_grant_permissions('one_permission', [
'administer permissions',
]);
$this->roleStorage
->create([
'id' => 'multiple_permissions',
'label' => 'Multiple permissions',
])
->save();
user_role_grant_permissions('multiple_permissions', [
'administer permissions',
'administer users',
'access user profiles',
]);
$this->users[] = $account = $this->userStorage
->create([
'name' => $this
->randomString(),
]);
$account
->save();
$this->users[] = $account = $this->userStorage
->create([
'name' => 'first_role',
]);
$account
->addRole('no_permission');
$account
->save();
$this->users[] = $account = $this->userStorage
->create([
'name' => 'second_role',
]);
$account
->addRole('one_permission');
$account
->save();
$this->users[] = $account = $this->userStorage
->create([
'name' => 'second_third_role',
]);
$account
->addRole('one_permission');
$account
->addRole('multiple_permissions');
$account
->save();
}
}