function ResourceTestBase::setUp
Same name in this branch
- 9 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
Same name in other branches
- 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
- 8.9.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
- 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()
- 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
- 11.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
Overrides BrowserTestBase::setUp
2 calls to ResourceTestBase::setUp()
- ConfigEntityResourceTestBase::setUp in core/
modules/ jsonapi/ tests/ src/ Functional/ ConfigEntityResourceTestBase.php - FileUploadTest::setUp in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php
2 methods override ResourceTestBase::setUp()
- ConfigEntityResourceTestBase::setUp in core/
modules/ jsonapi/ tests/ src/ Functional/ ConfigEntityResourceTestBase.php - FileUploadTest::setUp in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php
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
public function setUp() {
parent::setUp();
$this->serializer = $this->container
->get('jsonapi.serializer');
$this->config('system.logging')
->set('error_level', ERROR_REPORTING_HIDE)
->save();
// 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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.