diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-12 13:02:36 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-11-12 13:02:36 +0100 |
commit | 1409f1c89a7ca01456ae2dcd6357d296e2b99f5a (patch) | |
tree | ffa30a9358e82d27be75d8fc5e57f3c8820dc6d3 /tests/formatter/BookmarkDefaultFormatterTest.php | |
parent | 054e03f37fa29da8066f1a637919f13c7e7dc5d2 (diff) | |
parent | a6935feb22df8d9634189ee87d257da9f03eedbd (diff) | |
download | Shaarli-27ca44e31b73358f7df4940132b8264596250958.tar.gz Shaarli-27ca44e31b73358f7df4940132b8264596250958.tar.zst Shaarli-27ca44e31b73358f7df4940132b8264596250958.zip |
Diffstat (limited to 'tests/formatter/BookmarkDefaultFormatterTest.php')
-rw-r--r-- | tests/formatter/BookmarkDefaultFormatterTest.php | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php index 9534436e..4fcc5dd1 100644 --- a/tests/formatter/BookmarkDefaultFormatterTest.php +++ b/tests/formatter/BookmarkDefaultFormatterTest.php | |||
@@ -174,4 +174,139 @@ class BookmarkDefaultFormatterTest extends TestCase | |||
174 | $this->assertSame($tags, $link['taglist']); | 174 | $this->assertSame($tags, $link['taglist']); |
175 | $this->assertSame(implode(' ', $tags), $link['tags']); | 175 | $this->assertSame(implode(' ', $tags), $link['tags']); |
176 | } | 176 | } |
177 | |||
178 | /** | ||
179 | * Test formatTitleHtml with search result highlight. | ||
180 | */ | ||
181 | public function testFormatTitleHtmlWithSearchHighlight(): void | ||
182 | { | ||
183 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
184 | |||
185 | $bookmark = new Bookmark(); | ||
186 | $bookmark->setTitle('PSR-2: Coding Style Guide'); | ||
187 | $bookmark->addAdditionalContentEntry( | ||
188 | 'search_highlight', | ||
189 | ['title' => [ | ||
190 | ['start' => 0, 'end' => 5], // "psr-2" | ||
191 | ['start' => 7, 'end' => 13], // coding | ||
192 | ['start' => 20, 'end' => 25], // guide | ||
193 | ]] | ||
194 | ); | ||
195 | |||
196 | $link = $this->formatter->format($bookmark); | ||
197 | |||
198 | $this->assertSame( | ||
199 | '<span class="search-highlight">PSR-2</span>: ' . | ||
200 | '<span class="search-highlight">Coding</span> Style ' . | ||
201 | '<span class="search-highlight">Guide</span>', | ||
202 | $link['title_html'] | ||
203 | ); | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Test formatDescription with search result highlight. | ||
208 | */ | ||
209 | public function testFormatDescriptionWithSearchHighlight(): void | ||
210 | { | ||
211 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
212 | |||
213 | $bookmark = new Bookmark(); | ||
214 | $bookmark->setDescription('This guide extends and expands on PSR-1, the basic coding standard.'); | ||
215 | $bookmark->addAdditionalContentEntry( | ||
216 | 'search_highlight', | ||
217 | ['description' => [ | ||
218 | ['start' => 0, 'end' => 10], // "This guide" | ||
219 | ['start' => 45, 'end' => 50], // basic | ||
220 | ['start' => 58, 'end' => 67], // standard. | ||
221 | ]] | ||
222 | ); | ||
223 | |||
224 | $link = $this->formatter->format($bookmark); | ||
225 | |||
226 | $this->assertSame( | ||
227 | '<span class="search-highlight">This guide</span> extends and expands on PSR-1, the ' . | ||
228 | '<span class="search-highlight">basic</span> coding ' . | ||
229 | '<span class="search-highlight">standard.</span>', | ||
230 | $link['description'] | ||
231 | ); | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * Test formatUrlHtml with search result highlight. | ||
236 | */ | ||
237 | public function testFormatUrlHtmlWithSearchHighlight(): void | ||
238 | { | ||
239 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
240 | |||
241 | $bookmark = new Bookmark(); | ||
242 | $bookmark->setUrl('http://www.php-fig.org/psr/psr-2/'); | ||
243 | $bookmark->addAdditionalContentEntry( | ||
244 | 'search_highlight', | ||
245 | ['url' => [ | ||
246 | ['start' => 0, 'end' => 4], // http | ||
247 | ['start' => 15, 'end' => 18], // fig | ||
248 | ['start' => 27, 'end' => 33], // "psr-2/" | ||
249 | ]] | ||
250 | ); | ||
251 | |||
252 | $link = $this->formatter->format($bookmark); | ||
253 | |||
254 | $this->assertSame( | ||
255 | '<span class="search-highlight">http</span>://www.php-' . | ||
256 | '<span class="search-highlight">fig</span>.org/psr/' . | ||
257 | '<span class="search-highlight">psr-2/</span>', | ||
258 | $link['url_html'] | ||
259 | ); | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * Test formatTagListHtml with search result highlight. | ||
264 | */ | ||
265 | public function testFormatTagListHtmlWithSearchHighlight(): void | ||
266 | { | ||
267 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
268 | |||
269 | $bookmark = new Bookmark(); | ||
270 | $bookmark->setTagsString('coding-style standards quality assurance'); | ||
271 | $bookmark->addAdditionalContentEntry( | ||
272 | 'search_highlight', | ||
273 | ['tags' => [ | ||
274 | ['start' => 0, 'end' => 12], // coding-style | ||
275 | ['start' => 23, 'end' => 30], // quality | ||
276 | ['start' => 31, 'end' => 40], // assurance | ||
277 | ],] | ||
278 | ); | ||
279 | |||
280 | $link = $this->formatter->format($bookmark); | ||
281 | |||
282 | $this->assertSame( | ||
283 | [ | ||
284 | '<span class="search-highlight">coding-style</span>', | ||
285 | 'standards', | ||
286 | '<span class="search-highlight">quality</span>', | ||
287 | '<span class="search-highlight">assurance</span>', | ||
288 | ], | ||
289 | $link['taglist_html'] | ||
290 | ); | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * Test default formatting with formatter_settings.autolink set to false: | ||
295 | * URLs and hashtags should not be transformed | ||
296 | */ | ||
297 | public function testFormatDescriptionWithoutLinkification(): void | ||
298 | { | ||
299 | $this->conf->set('formatter_settings.autolink', false); | ||
300 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
301 | |||
302 | $bookmark = new Bookmark(); | ||
303 | $bookmark->setDescription('Hi!' . PHP_EOL . 'https://thisisaurl.tld #hashtag'); | ||
304 | |||
305 | $link = $this->formatter->format($bookmark); | ||
306 | |||
307 | static::assertSame( | ||
308 | 'Hi!<br />' . PHP_EOL . 'https://thisisaurl.tld #hashtag', | ||
309 | $link['description'] | ||
310 | ); | ||
311 | } | ||
177 | } | 312 | } |