You are here

public function RequestTest::testCreateFromGlobals in Zircon Profile 8

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

@dataProvider provideOverloadedMethods

File

vendor/symfony/http-foundation/Tests/RequestTest.php, line 1055

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testCreateFromGlobals($method) {
  $normalizedMethod = strtoupper($method);
  $_GET['foo1'] = 'bar1';
  $_POST['foo2'] = 'bar2';
  $_COOKIE['foo3'] = 'bar3';
  $_FILES['foo4'] = array(
    'bar4',
  );
  $_SERVER['foo5'] = 'bar5';
  $request = Request::createFromGlobals();
  $this
    ->assertEquals('bar1', $request->query
    ->get('foo1'), '::fromGlobals() uses values from $_GET');
  $this
    ->assertEquals('bar2', $request->request
    ->get('foo2'), '::fromGlobals() uses values from $_POST');
  $this
    ->assertEquals('bar3', $request->cookies
    ->get('foo3'), '::fromGlobals() uses values from $_COOKIE');
  $this
    ->assertEquals(array(
    'bar4',
  ), $request->files
    ->get('foo4'), '::fromGlobals() uses values from $_FILES');
  $this
    ->assertEquals('bar5', $request->server
    ->get('foo5'), '::fromGlobals() uses values from $_SERVER');
  unset($_GET['foo1'], $_POST['foo2'], $_COOKIE['foo3'], $_FILES['foo4'], $_SERVER['foo5']);
  $_SERVER['REQUEST_METHOD'] = $method;
  $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  $request = RequestContentProxy::createFromGlobals();
  $this
    ->assertEquals($normalizedMethod, $request
    ->getMethod());
  $this
    ->assertEquals('mycontent', $request->request
    ->get('content'));
  unset($_SERVER['REQUEST_METHOD'], $_SERVER['CONTENT_TYPE']);
  Request::createFromGlobals();
  Request::enableHttpMethodParameterOverride();
  $_POST['_method'] = $method;
  $_POST['foo6'] = 'bar6';
  $_SERVER['REQUEST_METHOD'] = 'PoSt';
  $request = Request::createFromGlobals();
  $this
    ->assertEquals($normalizedMethod, $request
    ->getMethod());
  $this
    ->assertEquals('POST', $request
    ->getRealMethod());
  $this
    ->assertEquals('bar6', $request->request
    ->get('foo6'));
  unset($_POST['_method'], $_POST['foo6'], $_SERVER['REQUEST_METHOD']);
  $this
    ->disableHttpMethodParameterOverride();
}