]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/Url/UrlTest.php
lint: apply phpcbf to tests/
[github/shaarli/Shaarli.git] / tests / Url / UrlTest.php
index e498d79e8ed8dbf9057ce88c04fd1e98143a5408..db229ce0d87c544ff912fd5240cc6a15dccaa950 100644 (file)
@@ -16,7 +16,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
     /**
      * Helper method
      */
-    private function assertUrlIsCleaned($query='', $fragment='')
+    private function assertUrlIsCleaned($query = '', $fragment = '')
     {
         $url = new Url(self::$baseUrl.$query.$fragment);
         $url->cleanup();
@@ -85,6 +85,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
         $this->assertUrlIsCleaned('?utm_term=1n4l');
 
         $this->assertUrlIsCleaned('?xtor=some-url');
+        $this->assertUrlIsCleaned('?PHPSESSID=012345678910111213');
     }
 
     /**
@@ -128,12 +129,19 @@ class UrlTest extends PHPUnit_Framework_TestCase
             self::$baseUrl.'?my=stuff&is=kept#again',
             $url->cleanup()
         );
+
+        // test firefox reader url
+        $url = new Url(
+            'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept')
+        );
+        $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup());
     }
 
     /**
      * Test default http scheme.
      */
-    public function testDefaultScheme() {
+    public function testDefaultScheme()
+    {
         $url = new Url(self::$baseUrl);
         $this->assertEquals('http', $url->getScheme());
         $url = new Url('domain.tld');
@@ -145,4 +153,48 @@ class UrlTest extends PHPUnit_Framework_TestCase
         $url = new Url('git://domain.tld/push?pull=clone#checkout');
         $this->assertEquals('git', $url->getScheme());
     }
+
+    /**
+     * Test add trailing slash.
+     */
+    public function testAddTrailingSlash()
+    {
+        $strOn = 'http://randomstr.com/test/';
+        $strOff = 'http://randomstr.com/test';
+        $this->assertEquals($strOn, add_trailing_slash($strOn));
+        $this->assertEquals($strOn, add_trailing_slash($strOff));
+    }
+
+    /**
+     * Test valid HTTP url.
+     */
+    public function testUrlIsHttp()
+    {
+        $url = new Url(self::$baseUrl);
+        $this->assertTrue($url->isHttp());
+    }
+
+    /**
+     * Test non HTTP url.
+     */
+    public function testUrlIsNotHttp()
+    {
+        $url = new Url('ftp://save.tld/mysave');
+        $this->assertFalse($url->isHttp());
+    }
+
+    /**
+     * Test International Domain Name to ASCII conversion
+     */
+    public function testIdnToAscii()
+    {
+        $ind = 'http://www.académie-française.fr/';
+        $expected = 'http://www.xn--acadmie-franaise-npb1a.fr/';
+        $url = new Url($ind);
+        $this->assertEquals($expected, $url->idnToAscii());
+
+        $notInd = 'http://www.academie-francaise.fr/';
+        $url = new Url($notInd);
+        $this->assertEquals($notInd, $url->idnToAscii());
+    }
 }