X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fformatter%2FBookmarkMarkdownFormatterTest.php;h=32f7b444881e868b9c8067d1980e13e0a603dcb7;hb=11edc143b42a7be09c0c9dc02730c83e8cbb73c2;hp=3e72d1eea340988b4b69c4f94e9cfdc2907d2cbf;hpb=03340c18ead651ef9e11f883745695f2edafbae3;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php index 3e72d1ee..32f7b444 100644 --- a/tests/formatter/BookmarkMarkdownFormatterTest.php +++ b/tests/formatter/BookmarkMarkdownFormatterTest.php @@ -3,9 +3,9 @@ namespace Shaarli\Formatter; use DateTime; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; /** * Class BookmarkMarkdownFormatterTest @@ -25,7 +25,7 @@ class BookmarkMarkdownFormatterTest extends TestCase /** * Initialize formatter instance. */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); @@ -132,6 +132,49 @@ class BookmarkMarkdownFormatterTest extends TestCase $this->assertEquals($description, $link['description']); } + /** + * Make sure that the description is properly formatted by the default formatter. + */ + public function testFormatDescriptionWithSearchHighlight() + { + $description = 'This a description'. PHP_EOL; + $description .= 'text https://sub.domain.tld?query=here&for=real#hash more text'. PHP_EOL; + $description .= 'Also, there is an #hashtag added'. PHP_EOL; + $description .= ' A N D KEEP SPACES ! '. PHP_EOL; + $description .= 'And [yet another link](https://other.domain.tld)'. PHP_EOL; + + $bookmark = new Bookmark(); + $bookmark->setDescription($description); + $bookmark->addAdditionalContentEntry( + 'search_highlight', + ['description' => [ + ['start' => 18, 'end' => 26], // cription + ['start' => 49, 'end' => 52], // sub + ['start' => 84, 'end' => 88], // hash + ['start' => 118, 'end' => 123], // hasht + ['start' => 203, 'end' => 215], // other.domain + ]] + ); + + $link = $this->formatter->format($bookmark); + + $description = '

'; + $description .= 'This a <strong>description</strong>
' . + PHP_EOL; + $url = 'https://sub.domain.tld?query=here&for=real#hash'; + $highlighted = 'https://sub.domain.tld'; + $highlighted .= '?query=here&for=real#hash'; + $description .= 'text '. $highlighted .' more text
'. PHP_EOL; + $description .= 'Also, there is an #hasht' . + 'ag added
'. PHP_EOL; + $description .= 'A N D KEEP SPACES !
' . PHP_EOL; + $description .= 'And ' . + 'yet another link'; + $description .= '

'; + + $this->assertEquals($description, $link['description']); + } + /** * Test formatting URL with an index_url set * It should prepend relative links.