X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkInitializerTest.php;h=351807c16d5a5a574e0e4d6f92efba35bf07fe47;hb=bcba6bd353161fab456b423e93571ab027d5423c;hp=3906cc7f4e3f542531eaa0b53b3b174c07cfc18a;hpb=a975d97a8da64864c3c49f1c54f571eb4ea5b81a;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 3906cc7f..351807c1 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -2,9 +2,11 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; +use malkusch\lock\mutex\NoMutex; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; /** * Class BookmarkInitializerTest @@ -34,11 +36,18 @@ class BookmarkInitializerTest extends TestCase /** @var BookmarkInitializer instance */ protected $initializer; + /** @var NoMutex */ + protected $mutex; + + /** @var PluginManager */ + protected $pluginManager; + /** * Initialize an empty BookmarkFileService */ - public function setUp() + public function setUp(): void { + $this->mutex = new NoMutex(); if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); } @@ -46,8 +55,15 @@ class BookmarkInitializerTest extends TestCase copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); $this->conf->set('resource.datastore', self::$testDatastore); + $this->pluginManager = new PluginManager($this->conf); $this->history = new History('sandbox/history.php'); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService( + $this->conf, + $this->pluginManager, + $this->history, + $this->mutex, + true + ); $this->initializer = new BookmarkInitializer($this->bookmarkService); } @@ -59,40 +75,70 @@ class BookmarkInitializerTest extends TestCase { $refDB = new \ReferenceLinkDB(); $refDB->write(self::$testDatastore); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService( + $this->conf, + $this->pluginManager, + $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->pluginManager, + $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()); } @@ -103,21 +149,35 @@ class BookmarkInitializerTest extends TestCase public function testInitializeNonExistentDataStore(): void { $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->bookmarkService = new BookmarkFileService( + $this->conf, + $this->pluginManager, + $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()); }