]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/LinkUtilsTest.php
Merge pull request #1234 from virtualtam/lint
[github/shaarli/Shaarli.git] / tests / LinkUtilsTest.php
index ef650f448d382fd2e4ab7ab7959186f831c255c9..5407159a04c37ed9908aa7fcb063c576b4fd8475 100644 (file)
@@ -83,7 +83,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
             'Date: Sat, 28 Oct 2017 12:01:33 GMT',
             'Content-Type: text/html; charset=utf-8',
             'Status: 200 OK',
-            'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea',
+            'end' => 'th=device-width">'
+            .'<title>Refactoring · GitHub</title>'
+            .'<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -106,7 +108,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
         $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_no_charset');
         $data = [
             'HTTP/1.1 200 OK',
-            'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea',
+            'end' => 'th=device-width">'
+            .'<title>Refactoring · GitHub</title>'
+            .'<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -126,7 +130,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
         $data = [
             'HTTP/1.1 200 OK',
             '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
-            'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea',
+            'end' => 'th=device-width">'
+            .'<title>Refactoring · GitHub</title>'
+            .'<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -211,13 +217,26 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
     public function testText2clickableWithoutRedirector()
     {
         $text = 'stuff http://hello.there/is=someone#here otherstuff';
-        $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff';
+        $expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
+            .'http://hello.there/is=someone#here</a> otherstuff';
+        $processedText = text2clickable($text, '');
+        $this->assertEquals($expectedText, $processedText);
+
+        $text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
+        $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
+            .'http://hello.there/is=someone#here(please)</a> otherstuff';
+        $processedText = text2clickable($text, '');
+        $this->assertEquals($expectedText, $processedText);
+
+        $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
+        $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
+            .'http://hello.there/is=someone#here(please)&no</a> otherstuff';
         $processedText = text2clickable($text, '');
         $this->assertEquals($expectedText, $processedText);
     }
 
     /**
-     * Test text2clickable a redirector set.
+     * Test text2clickable with a redirector set.
      */
     public function testText2clickableWithRedirector()
     {
@@ -231,6 +250,21 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($expectedText, $processedText);
     }
 
+    /**
+     * Test text2clickable a redirector set and without URL encode.
+     */
+    public function testText2clickableWithRedirectorDontEncode()
+    {
+        $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff';
+        $redirector = 'http://redirector.to';
+        $expectedText = 'stuff <a href="'.
+            $redirector .
+            'http://hello.there/?is=someone&or=something#here' .
+            '">http://hello.there/?is=someone&or=something#here</a> otherstuff';
+        $processedText = text2clickable($text, $redirector, false);
+        $this->assertEquals($expectedText, $processedText);
+    }
+
     /**
      * Test testSpace2nbsp.
      */
@@ -385,4 +419,3 @@ function ut_curl_getinfo_rs_ct_ko($ch, $type)
             return 'text/plain';
     }
 }
-