You are here

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

File

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

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testGetHost() {
  $request = new Request();
  $request
    ->initialize(array(
    'foo' => 'bar',
  ));
  $this
    ->assertEquals('', $request
    ->getHost(), '->getHost() return empty string if not initialized');
  $request
    ->initialize(array(), array(), array(), array(), array(), array(
    'HTTP_HOST' => 'www.example.com',
  ));
  $this
    ->assertEquals('www.example.com', $request
    ->getHost(), '->getHost() from Host Header');

  // Host header with port number
  $request
    ->initialize(array(), array(), array(), array(), array(), array(
    'HTTP_HOST' => 'www.example.com:8080',
  ));
  $this
    ->assertEquals('www.example.com', $request
    ->getHost(), '->getHost() from Host Header with port number');

  // Server values
  $request
    ->initialize(array(), array(), array(), array(), array(), array(
    'SERVER_NAME' => 'www.example.com',
  ));
  $this
    ->assertEquals('www.example.com', $request
    ->getHost(), '->getHost() from server name');
  $request
    ->initialize(array(), array(), array(), array(), array(), array(
    'SERVER_NAME' => 'www.example.com',
    'HTTP_HOST' => 'www.host.com',
  ));
  $this
    ->assertEquals('www.host.com', $request
    ->getHost(), '->getHost() value from Host header has priority over SERVER_NAME ');
}