diff --git a/core/modules/hal/tests/src/Functional/EntityResource/File/FileUploadHalJsonTestBase.php b/core/modules/hal/tests/src/Functional/EntityResource/File/FileUploadHalJsonTestBase.php index 1a02530807..735e7a5ece 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/File/FileUploadHalJsonTestBase.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/File/FileUploadHalJsonTestBase.php @@ -28,8 +28,8 @@ /** * {@inheritdoc} */ - protected function getExpectedNormalizedEntity($fid = 1, $actual_filename = 'example.txt') { - $normalization = parent::getExpectedNormalizedEntity($fid, $actual_filename); + protected function getExpectedNormalizedEntity($fid = 1, $expected_filename = 'example.txt') { + $normalization = parent::getExpectedNormalizedEntity($fid, $expected_filename); // Cannot use applyHalFieldNormalization() as it uses the $entity property // from the test class, which in the case of file upload tests, is the diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 2ee1be7dda..3de5839d3a 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -226,10 +226,8 @@ protected function denormalizeRequestData(Request $request, ResourceInterface $r /** * Prepares the REST response. * - * @TODO is there are requirement that REST resources MUST return a response - * object? If so, we can type hint that here. - * - * @param $response + * @param \Drupal\rest\ResourceResponseInterface $response + * The REST resource response. * @param \Drupal\rest\RestResourceConfigInterface $resource_config * The REST resource config entity. * diff --git a/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php b/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php index aa9d0543c2..9b3d683e09 100644 --- a/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php @@ -139,26 +139,26 @@ public function testPostFileUpload() { // The wrong content type header should return a 415 code. $response = $this->fileRequest($uri, $this->testFileData, ['Content-Type' => static::$mimeType]); - $this->assertSame(415, $response->getStatusCode()); + $this->assertResourceErrorResponse(415, sprintf('No route found that matches "Content-Type: %s"', static::$mimeType), $response); // An empty Content-Disposition header should return a 400. $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => '']); - $this->assertSame(400, $response->getStatusCode()); + $this->assertResourceErrorResponse(400, '"Content-Disposition" header is required. A file name in the format "filename=FILENAME" must be provided', $response); // An empty filename with a context in the Content-Disposition header should // return a 400. $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'file; filename=""']); - $this->assertSame(400, $response->getStatusCode()); + $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided', $response); // An empty filename without a context in the Content-Disposition header // should return a 400. $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'filename=""']); - $this->assertSame(400, $response->getStatusCode()); + $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided', $response); // An invalid key-value pair in the Content-Disposition header should return // a 400. $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'not_a_filename="example.txt"']); - $this->assertSame(400, $response->getStatusCode()); + $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided', $response); // This request will have the default 'application/octet-stream' content // type header. @@ -175,7 +175,7 @@ public function testPostFileUpload() { } /** - * Tests using the file upload POST route with a duplicate file. + * Tests using the file upload POST route with a duplicate file name. * * A new file should be created with a suffixed name. */ @@ -200,7 +200,7 @@ public function testPostFileUploadDuplicateFile() { $this->assertSame(201, $response->getStatusCode()); - // Loading expected normalized data for file 2 and duplicate file. + // Loading expected normalized data for file 2, the duplicate file. $expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt'); $this->assertResponseData($expected, $response); @@ -251,7 +251,7 @@ public function testFileUploadInvalidFileType() { // Test with a JSON file. $response = $this->fileRequest($uri, '{"test":123}', ['Content-Disposition' => 'filename="example.json"']); - $this->assertSame(422, $response->getStatusCode()); + $this->assertResourceErrorResponse(422, "Unprocessable Entity: file validation failed.\nOnly files with the following extensions are allowed: txt.", $response); // Make sure that no file was saved. $this->assertEmpty(File::load(1)); @@ -278,7 +278,7 @@ public function testFileUploadLargerFileSize() { // Generate a string larger than the 50 byte limit set. $response = $this->fileRequest($uri, $this->randomString(100)); - $this->assertSame(422, $response->getStatusCode()); + $this->assertResourceErrorResponse(422, "Unprocessable Entity: file validation failed.\nThe file is 100 bytes exceeding the maximum file size of 50 bytes.", $response); // Make sure that no file was saved. $this->assertEmpty(File::load(1)); @@ -304,13 +304,13 @@ protected function getExpectedUnauthorizedAccessMessage($method) { * * @param int $fid * The file ID to load and create normalized data for. - * @param string $actual_filename - * The actual filename for the stored file. + * @param string $expected_filename + * The expected filename for the stored file. * * @return array * The expected normalized data array. */ - protected function getExpectedNormalizedEntity($fid = 1, $actual_filename = 'example.txt') { + protected function getExpectedNormalizedEntity($fid = 1, $expected_filename = 'example.txt') { $author = User::load(static::$auth ? $this->account->id() : 0); $file = File::load($fid); @@ -345,7 +345,7 @@ protected function getExpectedNormalizedEntity($fid = 1, $actual_filename = 'exa ], 'uri' => [ [ - 'value' => 'public://foobar/' . $actual_filename, + 'value' => 'public://foobar/' . $expected_filename, ], ], 'filemime' => [