X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fnetscape%2FBookmarkExportTest.php;h=ad288f78ef802835f238e8d40f4c6c8d9bd2059d;hb=47d15818502b11315b484131aaf67a3e3f441c5a;hp=6de9876d419701cd76bcf7078b3c57a718e13510;hpb=349b0144011e25f2b1a727b1d28d49d55b3b2ebb;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 6de9876d..ad288f78 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -1,56 +1,109 @@ write(self::$testDatastore); - self::$linkDb = new LinkDB(self::$testDatastore, true, false); + $mutex = new NoMutex(); + static::$conf = new ConfigManager('tests/utils/config/configJson'); + static::$conf->set('resource.datastore', static::$testDatastore); + static::$refDb = new \ReferenceLinkDB(); + static::$refDb->write(static::$testDatastore); + static::$history = new History('sandbox/history.php'); + static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, $mutex, true); + $factory = new FormatterFactory(static::$conf, true); + static::$formatter = $factory->getFormatter('raw'); + } + + public function setUp(): void + { + $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils( + static::$bookmarkService, + static::$conf, + static::$history + ); } /** * Attempt to export an invalid link selection - * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid export selection/ */ public function testFilterAndFormatInvalid() { - NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, ''); + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Invalid export selection/'); + + $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, + 'derp', + false, + '' + ); } /** - * Prepare all links for export + * Prepare all bookmarks for export */ public function testFilterAndFormatAll() { - $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); + $links = $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, + 'all', + false, + '' + ); $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); foreach ($links as $link) { $date = $link['created']; @@ -66,11 +119,16 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase } /** - * Prepare private links for export + * Prepare private bookmarks for export */ public function testFilterAndFormatPrivate() { - $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); + $links = $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, + 'private', + false, + '' + ); $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); foreach ($links as $link) { $date = $link['created']; @@ -86,11 +144,16 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase } /** - * Prepare public links for export + * Prepare public bookmarks for export */ public function testFilterAndFormatPublic() { - $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); + $links = $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, + 'public', + false, + '' + ); $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); foreach ($links as $link) { $date = $link['created']; @@ -110,9 +173,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatDoNotPrependNoteUrl() { - $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); + $links = $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, + 'public', + false, + '' + ); $this->assertEquals( - '?WDWyig', + '/shaare/WDWyig', $links[2]['url'] ); } @@ -123,14 +191,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase public function testFilterAndFormatPrependNoteUrl() { $indexUrl = 'http://localhost:7469/shaarli/'; - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$linkDb, + $links = $this->netscapeBookmarkUtils->filterAndFormat( + self::$formatter, 'public', true, $indexUrl ); $this->assertEquals( - $indexUrl . '?WDWyig', + $indexUrl . 'shaare/WDWyig', $links[2]['url'] ); }