protected function ResourceTestBase::setUp in Drupal 10
Same name in this branch
- 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
- 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 219
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function setUp() : void {
parent::setUp();
$this->serializer = $this->container
->get('jsonapi.serializer');
// Ensure the anonymous user role has no permissions at all.
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
foreach ($user_role
->getPermissions() as $permission) {
$user_role
->revokePermission($permission);
}
$user_role
->save();
assert([] === $user_role
->getPermissions(), 'The anonymous user role has no permissions at all.');
// Ensure the authenticated user role has no permissions at all.
$user_role = Role::load(RoleInterface::AUTHENTICATED_ID);
foreach ($user_role
->getPermissions() as $permission) {
$user_role
->revokePermission($permission);
}
$user_role
->save();
assert([] === $user_role
->getPermissions(), 'The authenticated user role has no permissions at all.');
// Create an account, which tests will use. Also ensure the @current_user
// service this account, to ensure certain access check logic in tests works
// as expected.
$this->account = $this
->createUser();
$this->container
->get('current_user')
->setAccount($this->account);
// Create an entity.
$entity_type_manager = $this->container
->get('entity_type.manager');
$this->entityStorage = $entity_type_manager
->getStorage(static::$entityTypeId);
$this->uuidKey = $entity_type_manager
->getDefinition(static::$entityTypeId)
->getKey('uuid');
$this->entity = $this
->setUpFields($this
->createEntity(), $this->account);
$this->resourceType = $this->container
->get('jsonapi.resource_type.repository')
->getByTypeName(static::$resourceTypeName);
}