public function RequestTest::testOverrideGlobals in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/http-foundation/Tests/RequestTest.php \Symfony\Component\HttpFoundation\Tests\RequestTest::testOverrideGlobals()
File
- vendor/
symfony/ http-foundation/ Tests/ RequestTest.php, line 1096
Class
Namespace
Symfony\Component\HttpFoundation\TestsCode
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);
$request->headers
->set('X_FORWARDED_PROTO', 'https');
Request::setTrustedProxies(array(
'1.1.1.1',
));
$this
->assertFalse($request
->isSecure());
$request->server
->set('REMOTE_ADDR', '1.1.1.1');
$this
->assertTrue($request
->isSecure());
Request::setTrustedProxies(array());
$request
->overrideGlobals();
$this
->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
$request->headers
->set('CONTENT_TYPE', 'multipart/form-data');
$request->headers
->set('CONTENT_LENGTH', 12345);
$request
->overrideGlobals();
$this
->assertArrayHasKey('CONTENT_TYPE', $_SERVER);
$this
->assertArrayHasKey('CONTENT_LENGTH', $_SERVER);
$request
->initialize(array(
'foo' => 'bar',
'baz' => 'foo',
));
$request->query
->remove('baz');
$request
->overrideGlobals();
$this
->assertEquals(array(
'foo' => 'bar',
), $_GET);
$this
->assertEquals('foo=bar', $_SERVER['QUERY_STRING']);
$this
->assertEquals('foo=bar', $request->server
->get('QUERY_STRING'));
// restore initial $_SERVER array
$_SERVER = $server;
}