aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/updater
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-27 10:27:34 +0200
committerGitHub <noreply@github.com>2020-08-27 10:27:34 +0200
commitaf41d5ab5d2bd3ba64d052c997bc6afa6966a63c (patch)
tree8fad2829c55f94022e359fa8914e11f80a2afc2a /tests/updater
parentb8e3630f2ecd142d397b1b062a346a667bb78595 (diff)
parent0c6fdbe12bbbb336348666b14b82096f24d5858b (diff)
downloadShaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.gz
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.zst
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.zip
Merge pull request #1511 from ArthurHoaro/wip-slim-routing
Diffstat (limited to 'tests/updater')
-rw-r--r--tests/updater/UpdaterTest.php59
1 files changed, 55 insertions, 4 deletions
diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index c689982b..a7dd70bf 100644
--- a/tests/updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -2,17 +2,18 @@
2namespace Shaarli\Updater; 2namespace Shaarli\Updater;
3 3
4use Exception; 4use Exception;
5use PHPUnit\Framework\TestCase;
6use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\BookmarkServiceInterface;
5use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History;
6 10
7require_once 'tests/updater/DummyUpdater.php';
8require_once 'tests/utils/ReferenceLinkDB.php';
9require_once 'inc/rain.tpl.class.php';
10 11
11/** 12/**
12 * Class UpdaterTest. 13 * Class UpdaterTest.
13 * Runs unit tests against the updater class. 14 * Runs unit tests against the updater class.
14 */ 15 */
15class UpdaterTest extends \PHPUnit\Framework\TestCase 16class UpdaterTest extends TestCase
16{ 17{
17 /** 18 /**
18 * @var string Path to test datastore. 19 * @var string Path to test datastore.
@@ -29,13 +30,27 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase
29 */ 30 */
30 protected $conf; 31 protected $conf;
31 32
33 /** @var BookmarkServiceInterface */
34 protected $bookmarkService;
35
36 /** @var \ReferenceLinkDB */
37 protected $refDB;
38
39 /** @var Updater */
40 protected $updater;
41
32 /** 42 /**
33 * Executed before each test. 43 * Executed before each test.
34 */ 44 */
35 public function setUp() 45 public function setUp()
36 { 46 {
47 $this->refDB = new \ReferenceLinkDB();
48 $this->refDB->write(self::$testDatastore);
49
37 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); 50 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
38 $this->conf = new ConfigManager(self::$configFile); 51 $this->conf = new ConfigManager(self::$configFile);
52 $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), true);
53 $this->updater = new Updater([], $this->bookmarkService, $this->conf, true);
39 } 54 }
40 55
41 /** 56 /**
@@ -167,4 +182,40 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase
167 $updater = new DummyUpdater($updates, array(), $this->conf, true); 182 $updater = new DummyUpdater($updates, array(), $this->conf, true);
168 $updater->update(); 183 $updater->update();
169 } 184 }
185
186 public function testUpdateMethodRelativeHomeLinkRename(): void
187 {
188 $this->updater->setBasePath('/subfolder');
189 $this->conf->set('general.header_link', '?');
190
191 $this->updater->updateMethodRelativeHomeLink();
192
193 static::assertSame('/subfolder/', $this->conf->get('general.header_link'));
194 }
195
196 public function testUpdateMethodRelativeHomeLinkDoNotRename(): void
197 {
198 $this->conf->set('general.header_link', '~/my-blog');
199
200 $this->updater->updateMethodRelativeHomeLink();
201
202 static::assertSame('~/my-blog', $this->conf->get('general.header_link'));
203 }
204
205 public function testUpdateMethodMigrateExistingNotesUrl(): void
206 {
207 $this->updater->updateMethodMigrateExistingNotesUrl();
208
209 static::assertSame($this->refDB->getLinks()[0]->getUrl(), $this->bookmarkService->get(0)->getUrl());
210 static::assertSame($this->refDB->getLinks()[1]->getUrl(), $this->bookmarkService->get(1)->getUrl());
211 static::assertSame($this->refDB->getLinks()[4]->getUrl(), $this->bookmarkService->get(4)->getUrl());
212 static::assertSame($this->refDB->getLinks()[6]->getUrl(), $this->bookmarkService->get(6)->getUrl());
213 static::assertSame($this->refDB->getLinks()[7]->getUrl(), $this->bookmarkService->get(7)->getUrl());
214 static::assertSame($this->refDB->getLinks()[8]->getUrl(), $this->bookmarkService->get(8)->getUrl());
215 static::assertSame($this->refDB->getLinks()[9]->getUrl(), $this->bookmarkService->get(9)->getUrl());
216 static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl());
217 static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl());
218 static::assertSame('/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl());
219 static::assertSame('/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl());
220 }
170} 221}