function ResourceTestBase::setUp

Same name in this branch
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
  2. 8.9.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
  3. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
  4. 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()
  5. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::setUp()
  6. 11.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::setUp()

Overrides BrowserTestBase::setUp

7 calls to ResourceTestBase::setUp()
DbLogResourceTest::setUp in core/modules/hal/tests/src/Functional/dblog/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

7 methods override ResourceTestBase::setUp()
DbLogResourceTest::setUp in core/modules/hal/tests/src/Functional/dblog/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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.