3 namespace Shaarli\Bookmark
;
5 use malkusch\lock\mutex\NoMutex
;
6 use Shaarli\Config\ConfigManager
;
8 use Shaarli\Plugin\PluginManager
;
12 * Class BookmarkInitializerTest
13 * @package Shaarli\Bookmark
15 class BookmarkInitializerTest
extends TestCase
17 /** @var string Path of test data store */
18 protected static $testDatastore = 'sandbox/datastore.php';
20 /** @var string Path of test config file */
21 protected static $testConf = 'sandbox/config';
24 * @var ConfigManager instance.
29 * @var History instance.
33 /** @var BookmarkServiceInterface instance */
34 protected $bookmarkService;
36 /** @var BookmarkInitializer instance */
37 protected $initializer;
42 /** @var PluginManager */
43 protected $pluginManager;
46 * Initialize an empty BookmarkFileService
48 public function setUp(): void
50 $this->mutex
= new NoMutex();
51 if (file_exists(self
::$testDatastore)) {
52 unlink(self
::$testDatastore);
55 copy('tests/utils/config/configJson.json.php', self
::$testConf .'.json.php');
56 $this->conf
= new ConfigManager(self
::$testConf);
57 $this->conf
->set('resource.datastore', self
::$testDatastore);
58 $this->pluginManager
= new PluginManager($this->conf
);
59 $this->history
= new History('sandbox/history.php');
60 $this->bookmarkService
= new BookmarkFileService(
68 $this->initializer
= new BookmarkInitializer($this->bookmarkService
);
72 * Test initialize() with a data store containing bookmarks.
74 public function testInitializeNotEmptyDataStore(): void
76 $refDB = new \
ReferenceLinkDB();
77 $refDB->write(self
::$testDatastore);
78 $this->bookmarkService
= new BookmarkFileService(
85 $this->initializer
= new BookmarkInitializer($this->bookmarkService
);
87 $this->initializer
->initialize();
89 $this->assertEquals($refDB->countLinks() +
3, $this->bookmarkService
->count());
91 $bookmark = $this->bookmarkService
->get(43);
92 $this->assertStringStartsWith(
93 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
94 $bookmark->getDescription()
96 $this->assertTrue($bookmark->isPrivate());
98 $bookmark = $this->bookmarkService
->get(44);
99 $this->assertStringStartsWith(
100 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
101 $bookmark->getDescription()
103 $this->assertTrue($bookmark->isPrivate());
105 $bookmark = $this->bookmarkService
->get(45);
106 $this->assertStringStartsWith(
107 'Welcome to Shaarli!',
108 $bookmark->getDescription()
110 $this->assertFalse($bookmark->isPrivate());
112 $this->bookmarkService
->save();
115 $this->bookmarkService
= new BookmarkFileService(
117 $this->pluginManager
,
122 $this->assertEquals($refDB->countLinks() +
3, $this->bookmarkService
->count());
124 $bookmark = $this->bookmarkService
->get(43);
125 $this->assertStringStartsWith(
126 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
127 $bookmark->getDescription()
129 $this->assertTrue($bookmark->isPrivate());
131 $bookmark = $this->bookmarkService
->get(44);
132 $this->assertStringStartsWith(
133 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
134 $bookmark->getDescription()
136 $this->assertTrue($bookmark->isPrivate());
138 $bookmark = $this->bookmarkService
->get(45);
139 $this->assertStringStartsWith(
140 'Welcome to Shaarli!',
141 $bookmark->getDescription()
143 $this->assertFalse($bookmark->isPrivate());
147 * Test initialize() with an a non existent datastore file .
149 public function testInitializeNonExistentDataStore(): void
151 $this->conf
->set('resource.datastore', static::$testDatastore . '_empty');
152 $this->bookmarkService
= new BookmarkFileService(
154 $this->pluginManager
,
160 $this->initializer
->initialize();
162 $this->assertEquals(3, $this->bookmarkService
->count());
163 $bookmark = $this->bookmarkService
->get(0);
164 $this->assertStringStartsWith(
165 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
166 $bookmark->getDescription()
168 $this->assertTrue($bookmark->isPrivate());
170 $bookmark = $this->bookmarkService
->get(1);
171 $this->assertStringStartsWith(
172 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
173 $bookmark->getDescription()
175 $this->assertTrue($bookmark->isPrivate());
177 $bookmark = $this->bookmarkService
->get(2);
178 $this->assertStringStartsWith(
179 'Welcome to Shaarli!',
180 $bookmark->getDescription()
182 $this->assertFalse($bookmark->isPrivate());