]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/formatter/BookmarkDefaultFormatterTest.php
Support search highlights when matching URL content
[github/shaarli/Shaarli.git] / tests / formatter / BookmarkDefaultFormatterTest.php
index 3fc6f8dc58f4c8f38e877f1c49c18d2d083cbcde..983960b6ad77979c8b22ac5ca9a32d4559946a29 100644 (file)
@@ -211,13 +211,17 @@ class BookmarkDefaultFormatterTest extends TestCase
         $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
 
         $bookmark = new Bookmark();
-        $bookmark->setDescription('This guide extends and expands on PSR-1, the basic coding standard.');
+        $bookmark->setDescription(
+            'This guide extends and expands on PSR-1, the basic coding standard.' . PHP_EOL .
+            'https://www.php-fig.org/psr/psr-1/'
+        );
         $bookmark->addAdditionalContentEntry(
             'search_highlight',
             ['description' => [
                 ['start' => 0, 'end' => 10], // "This guide"
                 ['start' => 45, 'end' => 50], // basic
                 ['start' => 58, 'end' => 67], // standard.
+                ['start' => 84, 'end' => 87], // fig
             ]]
         );
 
@@ -226,7 +230,10 @@ class BookmarkDefaultFormatterTest extends TestCase
         $this->assertSame(
             '<span class="search-highlight">This guide</span> extends and expands on PSR-1, the ' .
             '<span class="search-highlight">basic</span> coding ' .
-            '<span class="search-highlight">standard.</span>',
+            '<span class="search-highlight">standard.</span><br />' . PHP_EOL .
+            '<a href="https://www.php-fig.org/psr/psr-1/">' .
+                'https://www.php-<span class="search-highlight">fig</span>.org/psr/psr-1/' .
+            '</a>',
             $link['description']
         );
     }
@@ -289,4 +296,24 @@ class BookmarkDefaultFormatterTest extends TestCase
             $link['taglist_html']
         );
     }
+
+    /**
+     * Test default formatting with formatter_settings.autolink set to false:
+     *   URLs and hashtags should not be transformed
+     */
+    public function testFormatDescriptionWithoutLinkification(): void
+    {
+        $this->conf->set('formatter_settings.autolink', false);
+        $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
+
+        $bookmark = new Bookmark();
+        $bookmark->setDescription('Hi!' . PHP_EOL . 'https://thisisaurl.tld  #hashtag');
+
+        $link = $this->formatter->format($bookmark);
+
+        static::assertSame(
+            'Hi!<br />' . PHP_EOL . 'https://thisisaurl.tld &nbsp;#hashtag',
+            $link['description']
+        );
+    }
 }