.../EntityResource/EntityResourceTestBase.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 6ec50fc..df66131 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -596,7 +596,8 @@ public function testPost() { $request_options = []; - // DX: 404 when resource not provisioned. HTML because no ?_format. + // DX: 404 when resource not provisioned. HTML response because missing + // ?_format query string. $response = $this->request('POST', $url, $request_options); $this->assertSame(404, $response->getStatusCode()); $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type')); @@ -615,7 +616,8 @@ public function testPost() { $url->setOption('query', []); - // DX: 415 when no Content-Type request header. HTML because no ?_format. + // DX: 415 when no Content-Type request header. HTML response because + // missing ?_format query string. $response = $this->request('POST', $url, $request_options); $this->assertSame(415, $response->getStatusCode()); $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type')); @@ -772,7 +774,8 @@ public function testPatch() { $request_options = []; - // DX: 405 if canonical route, 404 for non canonical. HTML because no ?_format. + // DX: 404 when resource not provisioned, 405 if canonical route. Plain text + // or HTML response because missing ?_format query string. $response = $this->request('PATCH', $url, $request_options); if ($has_canonical_url) { $this->assertSame(405, $response->getStatusCode()); @@ -788,11 +791,10 @@ public function testPatch() { $url->setOption('query', ['_format' => static::$format]); - // DX: 405 when resource not provisioned. 404 for non canonical. + // DX: 404 when resource not provisioned, 405 if canonical route. $response = $this->request('PATCH', $url, $request_options); if ($has_canonical_url) { - $this->assertSame(405, $response->getStatusCode()); - $this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow')); + $this->assertResourceErrorResponse(405, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response); } else { $this->assertResourceErrorResponse(404, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response); @@ -967,7 +969,8 @@ public function testDelete() { $request_options = []; - // DX: 405 when resource not provisioned. 404 for non canonical. + // DX: 404 when resource not provisioned, but 405 if canonical route. Plain + // text or HTML response because missing ?_format query string. $response = $this->request('DELETE', $url, $request_options); if ($has_canonical_url) { $this->assertSame(405, $response->getStatusCode()); @@ -979,14 +982,15 @@ public function testDelete() { $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type')); } + $url->setOption('query', ['_format' => static::$format]); - // DX: 405 when resource not provisioned. 404 for non canonical. + // DX: 404 when resource not provisioned, 405 if canonical route. $response = $this->request('DELETE', $url, $request_options); if ($has_canonical_url) { - $this->assertSame(405, $response->getStatusCode()); $this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow')); + $this->assertResourceErrorResponse(405, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response); } else { $this->assertResourceErrorResponse(404, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);