protected function JsonapiResourceTest::setUp in JSON:API Resources 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ JsonapiResourceTest.php, line 60
Class
- JsonapiResourceTest
- Tests JSON:API Resource processors.
Namespace
Drupal\Tests\jsonapi_resources\FunctionalCode
protected function setUp() : void {
parent::setUp();
// 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 test bundles and and entity references and rebuild routes.
NodeType::create([
'name' => 'article',
'type' => 'article',
])
->save();
NodeType::create([
'name' => 'reminder',
'type' => 'reminder',
])
->save();
$this
->createEntityReferenceField('user', 'user', 'field_reminders', 'Reminders', 'node', 'default', [
'target_bundles' => [
'reminder' => 'reminder',
],
], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Create a comment field on the article bundle.
$this
->addDefaultCommentField('node', 'article', 'comment');
$this->container
->get('router.builder')
->rebuildIfNeeded();
// 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);
}