From: ArthurHoaro Date: Tue, 28 Jul 2020 20:24:41 +0000 (+0200) Subject: Fix basePath in unit tests reference DB X-Git-Tag: v0.12.0-beta~4^2~4 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=f7f08ceec1b218e1525153e8bd3d0199f2fb1c9d;p=github%2Fshaarli%2FShaarli.git Fix basePath in unit tests reference DB --- diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php index 92c0e911..707489d0 100644 --- a/application/front/ShaarliMiddleware.php +++ b/application/front/ShaarliMiddleware.php @@ -93,6 +93,7 @@ class ShaarliMiddleware return; } + $this->container->updater->setBasePath($this->container->basePath); $newUpdates = $this->container->updater->update(); if (!empty($newUpdates)) { $this->container->updater->writeUpdates( diff --git a/application/updater/Updater.php b/application/updater/Updater.php index 4c578528..88a7bc7b 100644 --- a/application/updater/Updater.php +++ b/application/updater/Updater.php @@ -157,7 +157,7 @@ class Updater && 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match) ) { $updated = true; - $bookmark = $bookmark->setUrl($this->basePath . '/shaare/' . $match[1]); + $bookmark = $bookmark->setUrl('/shaare/' . $match[1]); $this->bookmarkService->set($bookmark, false); } diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index c26411ac..8bb81dc8 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -102,7 +102,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase $this->assertEquals($id, $data['id']); // Check link elements - $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); + $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); $this->assertEquals('WDWyig', $data['shorturl']); $this->assertEquals('Link title: @website', $data['title']); $this->assertEquals( diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 4e2d55ac..d02e6fad 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -109,7 +109,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase // Check first element fields $first = $data[2]; - $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); + $this->assertEquals('http://domain.tld/shaare/WDWyig', $first['url']); $this->assertEquals('WDWyig', $first['shorturl']); $this->assertEquals('Link title: @website', $first['title']); $this->assertEquals( diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index a8bf47cb..7b1906d3 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -340,7 +340,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(42); $this->assertEquals(42, $bookmark->getId()); - $this->assertEquals('?WDWyig', $bookmark->getUrl()); + $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); @@ -359,7 +359,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(42); $this->assertEquals(42, $bookmark->getId()); - $this->assertEquals('?WDWyig', $bookmark->getUrl()); + $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index b2b70b70..5c2aaedb 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php @@ -90,15 +90,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase $link = $data['links'][array_keys($data['links'])[2]]; $this->assertEquals(41, $link['id']); $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); - $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); - $this->assertEquals('http://host.tld/?WDWyig', $link['url']); + $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); + $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); $this->assertEquals($pub, $up); $this->assertContains('Stallman has a beard', $link['description']); $this->assertContains('Permalink', $link['description']); - $this->assertContains('http://host.tld/?WDWyig', $link['description']); + $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); $this->assertEquals(1, count($link['taglist'])); $this->assertEquals('sTuff', $link['taglist'][0]); @@ -198,15 +198,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase $link = $data['links'][array_keys($data['links'])[2]]; $this->assertEquals(41, $link['id']); $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); - $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); - $this->assertEquals('http://host.tld/?WDWyig', $link['url']); + $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); + $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); $this->assertContains('Direct link', $link['description']); - $this->assertContains('http://host.tld/?WDWyig', $link['description']); + $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); // Second link is a direct link $link = $data['links'][array_keys($data['links'])[3]]; $this->assertEquals(8, $link['id']); $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); - $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); + $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); $this->assertContains('Direct link', $link['description']); $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); @@ -271,8 +271,8 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase // Test first link (note link) $link = $data['links'][array_keys($data['links'])[2]]; - $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']); - $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']); + $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); + $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); } } diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 344c1dc0..509da51d 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -177,7 +177,7 @@ class BookmarkExportTest extends TestCase '' ); $this->assertEquals( - '?WDWyig', + '/shaare/WDWyig', $links[2]['url'] ); } @@ -195,7 +195,7 @@ class BookmarkExportTest extends TestCase $indexUrl ); $this->assertEquals( - $indexUrl . '?WDWyig', + $indexUrl . 'shaare/WDWyig', $links[2]['url'] ); } diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index c801d451..a7dd70bf 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,6 +2,7 @@ namespace Shaarli\Updater; use Exception; +use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; @@ -12,7 +13,7 @@ use Shaarli\History; * 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. @@ -194,7 +195,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase public function testUpdateMethodRelativeHomeLinkDoNotRename(): void { - $this->updater->setBasePath('/subfolder'); $this->conf->set('general.header_link', '~/my-blog'); $this->updater->updateMethodRelativeHomeLink(); @@ -204,8 +204,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase public function testUpdateMethodMigrateExistingNotesUrl(): void { - $this->updater->setBasePath('/subfolder'); - $this->updater->updateMethodMigrateExistingNotesUrl(); static::assertSame($this->refDB->getLinks()[0]->getUrl(), $this->bookmarkService->get(0)->getUrl()); @@ -215,9 +213,9 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase 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('/subfolder/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl()); - static::assertSame('/subfolder/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl()); - static::assertSame('/subfolder/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl()); - static::assertSame('/subfolder/shaare/PCRizQ', $this->bookmarkService->get(11)->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()); } } diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 0095f5a1..fc3cb109 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php @@ -30,7 +30,7 @@ class ReferenceLinkDB $this->addLink( 11, 'Pined older', - '?PCRizQ', + '/shaare/PCRizQ', 'This is an older pinned link', 0, DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100309_101010'), @@ -43,7 +43,7 @@ class ReferenceLinkDB $this->addLink( 10, 'Pined', - '?0gCTjQ', + '/shaare/0gCTjQ', 'This is a pinned link', 0, DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20121207_152312'), @@ -56,7 +56,7 @@ class ReferenceLinkDB $this->addLink( 41, 'Link title: @website', - '?WDWyig', + '/shaare/WDWyig', 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag', 0, DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), @@ -68,7 +68,7 @@ class ReferenceLinkDB $this->addLink( 42, 'Note: I have a big ID but an old date', - '?WDWyig', + '/shaare/WDWyig', 'Used to test bookmarks reordering.', 0, DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100310_101010'),