X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fupdater%2FUpdaterTest.php;h=73029e07395cdab39040c7285f5273d29740f04d;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=c689982b49ea15551b230290b76dbf50caa9f203;hpb=e26e2060f5470ce8bf4c5973284bae07b8af170a;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index c689982b..73029e07 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,17 +2,18 @@ namespace Shaarli\Updater; use Exception; +use Shaarli\Bookmark\BookmarkFileService; +use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\History; +use Shaarli\TestCase; -require_once 'tests/updater/DummyUpdater.php'; -require_once 'tests/utils/ReferenceLinkDB.php'; -require_once 'inc/rain.tpl.class.php'; /** * Class UpdaterTest. * Runs unit tests against the updater class. */ -class UpdaterTest extends \PHPUnit\Framework\TestCase +class UpdaterTest extends TestCase { /** * @var string Path to test datastore. @@ -29,13 +30,27 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase */ protected $conf; + /** @var BookmarkServiceInterface */ + protected $bookmarkService; + + /** @var \ReferenceLinkDB */ + protected $refDB; + + /** @var Updater */ + protected $updater; + /** * Executed before each test. */ - public function setUp() + protected function setUp(): void { + $this->refDB = new \ReferenceLinkDB(); + $this->refDB->write(self::$testDatastore); + copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); $this->conf = new ConfigManager(self::$configFile); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), true); + $this->updater = new Updater([], $this->bookmarkService, $this->conf, true); } /** @@ -74,10 +89,11 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase * Test errors in UpdaterUtils::write_updates_file(): empty updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/ */ public function testWriteEmptyUpdatesFile() { + $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); + UpdaterUtils::write_updates_file('', array('test')); } @@ -85,10 +101,11 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Unable to write(.*)/ */ public function testWriteUpdatesFileNotWritable() { + $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); @@ -153,11 +170,11 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase /** * Test Update failed. - * - * @expectedException \Exception */ public function testUpdateFailed() { + $this->expectException(\Exception::class); + $updates = array( 'updateMethodDummy1', 'updateMethodDummy2', @@ -167,4 +184,40 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase $updater = new DummyUpdater($updates, array(), $this->conf, true); $updater->update(); } + + public function testUpdateMethodRelativeHomeLinkRename(): void + { + $this->updater->setBasePath('/subfolder'); + $this->conf->set('general.header_link', '?'); + + $this->updater->updateMethodRelativeHomeLink(); + + static::assertSame('/subfolder/', $this->conf->get('general.header_link')); + } + + public function testUpdateMethodRelativeHomeLinkDoNotRename(): void + { + $this->conf->set('general.header_link', '~/my-blog'); + + $this->updater->updateMethodRelativeHomeLink(); + + static::assertSame('~/my-blog', $this->conf->get('general.header_link')); + } + + public function testUpdateMethodMigrateExistingNotesUrl(): void + { + $this->updater->updateMethodMigrateExistingNotesUrl(); + + static::assertSame($this->refDB->getLinks()[0]->getUrl(), $this->bookmarkService->get(0)->getUrl()); + static::assertSame($this->refDB->getLinks()[1]->getUrl(), $this->bookmarkService->get(1)->getUrl()); + static::assertSame($this->refDB->getLinks()[4]->getUrl(), $this->bookmarkService->get(4)->getUrl()); + static::assertSame($this->refDB->getLinks()[6]->getUrl(), $this->bookmarkService->get(6)->getUrl()); + static::assertSame($this->refDB->getLinks()[7]->getUrl(), $this->bookmarkService->get(7)->getUrl()); + static::assertSame($this->refDB->getLinks()[8]->getUrl(), $this->bookmarkService->get(8)->getUrl()); + static::assertSame($this->refDB->getLinks()[9]->getUrl(), $this->bookmarkService->get(9)->getUrl()); + static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl()); + static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl()); + static::assertSame('/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl()); + static::assertSame('/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl()); + } }