public function RequestTest::testOverrideGlobals

File

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

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testOverrideGlobals() {
  $request = new Request();
  $request
    ->initialize(array(
    'foo' => 'bar',
  ));

  // as the Request::overrideGlobals really work, it erase $_SERVER, so we must backup it
  $server = $_SERVER;
  $request
    ->overrideGlobals();
  $this
    ->assertEquals(array(
    'foo' => 'bar',
  ), $_GET);
  $request
    ->initialize(array(), array(
    'foo' => 'bar',
  ));
  $request
    ->overrideGlobals();
  $this
    ->assertEquals(array(
    'foo' => 'bar',
  ), $_POST);
  $this
    ->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
  $this
    ->startTrustingProxyData();
  $request->headers
    ->set('X_FORWARDED_PROTO', 'https');
  $this
    ->assertTrue($request
    ->isSecure());
  $this
    ->stopTrustingProxyData();
  $request
    ->overrideGlobals();
  $this
    ->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);

  // restore initial $_SERVER array
  $_SERVER = $server;
}