UrlTest: Add additional test cases

refs #12133
This commit is contained in:
Noah Hilverling 2016-10-19 13:12:55 +02:00
parent 1ff3149636
commit a84e0c4d84
1 changed files with 62 additions and 0 deletions

View File

@ -9,6 +9,68 @@ use Icinga\Test\BaseTestCase;
class UrlTest extends BaseTestCase
{
public function testWhetherFromPathCutsOfTheFirstCharOfThePathIfUrlIsInternalAndHasAUsernameInIt()
{
$this->getRequestMock()->shouldReceive('getServer')->with("SERVER_NAME")->andReturn('localhost')
->shouldReceive('getServer')->with("SERVER_PORT")->andReturn('8080');
$url = Url::fromPath('http://testusername:testpassword@localhost:8080/path/to/my/url.html');
$this->assertEquals(
'path/to/my/url.html',
$url->getPath(),
'Url::fromPath does not cut of the first char of path if the url is internal and has a username in it'
);
}
public function testWhetherGetAbsoluteUrlReturnsTheBasePathIfUrlIsInternalAndHasAUsernameInIt()
{
$this->getRequestMock()->shouldReceive('getServer')->with("SERVER_NAME")->andReturn('localhost')
->shouldReceive('getServer')->with("SERVER_PORT")->andReturn('8080');
$url = Url::fromPath('http://testusername:testpassword@localhost:8080/path/to/my/url.html');
$this->assertEquals(
'http://testusername:testpassword@localhost:8080/path/to/my/url.html',
$url->getAbsoluteUrl(),
'Url::getAbsoluteUrl does not reassemble the correct basePath'
);
}
public function testWhetherGetAbsoluteUrlReturnsTheBasePathIfUrlIsInternalAndHasNoUsernameInIt()
{
$url = Url::fromPath('/path/to/my/url.html');
$this->assertEquals(
'/path/to/my/url.html',
$url->getAbsoluteUrl(),
'Url::getAbsoluteUrl does not reassemble the correct basePath'
);
}
public function testWhetherGetAbsoluteUrlReturnsTheBasePathIfUrlIsExternalAndHasAUsernameInIt()
{
$this->getRequestMock()->shouldReceive('getServer')->with("SERVER_NAME")->andReturn('localhost')
->shouldReceive('getServer')->with("SERVER_PORT")->andReturn('8080');
$url = Url::fromPath('http://testusername:testpassword@testhost/path/to/my/url.html');
$this->assertEquals(
'http://testusername:testpassword@testhost/path/to/my/url.html',
$url->getAbsoluteUrl(),
'Url::getAbsoluteUrl does not reassemble the correct basePath'
);
}
public function testWhetherGetAbsoluteUrlReturnsTheBasePathIfUrlIsExternalAndHasNoUsernameInIt()
{
$this->getRequestMock()->shouldReceive('getServer')->with("SERVER_NAME")->andReturn('localhost')
->shouldReceive('getServer')->with("SERVER_PORT")->andReturn('8080');
$url = Url::fromPath('http://testhost/path/to/my/url.html');
$this->assertEquals(
'http://testhost/path/to/my/url.html',
$url->getAbsoluteUrl(),
'Url::getAbsoluteUrl does not reassemble the correct basePath'
);
}
public function testWhetherGetAbsoluteUrlReturnsTheGivenUsernameAndPassword()
{
$url = Url::fromPath('http://testusername:testpassword@testsite.com/path/to/my/url.html');