aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/formatter
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-12 12:23:57 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-16 20:31:49 +0200
commitf1a148ab92c061ac129b5b2976de02d45b6a71e7 (patch)
tree89b085ac6c4cd7608526f855f452d1a797dbb333 /tests/formatter
parent4e3875c0ce7f3b17e3d358dc5ecb1f8bed64546b (diff)
downloadShaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.tar.gz
Shaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.tar.zst
Shaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.zip
add search highlight unit tests
Diffstat (limited to 'tests/formatter')
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index 9534436e..3fc6f8dc 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -174,4 +174,119 @@ 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 }
177} 292}