Follow-up to feature #10724: Added unit tests for isValidUrl() and isOnCurrentHost...
authorOliver Hader <oliver.hader@typo3.org>
Tue, 1 Sep 2009 16:48:18 +0000 (16:48 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 1 Sep 2009 16:48:18 +0000 (16:48 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5868 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_div_testcase.php

index 3577309..07692ce 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * Follow-up to feature #9292: Fixed wrong disposal of global variables (thanks to Christian Kuhn)
        * Added feature #10724: Provide a check that compares a given URL with the host, TYPO3 is running on (thanks to Marcus Krause)
+       * Follow-up to feature #10724: Added unit tests for isValidUrl() and isOnCurrentHost() in t3lib_div (thanks to Marcus Krause)
 
 2009-09-01  Sebastian Kurfuerst  <sebastian@typo3.org>
 
index 1fd5e86..6adc7d5 100644 (file)
@@ -200,6 +200,115 @@ class t3lib_div_testcase extends tx_phpunit_testcase {
                        )
                );
        }
+
+       /**
+        * @test
+        * @see t3lib_div::isValidUrl()
+        */
+       public function checkisValidURLSucceedsWithWebRessource() {
+               $testUrl = 'http://www.example.org/';
+               $this->assertTrue(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isValidUrl()
+        */
+       public function checkisValidURLSucceedsWithExtentedWebRessource() {
+               $testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
+               $this->assertTrue(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isValidUrl()
+        */
+       public function checkisValidURLSucceedsWithTelnetRessource() {
+               $testUrl = 'telnet://192.0.2.16:80/';
+               $this->assertTrue(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        */
+       public function checkisValidURLSucceedsWithLdapRessource() {
+               $testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
+               $this->assertTrue(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isValidUrl()
+        */
+       public function checkisValidURLSucceedsWithFileRessource() {
+               $testUrl = 'file:///etc/passwd';
+               $this->assertTrue(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isValidUrl()
+        */
+       public function checkisValidURLFailsWithHostnameOnly() {
+               $testUrl = 'www.example.org/';
+               $this->assertFalse(t3lib_div::isValidUrl($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostFailsWithLocalhostIPOnly() {
+               $testUrl = '127.0.0.1';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostFailsWithPathsOnly() {
+               $testUrl = './relpath/file.txt';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+               $testUrl = '/abspath/file.txt?arg=value';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostFailsWithArbitraryString() {
+               $testUrl = 'arbitrary string';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostFailsWithEmptyUrl() {
+               $testUrl = '';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostFailsWithDifferentHost() {
+               $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
+               $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
+       }
+
+       /**
+        * @test
+        * @see t3lib_div::isOnCurrentHost()
+        */
+       public function checkisOnCurrentHostSucceedsWithCurrentHost() {
+               $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
+               $this->assertTrue(t3lib_div::isOnCurrentHost($testUrl));
+       }
 }
 
 ?>
\ No newline at end of file