From a84e0c4d84a81ae48720a9f51957a29ad7681883 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 19 Oct 2016 13:12:55 +0200 Subject: [PATCH] UrlTest: Add additional test cases refs #12133 --- test/php/library/Icinga/Web/UrlTest.php | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/php/library/Icinga/Web/UrlTest.php b/test/php/library/Icinga/Web/UrlTest.php index c5cd839bb..4975199e6 100644 --- a/test/php/library/Icinga/Web/UrlTest.php +++ b/test/php/library/Icinga/Web/UrlTest.php @@ -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');