Fix basePath in unit tests reference DB

This commit is contained in:
ArthurHoaro 2020-07-28 22:24:41 +02:00
parent 624123177f
commit f7f08ceec1
9 changed files with 27 additions and 28 deletions

View file

@ -93,6 +93,7 @@ class ShaarliMiddleware
return; return;
} }
$this->container->updater->setBasePath($this->container->basePath);
$newUpdates = $this->container->updater->update(); $newUpdates = $this->container->updater->update();
if (!empty($newUpdates)) { if (!empty($newUpdates)) {
$this->container->updater->writeUpdates( $this->container->updater->writeUpdates(

View file

@ -157,7 +157,7 @@ class Updater
&& 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match) && 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match)
) { ) {
$updated = true; $updated = true;
$bookmark = $bookmark->setUrl($this->basePath . '/shaare/' . $match[1]); $bookmark = $bookmark->setUrl('/shaare/' . $match[1]);
$this->bookmarkService->set($bookmark, false); $this->bookmarkService->set($bookmark, false);
} }

View file

@ -102,7 +102,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($id, $data['id']); $this->assertEquals($id, $data['id']);
// Check link elements // 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('WDWyig', $data['shorturl']);
$this->assertEquals('Link title: @website', $data['title']); $this->assertEquals('Link title: @website', $data['title']);
$this->assertEquals( $this->assertEquals(

View file

@ -109,7 +109,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
// Check first element fields // Check first element fields
$first = $data[2]; $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('WDWyig', $first['shorturl']);
$this->assertEquals('Link title: @website', $first['title']); $this->assertEquals('Link title: @website', $first['title']);
$this->assertEquals( $this->assertEquals(

View file

@ -340,7 +340,7 @@ class BookmarkFileServiceTest extends TestCase
$bookmark = $this->privateLinkDB->get(42); $bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId()); $this->assertEquals(42, $bookmark->getId());
$this->assertEquals('?WDWyig', $bookmark->getUrl()); $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl());
$this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl());
$this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
$this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription());
@ -359,7 +359,7 @@ class BookmarkFileServiceTest extends TestCase
$bookmark = $this->privateLinkDB->get(42); $bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId()); $this->assertEquals(42, $bookmark->getId());
$this->assertEquals('?WDWyig', $bookmark->getUrl()); $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl());
$this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl());
$this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
$this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription());

View file

@ -90,15 +90,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
$link = $data['links'][array_keys($data['links'])[2]]; $link = $data['links'][array_keys($data['links'])[2]];
$this->assertEquals(41, $link['id']); $this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); $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/shaare/WDWyig', $link['guid']);
$this->assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
$pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
$up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
$this->assertEquals($pub, $up); $this->assertEquals($pub, $up);
$this->assertContains('Stallman has a beard', $link['description']); $this->assertContains('Stallman has a beard', $link['description']);
$this->assertContains('Permalink', $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(1, count($link['taglist']));
$this->assertEquals('sTuff', $link['taglist'][0]); $this->assertEquals('sTuff', $link['taglist'][0]);
@ -198,15 +198,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
$link = $data['links'][array_keys($data['links'])[2]]; $link = $data['links'][array_keys($data['links'])[2]];
$this->assertEquals(41, $link['id']); $this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); $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/shaare/WDWyig', $link['guid']);
$this->assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
$this->assertContains('Direct link', $link['description']); $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 // Second link is a direct link
$link = $data['links'][array_keys($data['links'])[3]]; $link = $data['links'][array_keys($data['links'])[3]];
$this->assertEquals(8, $link['id']); $this->assertEquals(8, $link['id']);
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); $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->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
$this->assertContains('Direct link', $link['description']); $this->assertContains('Direct link', $link['description']);
$this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $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) // Test first link (note link)
$link = $data['links'][array_keys($data['links'])[2]]; $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/shaare/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['url']);
$this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
} }
} }

View file

@ -177,7 +177,7 @@ class BookmarkExportTest extends TestCase
'' ''
); );
$this->assertEquals( $this->assertEquals(
'?WDWyig', '/shaare/WDWyig',
$links[2]['url'] $links[2]['url']
); );
} }
@ -195,7 +195,7 @@ class BookmarkExportTest extends TestCase
$indexUrl $indexUrl
); );
$this->assertEquals( $this->assertEquals(
$indexUrl . '?WDWyig', $indexUrl . 'shaare/WDWyig',
$links[2]['url'] $links[2]['url']
); );
} }

View file

@ -2,6 +2,7 @@
namespace Shaarli\Updater; namespace Shaarli\Updater;
use Exception; use Exception;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
@ -12,7 +13,7 @@ use Shaarli\History;
* Class UpdaterTest. * Class UpdaterTest.
* Runs unit tests against the updater class. * Runs unit tests against the updater class.
*/ */
class UpdaterTest extends \PHPUnit\Framework\TestCase class UpdaterTest extends TestCase
{ {
/** /**
* @var string Path to test datastore. * @var string Path to test datastore.
@ -194,7 +195,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase
public function testUpdateMethodRelativeHomeLinkDoNotRename(): void public function testUpdateMethodRelativeHomeLinkDoNotRename(): void
{ {
$this->updater->setBasePath('/subfolder');
$this->conf->set('general.header_link', '~/my-blog'); $this->conf->set('general.header_link', '~/my-blog');
$this->updater->updateMethodRelativeHomeLink(); $this->updater->updateMethodRelativeHomeLink();
@ -204,8 +204,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase
public function testUpdateMethodMigrateExistingNotesUrl(): void public function testUpdateMethodMigrateExistingNotesUrl(): void
{ {
$this->updater->setBasePath('/subfolder');
$this->updater->updateMethodMigrateExistingNotesUrl(); $this->updater->updateMethodMigrateExistingNotesUrl();
static::assertSame($this->refDB->getLinks()[0]->getUrl(), $this->bookmarkService->get(0)->getUrl()); 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()[7]->getUrl(), $this->bookmarkService->get(7)->getUrl());
static::assertSame($this->refDB->getLinks()[8]->getUrl(), $this->bookmarkService->get(8)->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($this->refDB->getLinks()[9]->getUrl(), $this->bookmarkService->get(9)->getUrl());
static::assertSame('/subfolder/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl()); static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl());
static::assertSame('/subfolder/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl()); static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl());
static::assertSame('/subfolder/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl()); static::assertSame('/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl());
static::assertSame('/subfolder/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl()); static::assertSame('/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl());
} }
} }

View file

@ -30,7 +30,7 @@ class ReferenceLinkDB
$this->addLink( $this->addLink(
11, 11,
'Pined older', 'Pined older',
'?PCRizQ', '/shaare/PCRizQ',
'This is an older pinned link', 'This is an older pinned link',
0, 0,
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100309_101010'), DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100309_101010'),
@ -43,7 +43,7 @@ class ReferenceLinkDB
$this->addLink( $this->addLink(
10, 10,
'Pined', 'Pined',
'?0gCTjQ', '/shaare/0gCTjQ',
'This is a pinned link', 'This is a pinned link',
0, 0,
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20121207_152312'), DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20121207_152312'),
@ -56,7 +56,7 @@ class ReferenceLinkDB
$this->addLink( $this->addLink(
41, 41,
'Link title: @website', 'Link title: @website',
'?WDWyig', '/shaare/WDWyig',
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag', 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
0, 0,
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'),
@ -68,7 +68,7 @@ class ReferenceLinkDB
$this->addLink( $this->addLink(
42, 42,
'Note: I have a big ID but an old date', 'Note: I have a big ID but an old date',
'?WDWyig', '/shaare/WDWyig',
'Used to test bookmarks reordering.', 'Used to test bookmarks reordering.',
0, 0,
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100310_101010'), DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20100310_101010'),