function EntityResourceTestBase::assertResourceNotAvailable

Same name in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertResourceNotAvailable()
  2. 10 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertResourceNotAvailable()
  3. 11.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertResourceNotAvailable()

Asserts that a resource is unavailable: 404, 406 if it has canonical route.

Parameters

\Drupal\Core\Url $url: URL to request.

array $request_options: Request options to apply.

1 call to EntityResourceTestBase::assertResourceNotAvailable()
EntityResourceTestBase::testGet in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a GET request for an entity, plus edge cases to ensure good DX.

File

core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php, line 1367

Class

EntityResourceTestBase
Defines a base class for testing all entity resources.

Namespace

Drupal\Tests\rest\Functional\EntityResource

Code

protected function assertResourceNotAvailable(Url $url, array $request_options) {
    $has_canonical_url = $this->entity
        ->hasLinkTemplate('canonical');
    $response = $this->request('GET', $url, $request_options);
    if (!$has_canonical_url) {
        $this->assertSame(404, $response->getStatusCode());
    }
    else {
        $this->assert406Response($response);
    }
}

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