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/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
  2. 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()

Overrides BrowserTestBase::setUp

6 calls to ResourceTestBase::setUp()
DbLogResourceTest::setUp in core/modules/dblog/tests/src/Functional/DbLogResourceTest.php
EntityResourceTestBase::setUp in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
FileUploadResourceTestBase::setUp in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
LayoutRestTestBase::setUp in core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php
RestJsonApiUnsupported::setUp in core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php

... See full list

6 methods override ResourceTestBase::setUp()
DbLogResourceTest::setUp in core/modules/dblog/tests/src/Functional/DbLogResourceTest.php
EntityResourceTestBase::setUp in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
FileUploadResourceTestBase::setUp in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
LayoutRestTestBase::setUp in core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php
RestJsonApiUnsupported::setUp in core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php

... See full list

File

core/modules/rest/tests/src/Functional/ResourceTestBase.php, line 101

Class

ResourceTestBase
Subclass this for every REST resource, every format and every auth provider.

Namespace

Drupal\Tests\rest\Functional

Code

public function setUp() {
  parent::setUp();
  $this->serializer = $this->container
    ->get('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.');
  if (static::$auth !== FALSE) {

    // 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.
    $this->account = $this
      ->createUser();
  }
  else {

    // Otherwise, also create an account, so that any test involving User
    // entities will have the same user IDs regardless of authentication.
    $this
      ->createUser();
  }
  $this->resourceConfigStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('rest_resource_config');

  // Ensure there's a clean slate: delete all REST resource config entities.
  $this->resourceConfigStorage
    ->delete($this->resourceConfigStorage
    ->loadMultiple());
  $this
    ->refreshTestStateAfterRestConfigChange();
}