diff core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line diff
--- a/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php	Thu Feb 28 13:11:55 2019 +0000
+++ b/core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php	Thu May 09 15:34:47 2019 +0100
@@ -254,7 +254,7 @@
     $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' => '']);
+    $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => FALSE]);
     $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
@@ -373,11 +373,13 @@
 
     $uri = Url::fromUri('base:' . static::$postUri);
 
-    $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'file; filename="example-✓.txt"']);
+    // It is important that the filename starts with a unicode character. See
+    // https://bugs.php.net/bug.php?id=77239.
+    $response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'file; filename="Èxample-✓.txt"']);
     $this->assertSame(201, $response->getStatusCode());
-    $expected = $this->getExpectedNormalizedEntity(1, 'example-✓.txt', TRUE);
+    $expected = $this->getExpectedNormalizedEntity(1, 'Èxample-✓.txt', TRUE);
     $this->assertResponseData($expected, $response);
-    $this->assertSame($this->testFileData, file_get_contents('public://foobar/example-✓.txt'));
+    $this->assertSame($this->testFileData, file_get_contents('public://foobar/Èxample-✓.txt'));
   }
 
   /**
@@ -658,7 +660,8 @@
    *   The file contents to send as the request body.
    * @param array $headers
    *   Additional headers to send with the request. Defaults will be added for
-   *   Content-Type and Content-Disposition.
+   *   Content-Type and Content-Disposition. In order to remove the defaults set
+   *   the header value to FALSE.
    *
    * @return \Psr\Http\Message\ResponseInterface
    */
@@ -667,12 +670,15 @@
     $url->setOption('query', ['_format' => static::$format]);
 
     $request_options = [];
-    $request_options[RequestOptions::HEADERS] = $headers + [
+    $headers = $headers + [
       // Set the required (and only accepted) content type for the request.
       'Content-Type' => 'application/octet-stream',
       // Set the required Content-Disposition header for the file name.
       'Content-Disposition' => 'file; filename="example.txt"',
     ];
+    $request_options[RequestOptions::HEADERS] = array_filter($headers, function ($value) {
+      return $value !== FALSE;
+    });
     $request_options[RequestOptions::BODY] = $file_contents;
     $request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions('POST'));