From e26e2060f5470ce8bf4c5973284bae07b8af170a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 17 Jan 2020 21:34:12 +0100 Subject: Add and update unit test for the new system (Bookmark + Service) See #1307 --- tests/bookmark/BookmarkInitializerTest.php | 120 +++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tests/bookmark/BookmarkInitializerTest.php (limited to 'tests/bookmark/BookmarkInitializerTest.php') diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php new file mode 100644 index 00000000..d23eb069 --- /dev/null +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -0,0 +1,120 @@ +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->initializer = new BookmarkInitializer($this->bookmarkService); + } + + /** + * Test initialize() with an empty data store. + */ + public function testInitializeEmptyDataStore() + { + $refDB = new \ReferenceLinkDB(); + $refDB->write(self::$testDatastore); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->initializer = new BookmarkInitializer($this->bookmarkService); + + $this->initializer->initialize(); + + $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); + $bookmark = $this->bookmarkService->get(43); + $this->assertEquals(43, $bookmark->getId()); + $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $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->assertFalse($bookmark->isPrivate()); + + // Reload from file + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); + $bookmark = $this->bookmarkService->get(43); + $this->assertEquals(43, $bookmark->getId()); + $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $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->assertFalse($bookmark->isPrivate()); + } + + /** + * Test initialize() with a data store containing bookmarks. + */ + public function testInitializeNotEmptyDataStore() + { + $this->initializer->initialize(); + + $this->assertEquals(2, $this->bookmarkService->count()); + $bookmark = $this->bookmarkService->get(0); + $this->assertEquals(0, $bookmark->getId()); + $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); + $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->assertFalse($bookmark->isPrivate()); + } +} -- cgit v1.2.3 From d6e5f04d3987e498c5cb859eed6bff33d67949df Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 1 Aug 2020 11:10:57 +0200 Subject: Remove anonymous permission and initialize bookmarks on login --- tests/bookmark/BookmarkInitializerTest.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests/bookmark/BookmarkInitializerTest.php') diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index d23eb069..3906cc7f 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -3,7 +3,6 @@ namespace Shaarli\Bookmark; use PHPUnit\Framework\TestCase; -use ReferenceLinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; @@ -54,9 +53,9 @@ class BookmarkInitializerTest extends TestCase } /** - * 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); @@ -79,6 +78,8 @@ class BookmarkInitializerTest extends TestCase ); $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()); @@ -97,10 +98,13 @@ class BookmarkInitializerTest extends TestCase } /** - * 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, true); + $this->initializer->initialize(); $this->assertEquals(2, $this->bookmarkService->count()); -- cgit v1.2.3 From da7acb98302b99ec729bcde3e3c9f4bb164a1b34 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 6 Sep 2020 13:42:45 +0200 Subject: Improve default bookmarks after install Used @nodiscc suggestion in #1148 (slightly edited). It provides a description of what Shaarli does, Markdown rendering demo, and a thumbnail link. Fixes #1148 --- tests/bookmark/BookmarkInitializerTest.php | 70 ++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'tests/bookmark/BookmarkInitializerTest.php') diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 3906cc7f..454269bb 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -37,7 +37,7 @@ class BookmarkInitializerTest extends TestCase /** * Initialize an empty BookmarkFileService */ - public function setUp() + public function setUp(): void { if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); @@ -64,17 +64,26 @@ class BookmarkInitializerTest extends TestCase $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()); @@ -82,17 +91,26 @@ class BookmarkInitializerTest extends TestCase // Reload from file $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); - $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()); } @@ -107,17 +125,25 @@ class BookmarkInitializerTest extends TestCase $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()); } -- cgit v1.2.3 From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/bookmark/BookmarkInitializerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/bookmark/BookmarkInitializerTest.php') diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 454269bb..25704004 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php @@ -2,9 +2,9 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** * Class BookmarkInitializerTest -- cgit v1.2.3