function BinaryFileResponseTest::testCalculatedContentType

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Http/BinaryFileResponseTest.php \Drupal\KernelTests\Core\Http\BinaryFileResponseTest::testCalculatedContentType()
  2. main core/tests/Drupal/KernelTests/Core/Http/BinaryFileResponseTest.php \Drupal\KernelTests\Core\Http\BinaryFileResponseTest::testCalculatedContentType()

Test the content type generated by Drupal is correct.

Attributes

#[DataProvider('providerTestCalculatedContentType')]

File

core/tests/Drupal/KernelTests/Core/Http/BinaryFileResponseTest.php, line 28

Class

BinaryFileResponseTest
Tests the headers added by BinaryFileResponse.

Namespace

Drupal\KernelTests\Core\Http

Code

public function testCalculatedContentType($path, $content_type) : void {
  $query = [
    'relative_file_url' => $path,
  ];
  $request = Request::create('/binary_file_response_test/download', 'GET', $query);
  $response = \Drupal::service('http_kernel')->handle($request);
  $response->prepare($request);
  $this->assertSame($content_type, current(explode(';', $response->headers
    ->get('Content-Type'))));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.