[icinga-checkins] icinga.org: icingaweb2/master: UrlTest: Add additional test cases

git at icinga.org git at icinga.org
Thu Oct 20 09:31:15 CEST 2016


Module: icingaweb2
Branch: master
Commit: a84e0c4d84a81ae48720a9f51957a29ad7681883
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=a84e0c4d84a81ae48720a9f51957a29ad7681883

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Wed Oct 19 13:12:55 2016 +0200

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 c5cd839..4975199 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');



More information about the icinga-checkins mailing list