From e8a10f312a5c44314292402bb44e6ee2e71f3d5d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 17 Jun 2020 15:55:31 +0200 Subject: Use NetscapeBookmarkUtils object instance instead of static calls --- tests/netscape/BookmarkExportTest.php | 65 ++++++++++++++++++++++------------- tests/netscape/BookmarkImportTest.php | 53 +++++++++++++++------------- 2 files changed, 72 insertions(+), 46 deletions(-) (limited to 'tests/netscape') diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 6c948bba..344c1dc0 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -1,11 +1,12 @@ set('resource.datastore', self::$testDatastore); - self::$refDb = new \ReferenceLinkDB(); - self::$refDb->write(self::$testDatastore); - $history = new History('sandbox/history.php'); - self::$bookmarkService = new BookmarkFileService($conf, $history, true); - $factory = new FormatterFactory($conf, true); - self::$formatter = $factory->getFormatter('raw'); + 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, 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 + ); } /** @@ -57,8 +82,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatInvalid() { - NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'derp', false, @@ -71,8 +95,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatAll() { - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $links = $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'all', false, @@ -97,8 +120,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatPrivate() { - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $links = $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'private', false, @@ -123,8 +145,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatPublic() { - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $links = $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'public', false, @@ -149,8 +170,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase */ public function testFilterAndFormatDoNotPrependNoteUrl() { - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $links = $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'public', false, @@ -168,8 +188,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase public function testFilterAndFormatPrependNoteUrl() { $indexUrl = 'http://localhost:7469/shaarli/'; - $links = NetscapeBookmarkUtils::filterAndFormat( - self::$bookmarkService, + $links = $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'public', true, diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index fef7f6d1..20b1c6f4 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php @@ -1,11 +1,12 @@ conf->set('resource.datastore', self::$testDatastore); $this->history = new History(self::$historyFilePath); $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history); } /** @@ -115,7 +122,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertEquals( 'File empty.htm (0 bytes) has an unknown file format.' .' Nothing was imported.', - NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import(null, $files) ); $this->assertEquals(0, $this->bookmarkService->count()); } @@ -128,7 +135,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $files = file2array('no_doctype.htm'); $this->assertEquals( 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', - NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import(null, $files) ); $this->assertEquals(0, $this->bookmarkService->count()); } @@ -142,7 +149,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import(null, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import(null, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); } @@ -157,7 +164,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:' .' 1 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import([], $files) ); $this->assertEquals(1, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -185,7 +192,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:' .' 8 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import([], $files) ); $this->assertEquals(8, $this->bookmarkService->count()); $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -306,7 +313,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import([], $files) ); $this->assertEquals(2, $this->bookmarkService->count()); @@ -349,7 +356,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); @@ -392,7 +399,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -410,7 +417,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -430,7 +437,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -445,7 +452,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -465,7 +472,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -480,7 +487,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -498,7 +505,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -508,7 +515,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -527,7 +534,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -548,7 +555,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import($post, $files) ); $this->assertEquals(2, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -573,7 +580,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase $this->assertStringMatchesFormat( 'File same_date.htm (453 bytes) was successfully processed in %d seconds:' .' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', - NetscapeBookmarkUtils::import(array(), $files, $this->bookmarkService, $this->conf, $this->history) + $this->netscapeBookmarkUtils->import(array(), $files) ); $this->assertEquals(3, $this->bookmarkService->count()); $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); @@ -589,14 +596,14 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase 'overwrite' => 'true', ]; $files = file2array('netscape_basic.htm'); - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history); + $this->netscapeBookmarkUtils->import($post, $files); $history = $this->history->getHistory(); $this->assertEquals(1, count($history)); $this->assertEquals(History::IMPORT, $history[0]['event']); $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']); // re-import as private, enable overwriting - NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history); + $this->netscapeBookmarkUtils->import($post, $files); $history = $this->history->getHistory(); $this->assertEquals(2, count($history)); $this->assertEquals(History::IMPORT, $history[0]['event']); -- cgit v1.2.3