public function testHttpRequestHttpHost()
{
$this->specify("http host with empty server values does not return empty string", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTP_HOST', '');
$this->setServerVar('SERVER_NAME', '');
$this->setServerVar('SERVER_ADDR', '');
expect(is_string($request->getHttpHost()))->true();
expect($request->getHttpHost())->equals('');
});
$this->specify("http host without required server values does not return empty string", function () {
$request = $this->getRequestObject();
unset($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_ADDR']);
expect(is_string($request->getHttpHost()))->true();
expect($request->getHttpHost())->equals('');
});
$this->specify("The Request::getHttpHost without strict validation does not return expected host", function () {
$request = $this->getRequestObject();
$this->setServerVar('SERVER_NAME', 'host@name');
expect($request->getHttpHost())->equals('host@name');
});
$this->specify("http host without http does not contain correct data", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTPS', 'off');
$this->setServerVar('SERVER_NAME', 'localhost');
$this->setServerVar('SERVER_PORT', 80);
expect($request->getHttpHost())->equals('localhost');
});
$this->specify("http host with http does not contain correct data", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTPS', 'on');
$this->setServerVar('SERVER_NAME', 'localhost');
$this->setServerVar('SERVER_PORT', 80);
expect($request->getHttpHost())->equals('localhost');
});
$this->specify("http host with https and 443 port does not contain correct data", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTPS', 'on');
$this->setServerVar('SERVER_NAME', 'localhost');
$this->setServerVar('SERVER_PORT', 443);
expect($request->getHttpHost())->equals('localhost');
});
$this->specify("http host with SERVER_ADDR value does not return expected host name", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTP_HOST', '');
$this->setServerVar('SERVER_NAME', '');
$this->setServerVar('SERVER_ADDR', '8.8.8.8');
expect($request->getHttpHost())->equals('8.8.8.8');
});
$this->specify("http host with SERVER_NAME value does not return expected host name", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTP_HOST', '');
$this->setServerVar('SERVER_NAME', 'some.domain');
$this->setServerVar('SERVER_ADDR', '8.8.8.8');
expect($request->getHttpHost())->equals('some.domain');
});
$this->specify("http host with HTTP_HOST value does not return expected host name", function () {
$request = $this->getRequestObject();
$this->setServerVar('HTTP_HOST', 'example.com');
$this->setServerVar('SERVER_NAME', 'some.domain');
$this->setServerVar('SERVER_ADDR', '8.8.8.8');
expect($request->getHttpHost())->equals('example.com');
});
}