You are here

public function BinaryFileResponseTest::testRequests in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php \Symfony\Component\HttpFoundation\Tests\BinaryFileResponseTest::testRequests()

@dataProvider provideRanges

File

vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php, line 55

Class

BinaryFileResponseTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testRequests($requestRange, $offset, $length, $responseRange) {
  $response = BinaryFileResponse::create(__DIR__ . '/File/Fixtures/test.gif', 200, array(
    'Content-Type' => 'application/octet-stream',
  ))
    ->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($responseRange, $response->headers
    ->get('Content-Range'));
}