diff --git a/core/modules/file/tests/src/Functional/DownloadTest.php b/core/modules/file/tests/src/Functional/DownloadTest.php index 79c17a37c6..704c9db190 100644 --- a/core/modules/file/tests/src/Functional/DownloadTest.php +++ b/core/modules/file/tests/src/Functional/DownloadTest.php @@ -75,26 +75,17 @@ protected function doPrivateFileTransferTest() { // Test that the file transferred correctly. $this->assertSame($contents, $this->getSession()->getPage()->getContent(), 'Contents of the file are correct.'); + $http_client = $this->getSession()->getDriver()->getClient()->getClient(); + // Deny access to all downloads via a -1 header. file_test_set_return('download', -1); - $http_client = \Drupal::httpClient(); - try { - $http_client->head($url); - $this->fail('Not correctly denied access to a file when file_test sets the header to -1.'); - } - catch (RequestException $e) { - $this->assertSame(403, $e->getCode()); - } + $response = $http_client->head($url, ['http_errors' => FALSE]); + $this->assertSame(403, $response->getStatusCode(), 'Correctly denied access to a file when file_test sets the header to -1.'); // Try non-existent file. $url = file_create_url('private://' . $this->randomMachineName()); - try { - $http_client->head($url); - $this->fail('Not correctly returned 404 response for a non-existent file.'); - } - catch (RequestException $e) { - $this->assertSame(404, $e->getCode()); - } + $response = $http_client->head($url, ['http_errors' => FALSE]); + $this->assertSame(404, $response->getStatusCode(), 'Correctly returned 404 response for a non-existent file.'); } /**