.../rest/tests/modules/rest_test/rest_test.services.yml | 4 ++++ .../src/Functional/EntityResource/EntityResourceTestBase.php | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/modules/rest/tests/modules/rest_test/rest_test.services.yml b/core/modules/rest/tests/modules/rest_test/rest_test.services.yml index d316cf6..85b418a 100644 --- a/core/modules/rest/tests/modules/rest_test/rest_test.services.yml +++ b/core/modules/rest/tests/modules/rest_test/rest_test.services.yml @@ -12,3 +12,7 @@ services: public: false tags: - { name: page_cache_request_policy } + rest_test.encoder.foobar: + class: Drupal\serialization\Encoder\JsonEncoder + tags: + - { name: encoder, format: foobar } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 3f5bcf4..9618f99 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -164,7 +164,7 @@ protected function provisionEntityResource($single_format = FALSE) { $this->resourceConfigStorage->delete($this->resourceConfigStorage->loadMultiple()); $format = $single_format ? [static::$format] - : [static::$format, 'xml']; + : [static::$format, 'foobar']; // It's possible to not have any authentication providers enabled, when // testing public (anonymous) usage of a REST resource. $auth = isset(static::$auth) ? [static::$auth] : []; @@ -485,10 +485,16 @@ public function testGet() { // DX: 406 because despite unauthorized, ?_format is not omittable. $url->setOption('query', []); $response = $this->request('GET', $url, $request_options); - $this->assertSame(406, $response->getStatusCode()); + if ($has_canonical_url) { + $this->assertSame(403, $response->getStatusCode()); + $this->assertSame(['HIT'], $response->getHeader('X-Drupal-Dynamic-Cache')); + } + else { + $this->assertSame(406, $response->getStatusCode()); + $this->assertSame(['UNCACHEABLE'], $response->getHeader('X-Drupal-Dynamic-Cache')); + } $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type')); $this->assertSame(static::$auth ? [] : ['MISS'], $response->getHeader('X-Drupal-Cache')); - $this->assertSame(['UNCACHEABLE'], $response->getHeader('X-Drupal-Dynamic-Cache')); // DX: 403 because unauthorized. $url->setOption('query', ['_format' => static::$format]); $response = $this->request('GET', $url, $request_options);