aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/BookmarkInitializerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bookmark/BookmarkInitializerTest.php')
-rw-r--r--tests/bookmark/BookmarkInitializerTest.php97
1 files changed, 66 insertions, 31 deletions
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 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase; 5use malkusch\lock\mutex\NoMutex;
6use ReferenceLinkDB;
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
8use Shaarli\History; 7use Shaarli\History;
8use Shaarli\TestCase;
9 9
10/** 10/**
11 * Class BookmarkInitializerTest 11 * Class BookmarkInitializerTest
@@ -35,11 +35,15 @@ class BookmarkInitializerTest extends TestCase
35 /** @var BookmarkInitializer instance */ 35 /** @var BookmarkInitializer instance */
36 protected $initializer; 36 protected $initializer;
37 37
38 /** @var NoMutex */
39 protected $mutex;
40
38 /** 41 /**
39 * Initialize an empty BookmarkFileService 42 * Initialize an empty BookmarkFileService
40 */ 43 */
41 public function setUp() 44 public function setUp(): void
42 { 45 {
46 $this->mutex = new NoMutex();
43 if (file_exists(self::$testDatastore)) { 47 if (file_exists(self::$testDatastore)) {
44 unlink(self::$testDatastore); 48 unlink(self::$testDatastore);
45 } 49 }
@@ -48,72 +52,103 @@ class BookmarkInitializerTest extends TestCase
48 $this->conf = new ConfigManager(self::$testConf); 52 $this->conf = new ConfigManager(self::$testConf);
49 $this->conf->set('resource.datastore', self::$testDatastore); 53 $this->conf->set('resource.datastore', self::$testDatastore);
50 $this->history = new History('sandbox/history.php'); 54 $this->history = new History('sandbox/history.php');
51 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 55 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
52 56
53 $this->initializer = new BookmarkInitializer($this->bookmarkService); 57 $this->initializer = new BookmarkInitializer($this->bookmarkService);
54 } 58 }
55 59
56 /** 60 /**
57 * Test initialize() with an empty data store. 61 * Test initialize() with a data store containing bookmarks.
58 */ 62 */
59 public function testInitializeEmptyDataStore() 63 public function testInitializeNotEmptyDataStore(): void
60 { 64 {
61 $refDB = new \ReferenceLinkDB(); 65 $refDB = new \ReferenceLinkDB();
62 $refDB->write(self::$testDatastore); 66 $refDB->write(self::$testDatastore);
63 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 67 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
64 $this->initializer = new BookmarkInitializer($this->bookmarkService); 68 $this->initializer = new BookmarkInitializer($this->bookmarkService);
65 69
66 $this->initializer->initialize(); 70 $this->initializer->initialize();
67 71
68 $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); 72 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
73
69 $bookmark = $this->bookmarkService->get(43); 74 $bookmark = $this->bookmarkService->get(43);
70 $this->assertEquals(43, $bookmark->getId()); 75 $this->assertStringStartsWith(
71 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 76 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
77 $bookmark->getDescription()
78 );
72 $this->assertTrue($bookmark->isPrivate()); 79 $this->assertTrue($bookmark->isPrivate());
73 80
74 $bookmark = $this->bookmarkService->get(44); 81 $bookmark = $this->bookmarkService->get(44);
75 $this->assertEquals(44, $bookmark->getId()); 82 $this->assertStringStartsWith(
76 $this->assertEquals( 83 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
77 'The personal, minimalist, super-fast, database free, bookmarking service', 84 $bookmark->getDescription()
78 $bookmark->getTitle() 85 );
86 $this->assertTrue($bookmark->isPrivate());
87
88 $bookmark = $this->bookmarkService->get(45);
89 $this->assertStringStartsWith(
90 'Welcome to Shaarli!',
91 $bookmark->getDescription()
79 ); 92 );
80 $this->assertFalse($bookmark->isPrivate()); 93 $this->assertFalse($bookmark->isPrivate());
81 94
95 $this->bookmarkService->save();
96
82 // Reload from file 97 // Reload from file
83 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 98 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
84 $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); 99 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
100
85 $bookmark = $this->bookmarkService->get(43); 101 $bookmark = $this->bookmarkService->get(43);
86 $this->assertEquals(43, $bookmark->getId()); 102 $this->assertStringStartsWith(
87 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 103 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
104 $bookmark->getDescription()
105 );
88 $this->assertTrue($bookmark->isPrivate()); 106 $this->assertTrue($bookmark->isPrivate());
89 107
90 $bookmark = $this->bookmarkService->get(44); 108 $bookmark = $this->bookmarkService->get(44);
91 $this->assertEquals(44, $bookmark->getId()); 109 $this->assertStringStartsWith(
92 $this->assertEquals( 110 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
93 'The personal, minimalist, super-fast, database free, bookmarking service', 111 $bookmark->getDescription()
94 $bookmark->getTitle() 112 );
113 $this->assertTrue($bookmark->isPrivate());
114
115 $bookmark = $this->bookmarkService->get(45);
116 $this->assertStringStartsWith(
117 'Welcome to Shaarli!',
118 $bookmark->getDescription()
95 ); 119 );
96 $this->assertFalse($bookmark->isPrivate()); 120 $this->assertFalse($bookmark->isPrivate());
97 } 121 }
98 122
99 /** 123 /**
100 * Test initialize() with a data store containing bookmarks. 124 * Test initialize() with an a non existent datastore file .
101 */ 125 */
102 public function testInitializeNotEmptyDataStore() 126 public function testInitializeNonExistentDataStore(): void
103 { 127 {
128 $this->conf->set('resource.datastore', static::$testDatastore . '_empty');
129 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
130
104 $this->initializer->initialize(); 131 $this->initializer->initialize();
105 132
106 $this->assertEquals(2, $this->bookmarkService->count()); 133 $this->assertEquals(3, $this->bookmarkService->count());
107 $bookmark = $this->bookmarkService->get(0); 134 $bookmark = $this->bookmarkService->get(0);
108 $this->assertEquals(0, $bookmark->getId()); 135 $this->assertStringStartsWith(
109 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 136 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
137 $bookmark->getDescription()
138 );
110 $this->assertTrue($bookmark->isPrivate()); 139 $this->assertTrue($bookmark->isPrivate());
111 140
112 $bookmark = $this->bookmarkService->get(1); 141 $bookmark = $this->bookmarkService->get(1);
113 $this->assertEquals(1, $bookmark->getId()); 142 $this->assertStringStartsWith(
114 $this->assertEquals( 143 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
115 'The personal, minimalist, super-fast, database free, bookmarking service', 144 $bookmark->getDescription()
116 $bookmark->getTitle() 145 );
146 $this->assertTrue($bookmark->isPrivate());
147
148 $bookmark = $this->bookmarkService->get(2);
149 $this->assertStringStartsWith(
150 'Welcome to Shaarli!',
151 $bookmark->getDescription()
117 ); 152 );
118 $this->assertFalse($bookmark->isPrivate()); 153 $this->assertFalse($bookmark->isPrivate());
119 } 154 }