core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php | 3 +++ .../tests/src/Functional/EntityResource/EntityResourceTestBase.php | 7 +++---- core/tests/Drupal/FunctionalTests/Routing/DefaultFormatTest.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php index dbfb801..1586db8 100644 --- a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php +++ b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php @@ -18,6 +18,9 @@ public function filter(RouteCollection $collection, Request $request) { // Determine the request format. $default_format = static::getDefaultFormat($collection); $format = $request->getRequestFormat($default_format); + if (is_null($request->getRequestFormat(NULL))) { + $request->setRequestFormat($format); + } $routes_with_requirement = []; $routes_without_requirement = []; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 257c580..8f48a0c 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -470,17 +470,16 @@ public function testGet() { // First: single format. Drupal will automatically pick the only format. $this->provisionEntityResource(TRUE); + $expected_403_cacheability = $this->getExpectedUnauthorizedAccessCacheability(); // DX: 403 because unauthorized single-format route, ?_format is omittable. $url->setOption('query', []); $response = $this->request('GET', $url, $request_options); - $this->assertSame(403, $response->getStatusCode()); - $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type')); + $this->assertResourceErrorResponse(403, FALSE, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), static::$auth ? FALSE : 'MISS', 'MISS'); $this->assertSame(static::$auth ? [] : ['MISS'], $response->getHeader('X-Drupal-Cache')); // DX: 403 because unauthorized. $url->setOption('query', ['_format' => static::$format]); $response = $this->request('GET', $url, $request_options); - $expected_403_cacheability = $this->getExpectedUnauthorizedAccessCacheability(); - $this->assertResourceErrorResponse(403, FALSE, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), static::$auth ? FALSE : 'MISS', 'MISS'); + $this->assertResourceErrorResponse(403, FALSE, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), static::$auth ? FALSE : 'MISS', 'HIT'); // Then, what we'll use for the remainder of the test: multiple formats. $this->provisionEntityResource(); diff --git a/core/tests/Drupal/FunctionalTests/Routing/DefaultFormatTest.php b/core/tests/Drupal/FunctionalTests/Routing/DefaultFormatTest.php index fba590e..7a05991 100644 --- a/core/tests/Drupal/FunctionalTests/Routing/DefaultFormatTest.php +++ b/core/tests/Drupal/FunctionalTests/Routing/DefaultFormatTest.php @@ -20,7 +20,7 @@ public function testFoo() { $this->assertSame('MISS', $this->drupalGetHeader('X-Drupal-Cache')); $this->drupalGet('/default_format_test/machine'); - $this->assertSame('format:html', $this->getSession()->getPage()->getContent()); + $this->assertSame('format:json', $this->getSession()->getPage()->getContent()); $this->assertSame('MISS', $this->drupalGetHeader('X-Drupal-Cache')); }