You are here

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

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

File

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

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testGetUriForPath() {
  $request = Request::create('http://test.com/foo?bar=baz');
  $this
    ->assertEquals('http://test.com/some/path', $request
    ->getUriForPath('/some/path'));
  $request = Request::create('http://test.com:90/foo?bar=baz');
  $this
    ->assertEquals('http://test.com:90/some/path', $request
    ->getUriForPath('/some/path'));
  $request = Request::create('https://test.com/foo?bar=baz');
  $this
    ->assertEquals('https://test.com/some/path', $request
    ->getUriForPath('/some/path'));
  $request = Request::create('https://test.com:90/foo?bar=baz');
  $this
    ->assertEquals('https://test.com:90/some/path', $request
    ->getUriForPath('/some/path'));
  $server = array();

  // Standard Request on non default PORT
  // http://host:8080/index.php/path/info?query=string
  $server['HTTP_HOST'] = 'host:8080';
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '8080';
  $server['QUERY_STRING'] = 'query=string';
  $server['REQUEST_URI'] = '/index.php/path/info?query=string';
  $server['SCRIPT_NAME'] = '/index.php';
  $server['PATH_INFO'] = '/path/info';
  $server['PATH_TRANSLATED'] = 'redirect:/index.php/path/info';
  $server['PHP_SELF'] = '/index_dev.php/path/info';
  $server['SCRIPT_FILENAME'] = '/some/where/index.php';
  $request = new Request();
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://host:8080/index.php/some/path', $request
    ->getUriForPath('/some/path'), '->getUriForPath() with non default port');

  // Use std port number
  $server['HTTP_HOST'] = 'host';
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '80';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://host/index.php/some/path', $request
    ->getUriForPath('/some/path'), '->getUriForPath() with default port');

  // Without HOST HEADER
  unset($server['HTTP_HOST']);
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '80';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://servername/index.php/some/path', $request
    ->getUriForPath('/some/path'), '->getUriForPath() with default port without HOST_HEADER');

  // Request with URL REWRITING (hide index.php)
  //   RewriteCond %{REQUEST_FILENAME} !-f
  //   RewriteRule ^(.*)$ index.php [QSA,L]
  // http://host:8080/path/info?query=string
  $server = array();
  $server['HTTP_HOST'] = 'host:8080';
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '8080';
  $server['REDIRECT_QUERY_STRING'] = 'query=string';
  $server['REDIRECT_URL'] = '/path/info';
  $server['SCRIPT_NAME'] = '/index.php';
  $server['QUERY_STRING'] = 'query=string';
  $server['REQUEST_URI'] = '/path/info?toto=test&1=1';
  $server['SCRIPT_NAME'] = '/index.php';
  $server['PHP_SELF'] = '/index.php';
  $server['SCRIPT_FILENAME'] = '/some/where/index.php';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://host:8080/some/path', $request
    ->getUriForPath('/some/path'), '->getUri() with rewrite');

  // Use std port number
  //  http://host/path/info?query=string
  $server['HTTP_HOST'] = 'host';
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '80';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://host/some/path', $request
    ->getUriForPath('/some/path'), '->getUriForPath() with rewrite and default port');

  // Without HOST HEADER
  unset($server['HTTP_HOST']);
  $server['SERVER_NAME'] = 'servername';
  $server['SERVER_PORT'] = '80';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://servername/some/path', $request
    ->getUriForPath('/some/path'), '->getUriForPath() with rewrite, default port without HOST_HEADER');
  $this
    ->assertEquals('servername', $request
    ->getHttpHost());

  // with user info
  $server['PHP_AUTH_USER'] = 'fabien';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://servername/some/path', $request
    ->getUriForPath('/some/path'));
  $server['PHP_AUTH_PW'] = 'symfony';
  $request
    ->initialize(array(), array(), array(), array(), array(), $server);
  $this
    ->assertEquals('http://servername/some/path', $request
    ->getUriForPath('/some/path'));
}