public function BinaryFileResponseTest::testRequests

@dataProvider provideRanges

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php, line 53

Class

BinaryFileResponseTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testRequests($requestRange, $offset, $length, $responseRange) {
  $response = BinaryFileResponse::create(__DIR__ . '/File/Fixtures/test.gif')
    ->setAutoEtag();

  // do a request to get the ETag
  $request = Request::create('/');
  $response
    ->prepare($request);
  $etag = $response->headers
    ->get('ETag');

  // prepare a request for a range of the testing file
  $request = Request::create('/');
  $request->headers
    ->set('If-Range', $etag);
  $request->headers
    ->set('Range', $requestRange);
  $file = fopen(__DIR__ . '/File/Fixtures/test.gif', 'r');
  fseek($file, $offset);
  $data = fread($file, $length);
  fclose($file);
  $this
    ->expectOutputString($data);
  $response = clone $response;
  $response
    ->prepare($request);
  $response
    ->sendContent();
  $this
    ->assertEquals(206, $response
    ->getStatusCode());
  $this
    ->assertEquals('binary', $response->headers
    ->get('Content-Transfer-Encoding'));
  $this
    ->assertEquals($responseRange, $response->headers
    ->get('Content-Range'));
}