3 namespace Shaarli\Bookmark
;
5 use PHPUnit\Framework\TestCase
;
7 use Shaarli\Config\ConfigManager
;
11 * Class BookmarkInitializerTest
12 * @package Shaarli\Bookmark
14 class BookmarkInitializerTest
extends TestCase
16 /** @var string Path of test data store */
17 protected static $testDatastore = 'sandbox/datastore.php';
19 /** @var string Path of test config file */
20 protected static $testConf = 'sandbox/config';
23 * @var ConfigManager instance.
28 * @var History instance.
32 /** @var BookmarkServiceInterface instance */
33 protected $bookmarkService;
35 /** @var BookmarkInitializer instance */
36 protected $initializer;
39 * Initialize an empty BookmarkFileService
41 public function setUp()
43 if (file_exists(self
::$testDatastore)) {
44 unlink(self
::$testDatastore);
47 copy('tests/utils/config/configJson.json.php', self
::$testConf .'.json.php');
48 $this->conf
= new ConfigManager(self
::$testConf);
49 $this->conf
->set('resource.datastore', self
::$testDatastore);
50 $this->history
= new History('sandbox/history.php');
51 $this->bookmarkService
= new BookmarkFileService($this->conf
, $this->history
, true);
53 $this->initializer
= new BookmarkInitializer($this->bookmarkService
);
57 * Test initialize() with an empty data store.
59 public function testInitializeEmptyDataStore()
61 $refDB = new \
ReferenceLinkDB();
62 $refDB->write(self
::$testDatastore);
63 $this->bookmarkService
= new BookmarkFileService($this->conf
, $this->history
, true);
64 $this->initializer
= new BookmarkInitializer($this->bookmarkService
);
66 $this->initializer
->initialize();
68 $this->assertEquals($refDB->countLinks() +
2, $this->bookmarkService
->count());
69 $bookmark = $this->bookmarkService
->get(43);
70 $this->assertEquals(43, $bookmark->getId());
71 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle());
72 $this->assertTrue($bookmark->isPrivate());
74 $bookmark = $this->bookmarkService
->get(44);
75 $this->assertEquals(44, $bookmark->getId());
77 'The personal, minimalist, super-fast, database free, bookmarking service',
80 $this->assertFalse($bookmark->isPrivate());
83 $this->bookmarkService
= new BookmarkFileService($this->conf
, $this->history
, true);
84 $this->assertEquals($refDB->countLinks() +
2, $this->bookmarkService
->count());
85 $bookmark = $this->bookmarkService
->get(43);
86 $this->assertEquals(43, $bookmark->getId());
87 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle());
88 $this->assertTrue($bookmark->isPrivate());
90 $bookmark = $this->bookmarkService
->get(44);
91 $this->assertEquals(44, $bookmark->getId());
93 'The personal, minimalist, super-fast, database free, bookmarking service',
96 $this->assertFalse($bookmark->isPrivate());
100 * Test initialize() with a data store containing bookmarks.
102 public function testInitializeNotEmptyDataStore()
104 $this->initializer
->initialize();
106 $this->assertEquals(2, $this->bookmarkService
->count());
107 $bookmark = $this->bookmarkService
->get(0);
108 $this->assertEquals(0, $bookmark->getId());
109 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle());
110 $this->assertTrue($bookmark->isPrivate());
112 $bookmark = $this->bookmarkService
->get(1);
113 $this->assertEquals(1, $bookmark->getId());
115 'The personal, minimalist, super-fast, database free, bookmarking service',
116 $bookmark->getTitle()
118 $this->assertFalse($bookmark->isPrivate());