X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkTest.php;h=4c1ae25dce6cfb8b329906e9840211ef3dbd3b83;hb=330ac859fb13a3a15875f185a611bfaa6c5f5587;hp=4b6a3c07c6207e6b41f6ec65b75fb4c79f333de6;hpb=301c7ab1a079d937ab41c6f52b8804e5731008e6;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 4b6a3c07..4c1ae25d 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php @@ -2,8 +2,8 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Exception\InvalidBookmarkException; +use Shaarli\TestCase; /** * Class BookmarkTest @@ -150,26 +150,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- ID: '. PHP_EOL, $exception->getMessage()); - } - - /** - * Test validate() with a a bookmark with a non integer ID. - */ - public function testValidateNotValidStringId() - { - $bookmark = new Bookmark(); - $bookmark->setId('str'); - $bookmark->setShortUrl('abc'); - $bookmark->setCreated(\DateTime::createFromFormat('Ymd_His', '20190514_200102')); - $exception = null; - try { - $bookmark->validate(); - } catch (InvalidBookmarkException $e) { - $exception = $e; - } - $this->assertNotNull($exception); - $this->assertContains('- ID: str'. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage()); } /** @@ -188,7 +169,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- ShortUrl: '. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage()); } /** @@ -207,26 +188,7 @@ class BookmarkTest extends TestCase $exception = $e; } $this->assertNotNull($exception); - $this->assertContains('- Created: '. PHP_EOL, $exception->getMessage()); - } - - /** - * Test validate() with a a bookmark with a bad created datetime. - */ - public function testValidateNotValidBadCreated() - { - $bookmark = new Bookmark(); - $bookmark->setId(1); - $bookmark->setShortUrl('abc'); - $bookmark->setCreated('hi!'); - $exception = null; - try { - $bookmark->validate(); - } catch (InvalidBookmarkException $e) { - $exception = $e; - } - $this->assertNotNull($exception); - $this->assertContains('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); + $this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage()); } /** @@ -385,4 +347,48 @@ class BookmarkTest extends TestCase $bookmark->deleteTag('nope'); $this->assertEquals(['tag1', 'tag2', 'chair'], $bookmark->getTags()); } + + /** + * Test shouldUpdateThumbnail() with bookmarks needing an update. + */ + public function testShouldUpdateThumbnail(): void + { + $bookmark = (new Bookmark())->setUrl('http://domain.tld/with-image'); + + static::assertTrue($bookmark->shouldUpdateThumbnail()); + + $bookmark = (new Bookmark()) + ->setUrl('http://domain.tld/with-image') + ->setThumbnail('unknown file') + ; + + static::assertTrue($bookmark->shouldUpdateThumbnail()); + } + + /** + * Test shouldUpdateThumbnail() with bookmarks that should not update. + */ + public function testShouldNotUpdateThumbnail(): void + { + $bookmark = (new Bookmark()); + + static::assertFalse($bookmark->shouldUpdateThumbnail()); + + $bookmark = (new Bookmark()) + ->setUrl('ftp://domain.tld/other-protocol', ['ftp']) + ; + + static::assertFalse($bookmark->shouldUpdateThumbnail()); + + $bookmark = (new Bookmark()) + ->setUrl('http://domain.tld/with-image') + ->setThumbnail(__FILE__) + ; + + static::assertFalse($bookmark->shouldUpdateThumbnail()); + + $bookmark = (new Bookmark())->setUrl('/shaare/abcdef'); + + static::assertFalse($bookmark->shouldUpdateThumbnail()); + } }