.../Functional/EntityResource/EntityResourceTestBase.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 232986b..0e915ce 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -86,11 +86,21 @@ public function testGet() { $this->provisionEntityResource(); /** @var \Psr\Http\Message\ResponseInterface $response */ - $url = $this->entity->toUrl(); + $has_canonical_url = $this->entity->hasLinkTemplate('canonical'); + $url = $has_canonical_url ? $this->entity->toUrl() : Url::fromUri('base:entity/' . static::$entityType . '/' . $this->entity->id()); // Requesting without the appropriate ?_format query argument. - $response = $this->httpClient->get($url->toString()); - $this->assertSame(200, $response->getStatusCode()); + try { + $response = $this->httpClient->get($url->toString()); + } catch (ClientException $e) { + if (!$has_canonical_url) { + $response = $e->getResponse(); + $this->assertSame(406, $response->getStatusCode()); + } + } + if ($has_canonical_url) { + $this->assertSame(200, $response->getStatusCode()); + } $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type')); $url->setOption('query', ['_format' => static::$format]);