Fix basePath in unit tests reference DB
This commit is contained in:
parent
624123177f
commit
f7f08ceec1
9 changed files with 27 additions and 28 deletions
|
@ -93,6 +93,7 @@ protected function runUpdates(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$this->container->updater->setBasePath($this->container->basePath);
|
||||
$newUpdates = $this->container->updater->update();
|
||||
if (!empty($newUpdates)) {
|
||||
$this->container->updater->writeUpdates(
|
||||
|
|
|
@ -157,7 +157,7 @@ public function updateMethodMigrateExistingNotesUrl(): bool
|
|||
&& 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);
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public function testGetLinkId()
|
|||
$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(
|
||||
|
|
|
@ -109,7 +109,7 @@ public function testGetLinks()
|
|||
|
||||
// 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(
|
||||
|
|
|
@ -340,7 +340,7 @@ public function testSetMinimal()
|
|||
|
||||
$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 @@ public function testSetMinimal()
|
|||
|
||||
$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());
|
||||
|
|
|
@ -90,15 +90,15 @@ public function testRSSBuildData()
|
|||
$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 @@ public function testBuildDataPermalinks()
|
|||
$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 @@ public function testBuildDataServerSubdir()
|
|||
|
||||
// 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']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ public function testFilterAndFormatDoNotPrependNoteUrl()
|
|||
''
|
||||
);
|
||||
$this->assertEquals(
|
||||
'?WDWyig',
|
||||
'/shaare/WDWyig',
|
||||
$links[2]['url']
|
||||
);
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public function testFilterAndFormatPrependNoteUrl()
|
|||
$indexUrl
|
||||
);
|
||||
$this->assertEquals(
|
||||
$indexUrl . '?WDWyig',
|
||||
$indexUrl . 'shaare/WDWyig',
|
||||
$links[2]['url']
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 @@
|
|||
* 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 @@ public function testUpdateMethodRelativeHomeLinkRename(): void
|
|||
|
||||
public function testUpdateMethodRelativeHomeLinkDoNotRename(): void
|
||||
{
|
||||
$this->updater->setBasePath('/subfolder');
|
||||
$this->conf->set('general.header_link', '~/my-blog');
|
||||
|
||||
$this->updater->updateMethodRelativeHomeLink();
|
||||
|
@ -204,8 +204,6 @@ public function testUpdateMethodRelativeHomeLinkDoNotRename(): void
|
|||
|
||||
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 @@ public function testUpdateMethodMigrateExistingNotesUrl(): void
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public function __construct($isLegacy = false)
|
|||
$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 @@ public function __construct($isLegacy = false)
|
|||
$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 @@ public function __construct($isLegacy = false)
|
|||
$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 @@ public function __construct($isLegacy = false)
|
|||
$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'),
|
||||
|
|
Loading…
Reference in a new issue