X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkInitializerTest.php;h=0c8420ce5ffceac84e4dd471cdc8f8fa567113d1;hb=b1d78519a8dd8b43698f76c61d9967ca542a1660;hp=d23eb0695b1fdde093b4fcb4b6274a8bd44cb44a;hpb=3fb29fdda04ca86e04422d49b86cf646d53c4f9d;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index d23eb069..0c8420ce 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -2,10 +2,10 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; -use ReferenceLinkDB; +use malkusch\lock\mutex\NoMutex; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** * Class BookmarkInitializerTest @@ -35,11 +35,15 @@ class BookmarkInitializerTest extends TestCase /** @var BookmarkInitializer instance */ protected $initializer; + /** @var NoMutex */ + protected $mutex; + /** * Initialize an empty BookmarkFileService */ - public function setUp() + public function setUp(): void { + $this->mutex = new NoMutex(); if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); } @@ -48,72 +52,103 @@ class BookmarkInitializerTest extends TestCase $this->conf = new ConfigManager(self::$testConf); $this->conf->set('resource.datastore', self::$testDatastore); $this->history = new History('sandbox/history.php'); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); $this->initializer = new BookmarkInitializer($this->bookmarkService); } /** - * Test initialize() with an empty data store. + * Test initialize() with a data store containing bookmarks. */ - public function testInitializeEmptyDataStore() + public function testInitializeNotEmptyDataStore(): void { $refDB = new \ReferenceLinkDB(); $refDB->write(self::$testDatastore); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); $this->initializer = new BookmarkInitializer($this->bookmarkService); $this->initializer->initialize(); - $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); + $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); + $bookmark = $this->bookmarkService->get(43); - $this->assertEquals(43, $bookmark->getId()); - $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $this->assertStringStartsWith( + 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', + $bookmark->getDescription() + ); $this->assertTrue($bookmark->isPrivate()); $bookmark = $this->bookmarkService->get(44); - $this->assertEquals(44, $bookmark->getId()); - $this->assertEquals( - 'The personal, minimalist, super-fast, database free, bookmarking service', - $bookmark->getTitle() + $this->assertStringStartsWith( + 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', + $bookmark->getDescription() + ); + $this->assertTrue($bookmark->isPrivate()); + + $bookmark = $this->bookmarkService->get(45); + $this->assertStringStartsWith( + 'Welcome to Shaarli!', + $bookmark->getDescription() ); $this->assertFalse($bookmark->isPrivate()); + $this->bookmarkService->save(); + // Reload from file - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); - $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); + $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); + $bookmark = $this->bookmarkService->get(43); - $this->assertEquals(43, $bookmark->getId()); - $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $this->assertStringStartsWith( + 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', + $bookmark->getDescription() + ); $this->assertTrue($bookmark->isPrivate()); $bookmark = $this->bookmarkService->get(44); - $this->assertEquals(44, $bookmark->getId()); - $this->assertEquals( - 'The personal, minimalist, super-fast, database free, bookmarking service', - $bookmark->getTitle() + $this->assertStringStartsWith( + 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', + $bookmark->getDescription() + ); + $this->assertTrue($bookmark->isPrivate()); + + $bookmark = $this->bookmarkService->get(45); + $this->assertStringStartsWith( + 'Welcome to Shaarli!', + $bookmark->getDescription() ); $this->assertFalse($bookmark->isPrivate()); } /** - * Test initialize() with a data store containing bookmarks. + * Test initialize() with an a non existent datastore file . */ - public function testInitializeNotEmptyDataStore() + public function testInitializeNonExistentDataStore(): void { + $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); + $this->initializer->initialize(); - $this->assertEquals(2, $this->bookmarkService->count()); + $this->assertEquals(3, $this->bookmarkService->count()); $bookmark = $this->bookmarkService->get(0); - $this->assertEquals(0, $bookmark->getId()); - $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $this->assertStringStartsWith( + 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', + $bookmark->getDescription() + ); $this->assertTrue($bookmark->isPrivate()); $bookmark = $this->bookmarkService->get(1); - $this->assertEquals(1, $bookmark->getId()); - $this->assertEquals( - 'The personal, minimalist, super-fast, database free, bookmarking service', - $bookmark->getTitle() + $this->assertStringStartsWith( + 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', + $bookmark->getDescription() + ); + $this->assertTrue($bookmark->isPrivate()); + + $bookmark = $this->bookmarkService->get(2); + $this->assertStringStartsWith( + 'Welcome to Shaarli!', + $bookmark->getDescription() ); $this->assertFalse($bookmark->isPrivate()); }