You are here

public function ResourceTestBase::setUp in Drupal 8

Same name in this branch
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
  2. 8 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()

Overrides BrowserTestBase::setUp

1 call to ResourceTestBase::setUp()
FileUploadTest::setUp in core/modules/jsonapi/tests/src/Functional/FileUploadTest.php
1 method overrides ResourceTestBase::setUp()
FileUploadTest::setUp in core/modules/jsonapi/tests/src/Functional/FileUploadTest.php

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 218

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function setUp() {
  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);
}