aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-02-04 10:57:12 +0100
committerGitHub <noreply@github.com>2021-02-04 10:57:12 +0100
commit11edc143b42a7be09c0c9dc02730c83e8cbb73c2 (patch)
tree55d6d35896c600066981f4cf3f49d6563ffda7d0 /tests
parent83b4eb17958c0c03bea637db7e394f6d622aeb00 (diff)
parenta1cd7a3b2ff32bf6a0f6083007f59104a85eb4bf (diff)
downloadShaarli-11edc143b42a7be09c0c9dc02730c83e8cbb73c2.tar.gz
Shaarli-11edc143b42a7be09c0c9dc02730c83e8cbb73c2.tar.zst
Shaarli-11edc143b42a7be09c0c9dc02730c83e8cbb73c2.zip
Merge pull request #1696 from ArthurHoaro/fix/search-highlight-url
Diffstat (limited to 'tests')
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php11
-rw-r--r--tests/formatter/BookmarkMarkdownFormatterTest.php43
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index 4fcc5dd1..983960b6 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -211,13 +211,17 @@ class BookmarkDefaultFormatterTest extends TestCase
211 $this->formatter = new BookmarkDefaultFormatter($this->conf, false); 211 $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
212 212
213 $bookmark = new Bookmark(); 213 $bookmark = new Bookmark();
214 $bookmark->setDescription('This guide extends and expands on PSR-1, the basic coding standard.'); 214 $bookmark->setDescription(
215 'This guide extends and expands on PSR-1, the basic coding standard.' . PHP_EOL .
216 'https://www.php-fig.org/psr/psr-1/'
217 );
215 $bookmark->addAdditionalContentEntry( 218 $bookmark->addAdditionalContentEntry(
216 'search_highlight', 219 'search_highlight',
217 ['description' => [ 220 ['description' => [
218 ['start' => 0, 'end' => 10], // "This guide" 221 ['start' => 0, 'end' => 10], // "This guide"
219 ['start' => 45, 'end' => 50], // basic 222 ['start' => 45, 'end' => 50], // basic
220 ['start' => 58, 'end' => 67], // standard. 223 ['start' => 58, 'end' => 67], // standard.
224 ['start' => 84, 'end' => 87], // fig
221 ]] 225 ]]
222 ); 226 );
223 227
@@ -226,7 +230,10 @@ class BookmarkDefaultFormatterTest extends TestCase
226 $this->assertSame( 230 $this->assertSame(
227 '<span class="search-highlight">This guide</span> extends and expands on PSR-1, the ' . 231 '<span class="search-highlight">This guide</span> extends and expands on PSR-1, the ' .
228 '<span class="search-highlight">basic</span> coding ' . 232 '<span class="search-highlight">basic</span> coding ' .
229 '<span class="search-highlight">standard.</span>', 233 '<span class="search-highlight">standard.</span><br />' . PHP_EOL .
234 '<a href="https://www.php-fig.org/psr/psr-1/">' .
235 'https://www.php-<span class="search-highlight">fig</span>.org/psr/psr-1/' .
236 '</a>',
230 $link['description'] 237 $link['description']
231 ); 238 );
232 } 239 }
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php
index ab6b4080..32f7b444 100644
--- a/tests/formatter/BookmarkMarkdownFormatterTest.php
+++ b/tests/formatter/BookmarkMarkdownFormatterTest.php
@@ -133,6 +133,49 @@ class BookmarkMarkdownFormatterTest extends TestCase
133 } 133 }
134 134
135 /** 135 /**
136 * Make sure that the description is properly formatted by the default formatter.
137 */
138 public function testFormatDescriptionWithSearchHighlight()
139 {
140 $description = 'This a <strong>description</strong>'. PHP_EOL;
141 $description .= 'text https://sub.domain.tld?query=here&for=real#hash more text'. PHP_EOL;
142 $description .= 'Also, there is an #hashtag added'. PHP_EOL;
143 $description .= ' A N D KEEP SPACES ! '. PHP_EOL;
144 $description .= 'And [yet another link](https://other.domain.tld)'. PHP_EOL;
145
146 $bookmark = new Bookmark();
147 $bookmark->setDescription($description);
148 $bookmark->addAdditionalContentEntry(
149 'search_highlight',
150 ['description' => [
151 ['start' => 18, 'end' => 26], // cription
152 ['start' => 49, 'end' => 52], // sub
153 ['start' => 84, 'end' => 88], // hash
154 ['start' => 118, 'end' => 123], // hasht
155 ['start' => 203, 'end' => 215], // other.domain
156 ]]
157 );
158
159 $link = $this->formatter->format($bookmark);
160
161 $description = '<div class="markdown"><p>';
162 $description .= 'This a &lt;strong&gt;des<span class="search-highlight">cription</span>&lt;/strong&gt;<br />' .
163 PHP_EOL;
164 $url = 'https://sub.domain.tld?query=here&amp;for=real#hash';
165 $highlighted = 'https://<span class="search-highlight">sub</span>.domain.tld';
166 $highlighted .= '?query=here&amp;for=real#<span class="search-highlight">hash</span>';
167 $description .= 'text <a href="'. $url .'">'. $highlighted .'</a> more text<br />'. PHP_EOL;
168 $description .= 'Also, there is an <a href="./add-tag/hashtag">#<span class="search-highlight">hasht</span>' .
169 'ag</a> added<br />'. PHP_EOL;
170 $description .= 'A N D KEEP SPACES !<br />' . PHP_EOL;
171 $description .= 'And <a href="https://other.domain.tld">' .
172 '<span class="search-highlight">yet another link</span></a>';
173 $description .= '</p></div>';
174
175 $this->assertEquals($description, $link['description']);
176 }
177
178 /**
136 * Test formatting URL with an index_url set 179 * Test formatting URL with an index_url set
137 * It should prepend relative links. 180 * It should prepend relative links.
138 */ 181 */