diff options
Diffstat (limited to 'tests/bookmark/BookmarkTest.php')
-rw-r--r-- | tests/bookmark/BookmarkTest.php | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 4c7ae4c0..cb91b26b 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php | |||
@@ -79,6 +79,23 @@ class BookmarkTest extends TestCase | |||
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Test fromArray() with a link with a custom tags separator | ||
83 | */ | ||
84 | public function testFromArrayCustomTagsSeparator() | ||
85 | { | ||
86 | $data = [ | ||
87 | 'id' => 1, | ||
88 | 'tags' => ['tag1', 'tag2', 'chair'], | ||
89 | ]; | ||
90 | |||
91 | $bookmark = (new Bookmark())->fromArray($data, '@'); | ||
92 | $this->assertEquals($data['id'], $bookmark->getId()); | ||
93 | $this->assertEquals($data['tags'], $bookmark->getTags()); | ||
94 | $this->assertEquals('tag1@tag2@chair', $bookmark->getTagsString('@')); | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
82 | * Test validate() with a valid minimal bookmark | 99 | * Test validate() with a valid minimal bookmark |
83 | */ | 100 | */ |
84 | public function testValidateValidFullBookmark() | 101 | public function testValidateValidFullBookmark() |
@@ -252,7 +269,7 @@ class BookmarkTest extends TestCase | |||
252 | { | 269 | { |
253 | $bookmark = new Bookmark(); | 270 | $bookmark = new Bookmark(); |
254 | 271 | ||
255 | $str = 'tag1 tag2 tag3.tag3-2, tag4 , -tag5 '; | 272 | $str = 'tag1 tag2 tag3.tag3-2 tag4 -tag5 '; |
256 | $bookmark->setTagsString($str); | 273 | $bookmark->setTagsString($str); |
257 | $this->assertEquals( | 274 | $this->assertEquals( |
258 | [ | 275 | [ |
@@ -276,9 +293,9 @@ class BookmarkTest extends TestCase | |||
276 | $array = [ | 293 | $array = [ |
277 | 'tag1 ', | 294 | 'tag1 ', |
278 | ' tag2', | 295 | ' tag2', |
279 | 'tag3.tag3-2,', | 296 | 'tag3.tag3-2', |
280 | ', tag4', | 297 | ' tag4', |
281 | ', ', | 298 | ' ', |
282 | '-tag5 ', | 299 | '-tag5 ', |
283 | ]; | 300 | ]; |
284 | $bookmark->setTags($array); | 301 | $bookmark->setTags($array); |
@@ -347,4 +364,48 @@ class BookmarkTest extends TestCase | |||
347 | $bookmark->deleteTag('nope'); | 364 | $bookmark->deleteTag('nope'); |
348 | $this->assertEquals(['tag1', 'tag2', 'chair'], $bookmark->getTags()); | 365 | $this->assertEquals(['tag1', 'tag2', 'chair'], $bookmark->getTags()); |
349 | } | 366 | } |
367 | |||
368 | /** | ||
369 | * Test shouldUpdateThumbnail() with bookmarks needing an update. | ||
370 | */ | ||
371 | public function testShouldUpdateThumbnail(): void | ||
372 | { | ||
373 | $bookmark = (new Bookmark())->setUrl('http://domain.tld/with-image'); | ||
374 | |||
375 | static::assertTrue($bookmark->shouldUpdateThumbnail()); | ||
376 | |||
377 | $bookmark = (new Bookmark()) | ||
378 | ->setUrl('http://domain.tld/with-image') | ||
379 | ->setThumbnail('unknown file') | ||
380 | ; | ||
381 | |||
382 | static::assertTrue($bookmark->shouldUpdateThumbnail()); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Test shouldUpdateThumbnail() with bookmarks that should not update. | ||
387 | */ | ||
388 | public function testShouldNotUpdateThumbnail(): void | ||
389 | { | ||
390 | $bookmark = (new Bookmark()); | ||
391 | |||
392 | static::assertFalse($bookmark->shouldUpdateThumbnail()); | ||
393 | |||
394 | $bookmark = (new Bookmark()) | ||
395 | ->setUrl('ftp://domain.tld/other-protocol', ['ftp']) | ||
396 | ; | ||
397 | |||
398 | static::assertFalse($bookmark->shouldUpdateThumbnail()); | ||
399 | |||
400 | $bookmark = (new Bookmark()) | ||
401 | ->setUrl('http://domain.tld/with-image') | ||
402 | ->setThumbnail(__FILE__) | ||
403 | ; | ||
404 | |||
405 | static::assertFalse($bookmark->shouldUpdateThumbnail()); | ||
406 | |||
407 | $bookmark = (new Bookmark())->setUrl('/shaare/abcdef'); | ||
408 | |||
409 | static::assertFalse($bookmark->shouldUpdateThumbnail()); | ||
410 | } | ||
350 | } | 411 | } |