You are here

public function RequestTest::testCreate 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::testCreate()

@covers Symfony\Component\HttpFoundation\Request::create

File

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

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testCreate() {
  $request = Request::create('http://test.com/foo?bar=baz');
  $this
    ->assertEquals('http://test.com/foo?bar=baz', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('bar=baz', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com/foo', 'GET', array(
    'bar' => 'baz',
  ));
  $this
    ->assertEquals('http://test.com/foo?bar=baz', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('bar=baz', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com/foo?bar=foo', 'GET', array(
    'bar' => 'baz',
  ));
  $this
    ->assertEquals('http://test.com/foo?bar=baz', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('bar=baz', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('https://test.com/foo?bar=baz');
  $this
    ->assertEquals('https://test.com/foo?bar=baz', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('bar=baz', $request
    ->getQueryString());
  $this
    ->assertEquals(443, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertTrue($request
    ->isSecure());
  $request = Request::create('test.com:90/foo');
  $this
    ->assertEquals('http://test.com:90/foo', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('test.com', $request
    ->getHost());
  $this
    ->assertEquals('test.com:90', $request
    ->getHttpHost());
  $this
    ->assertEquals(90, $request
    ->getPort());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('https://test.com:90/foo');
  $this
    ->assertEquals('https://test.com:90/foo', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('test.com', $request
    ->getHost());
  $this
    ->assertEquals('test.com:90', $request
    ->getHttpHost());
  $this
    ->assertEquals(90, $request
    ->getPort());
  $this
    ->assertTrue($request
    ->isSecure());
  $request = Request::create('https://127.0.0.1:90/foo');
  $this
    ->assertEquals('https://127.0.0.1:90/foo', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('127.0.0.1', $request
    ->getHost());
  $this
    ->assertEquals('127.0.0.1:90', $request
    ->getHttpHost());
  $this
    ->assertEquals(90, $request
    ->getPort());
  $this
    ->assertTrue($request
    ->isSecure());
  $request = Request::create('https://[::1]:90/foo');
  $this
    ->assertEquals('https://[::1]:90/foo', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('[::1]', $request
    ->getHost());
  $this
    ->assertEquals('[::1]:90', $request
    ->getHttpHost());
  $this
    ->assertEquals(90, $request
    ->getPort());
  $this
    ->assertTrue($request
    ->isSecure());
  $request = Request::create('https://[::1]/foo');
  $this
    ->assertEquals('https://[::1]/foo', $request
    ->getUri());
  $this
    ->assertEquals('/foo', $request
    ->getPathInfo());
  $this
    ->assertEquals('[::1]', $request
    ->getHost());
  $this
    ->assertEquals('[::1]', $request
    ->getHttpHost());
  $this
    ->assertEquals(443, $request
    ->getPort());
  $this
    ->assertTrue($request
    ->isSecure());
  $json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
  $request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
  $this
    ->assertEquals($json, $request
    ->getContent());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com');
  $this
    ->assertEquals('http://test.com/', $request
    ->getUri());
  $this
    ->assertEquals('/', $request
    ->getPathInfo());
  $this
    ->assertEquals('', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com?test=1');
  $this
    ->assertEquals('http://test.com/?test=1', $request
    ->getUri());
  $this
    ->assertEquals('/', $request
    ->getPathInfo());
  $this
    ->assertEquals('test=1', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com:90/?test=1');
  $this
    ->assertEquals('http://test.com:90/?test=1', $request
    ->getUri());
  $this
    ->assertEquals('/', $request
    ->getPathInfo());
  $this
    ->assertEquals('test=1', $request
    ->getQueryString());
  $this
    ->assertEquals(90, $request
    ->getPort());
  $this
    ->assertEquals('test.com:90', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://username:password@test.com');
  $this
    ->assertEquals('http://test.com/', $request
    ->getUri());
  $this
    ->assertEquals('/', $request
    ->getPathInfo());
  $this
    ->assertEquals('', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertEquals('username', $request
    ->getUser());
  $this
    ->assertEquals('password', $request
    ->getPassword());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://username@test.com');
  $this
    ->assertEquals('http://test.com/', $request
    ->getUri());
  $this
    ->assertEquals('/', $request
    ->getPathInfo());
  $this
    ->assertEquals('', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertEquals('username', $request
    ->getUser());
  $this
    ->assertSame('', $request
    ->getPassword());
  $this
    ->assertFalse($request
    ->isSecure());
  $request = Request::create('http://test.com/?foo');
  $this
    ->assertEquals('/?foo', $request
    ->getRequestUri());
  $this
    ->assertEquals(array(
    'foo' => '',
  ), $request->query
    ->all());

  ## assume rewrite rule: (.*) --> app/app.php ; app/ is a symlink to a symfony web/ directory
  $request = Request::create('http://test.com/apparthotel-1234', 'GET', array(), array(), array(), array(
    'DOCUMENT_ROOT' => '/var/www/www.test.com',
    'SCRIPT_FILENAME' => '/var/www/www.test.com/app/app.php',
    'SCRIPT_NAME' => '/app/app.php',
    'PHP_SELF' => '/app/app.php/apparthotel-1234',
  ));
  $this
    ->assertEquals('http://test.com/apparthotel-1234', $request
    ->getUri());
  $this
    ->assertEquals('/apparthotel-1234', $request
    ->getPathInfo());
  $this
    ->assertEquals('', $request
    ->getQueryString());
  $this
    ->assertEquals(80, $request
    ->getPort());
  $this
    ->assertEquals('test.com', $request
    ->getHttpHost());
  $this
    ->assertFalse($request
    ->isSecure());
}