You are here

protected function EntityResourceTestBase::assertResourceNotAvailable in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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 1376

Class

EntityResourceTestBase
Even though there is the generic EntityResource, it's necessary for every entity type to have its own test, because they each have different fields, validation constraints, et cetera. It's not because the generic case works, that every case…

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);
  }
}