public function ResourceTestBase::setUp in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ ResourceTestBase.php, line 163
Class
- ResourceTestBase
- Subclass this for every JSON API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function setUp() {
parent::setUp();
$this->serializer = $this->container
->get('jsonapi.serializer_do_not_use_removal_imminent');
// 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 uses this account, to ensure the @jsonapi.entity.to_jsonapi
// service that we use to generate expectations matching that of this user.
$this->account = $this
->createUser();
$this->container
->get('current_user')
->setAccount($this->account);
// Create an entity.
$this->entityStorage = $this->container
->get('entity_type.manager')
->getStorage(static::$entityTypeId);
$this->entity = $this
->setUpFields($this
->createEntity(), $this->account);
}