From e26e2060f5470ce8bf4c5973284bae07b8af170a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 17 Jan 2020 21:34:12 +0100 Subject: Add and update unit test for the new system (Bookmark + Service) See #1307 --- tests/api/controllers/history/HistoryTest.php | 4 ++-- tests/api/controllers/info/InfoTest.php | 20 +++++++++++------ tests/api/controllers/links/DeleteLinkTest.php | 22 ++++++++++--------- tests/api/controllers/links/GetLinkIdTest.php | 11 +++++++--- tests/api/controllers/links/GetLinksTest.php | 15 ++++++++----- tests/api/controllers/links/PostLinkTest.php | 30 ++++++++++++++++---------- tests/api/controllers/links/PutLinkTest.php | 24 ++++++++++++++------- tests/api/controllers/tags/DeleteTagTest.php | 29 ++++++++++++++----------- tests/api/controllers/tags/GetTagNameTest.php | 8 +++++-- tests/api/controllers/tags/GetTagsTest.php | 23 ++++++++++++-------- tests/api/controllers/tags/PutTagTest.php | 25 ++++++++++----------- 11 files changed, 129 insertions(+), 82 deletions(-) (limited to 'tests/api/controllers') diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php index e287f239..f4d3b646 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php @@ -39,11 +39,11 @@ class HistoryTest extends \PHPUnit\Framework\TestCase protected $controller; /** - * Before every test, instantiate a new Api with its config, plugins and links. + * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { - $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->refHistory = new \ReferenceHistory(); $this->refHistory->write(self::$testHistory); $this->container = new Container(); diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index e70d371b..b5c938e1 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php @@ -1,7 +1,10 @@ conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $history = new History('sandbox/history.php'); + $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); + $this->container['db'] = new BookmarkFileService($this->conf, $history, true); $this->container['history'] = null; $this->controller = new Info($this->container); @@ -84,11 +90,11 @@ class InfoTest extends \PHPUnit\Framework\TestCase $this->assertEquals(2, $data['private_counter']); $this->assertEquals('Shaarli', $data['settings']['title']); $this->assertEquals('?', $data['settings']['header_link']); - $this->assertEquals('UTC', $data['settings']['timezone']); + $this->assertEquals('Europe/Paris', $data['settings']['timezone']); $this->assertEquals(ConfigManager::$DEFAULT_PLUGINS, $data['settings']['enabled_plugins']); - $this->assertEquals(false, $data['settings']['default_private_links']); + $this->assertEquals(true, $data['settings']['default_private_links']); - $title = 'My links'; + $title = 'My bookmarks'; $headerLink = 'http://shaarli.tld'; $timezone = 'Europe/Paris'; $enabledPlugins = array('foo', 'bar'); diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 90193e28..6c2b3698 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php @@ -3,7 +3,7 @@ namespace Shaarli\Api\Controllers; -use Shaarli\Bookmark\LinkDB; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Slim\Container; @@ -34,9 +34,9 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase protected $refDB = null; /** - * @var LinkDB instance. + * @var BookmarkFileService instance. */ - protected $linkDB; + protected $bookmarkService; /** * @var HistoryController instance. @@ -54,20 +54,22 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase protected $controller; /** - * Before each test, instantiate a new Api with its config, plugins and links. + * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $this->linkDB = new LinkDB(self::$testDatastore, true, false); $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = $this->linkDB; + $this->container['db'] = $this->bookmarkService; $this->container['history'] = $this->history; $this->controller = new Links($this->container); @@ -88,7 +90,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase public function testDeleteLinkValid() { $id = '41'; - $this->assertTrue(isset($this->linkDB[$id])); + $this->assertTrue($this->bookmarkService->exists($id)); $env = Environment::mock([ 'REQUEST_METHOD' => 'DELETE', ]); @@ -98,8 +100,8 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals(204, $response->getStatusCode()); $this->assertEmpty((string) $response->getBody()); - $this->linkDB = new LinkDB(self::$testDatastore, true, false); - $this->assertFalse(isset($this->linkDB[$id])); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->assertFalse($this->bookmarkService->exists($id)); $historyEntry = $this->history->getHistory()[0]; $this->assertEquals(History::DELETED, $historyEntry['event']); @@ -117,7 +119,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase public function testDeleteLink404() { $id = -1; - $this->assertFalse(isset($this->linkDB[$id])); + $this->assertFalse($this->bookmarkService->exists($id)); $env = Environment::mock([ 'REQUEST_METHOD' => 'DELETE', ]); diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index cb9b7f6a..c26411ac 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -2,7 +2,10 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\Bookmark; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -50,17 +53,19 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase const NB_FIELDS_LINK = 9; /** - * Before each test, instantiate a new Api with its config, plugins and links. + * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $history = new History('sandbox/history.php'); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); + $this->container['db'] = new BookmarkFileService($this->conf, $history, true); $this->container['history'] = null; $this->controller = new Links($this->container); @@ -107,7 +112,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase $this->assertEquals('sTuff', $data['tags'][0]); $this->assertEquals(false, $data['private']); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), $data['created'] ); $this->assertEmpty($data['updated']); diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 711a3152..4e2d55ac 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -1,8 +1,11 @@ conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $history = new History('sandbox/history.php'); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new LinkDB(self::$testDatastore, true, false); + $this->container['db'] = new BookmarkFileService($this->conf, $history, true); $this->container['history'] = null; $this->controller = new Links($this->container); @@ -75,7 +80,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase } /** - * Test basic getLinks service: returns all links. + * Test basic getLinks service: returns all bookmarks. */ public function testGetLinks() { @@ -114,7 +119,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase $this->assertEquals('sTuff', $first['tags'][0]); $this->assertEquals(false, $first['private']); $this->assertEquals( - \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), $first['created'] ); $this->assertEmpty($first['updated']); @@ -125,7 +130,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase // Update date $this->assertEquals( - \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), $link['updated'] ); } diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index d683a984..b2dd09eb 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -3,6 +3,8 @@ namespace Shaarli\Api\Controllers; use PHPUnit\Framework\TestCase; +use Shaarli\Bookmark\Bookmark; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Slim\Container; @@ -40,6 +42,11 @@ class PostLinkTest extends TestCase */ protected $refDB = null; + /** + * @var BookmarkFileService instance. + */ + protected $bookmarkService; + /** * @var HistoryController instance. */ @@ -61,29 +68,30 @@ class PostLinkTest extends TestCase const NB_FIELDS_LINK = 9; /** - * Before every test, instantiate a new Api with its config, plugins and links. + * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { - $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); - $this->container['history'] = new History(self::$testHistory); + $this->container['db'] = $this->bookmarkService; + $this->container['history'] = $this->history; $this->controller = new Links($this->container); $mock = $this->createMock(Router::class); $mock->expects($this->any()) ->method('relativePathFor') - ->willReturn('api/v1/links/1'); + ->willReturn('api/v1/bookmarks/1'); // affect @property-read... seems to work $this->controller->getCi()->router = $mock; @@ -118,7 +126,7 @@ class PostLinkTest extends TestCase $response = $this->controller->postLink($request, new Response()); $this->assertEquals(201, $response->getStatusCode()); - $this->assertEquals('api/v1/links/1', $response->getHeader('Location')[0]); + $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(43, $data['id']); @@ -127,7 +135,7 @@ class PostLinkTest extends TestCase $this->assertEquals('?' . $data['shorturl'], $data['title']); $this->assertEquals('', $data['description']); $this->assertEquals([], $data['tags']); - $this->assertEquals(false, $data['private']); + $this->assertEquals(true, $data['private']); $this->assertTrue( new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) ); @@ -163,7 +171,7 @@ class PostLinkTest extends TestCase $response = $this->controller->postLink($request, new Response()); $this->assertEquals(201, $response->getStatusCode()); - $this->assertEquals('api/v1/links/1', $response->getHeader('Location')[0]); + $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(43, $data['id']); @@ -211,11 +219,11 @@ class PostLinkTest extends TestCase $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(false, $data['private']); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130614_184135'), \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) ); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130615_184230'), \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) ); } diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index cd815b66..cb63742e 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -3,6 +3,8 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\Bookmark; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Config\ConfigManager; use Shaarli\History; use Slim\Container; @@ -32,6 +34,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase */ protected $refDB = null; + /** + * @var BookmarkFileService instance. + */ + protected $bookmarkService; + /** * @var HistoryController instance. */ @@ -53,22 +60,23 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase const NB_FIELDS_LINK = 9; /** - * Before every test, instantiate a new Api with its config, plugins and links. + * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { - $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); - $this->container['history'] = new History(self::$testHistory); + $this->container['db'] = $this->bookmarkService; + $this->container['history'] = $this->history; $this->controller = new Links($this->container); @@ -110,7 +118,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals('?WDWyig', $data['title']); $this->assertEquals('', $data['description']); $this->assertEquals([], $data['tags']); - $this->assertEquals(false, $data['private']); + $this->assertEquals(true, $data['private']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20150310_114651'), \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) @@ -199,11 +207,11 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(false, $data['private']); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130614_184135'), \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) ); $this->assertEquals( - \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20130615_184230'), \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) ); } diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index 84e1d56e..c6748872 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php @@ -3,6 +3,7 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; @@ -34,9 +35,9 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase protected $refDB = null; /** - * @var LinkDB instance. + * @var BookmarkFileService instance. */ - protected $linkDB; + protected $bookmarkService; /** * @var HistoryController instance. @@ -54,20 +55,22 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase protected $controller; /** - * Before each test, instantiate a new Api with its config, plugins and links. + * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $this->linkDB = new LinkDB(self::$testDatastore, true, false); $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = $this->linkDB; + $this->container['db'] = $this->bookmarkService; $this->container['history'] = $this->history; $this->controller = new Tags($this->container); @@ -88,7 +91,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase public function testDeleteTagValid() { $tagName = 'gnu'; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertTrue($tags[$tagName] > 0); $env = Environment::mock([ 'REQUEST_METHOD' => 'DELETE', @@ -99,11 +102,11 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase $this->assertEquals(204, $response->getStatusCode()); $this->assertEmpty((string) $response->getBody()); - $this->linkDB = new LinkDB(self::$testDatastore, true, false); - $tags = $this->linkDB->linksCountPerTag(); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertFalse(isset($tags[$tagName])); - // 2 links affected + // 2 bookmarks affected $historyEntry = $this->history->getHistory()[0]; $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( @@ -122,7 +125,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase public function testDeleteTagCaseSensitivity() { $tagName = 'sTuff'; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertTrue($tags[$tagName] > 0); $env = Environment::mock([ 'REQUEST_METHOD' => 'DELETE', @@ -133,8 +136,8 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase $this->assertEquals(204, $response->getStatusCode()); $this->assertEmpty((string) $response->getBody()); - $this->linkDB = new LinkDB(self::$testDatastore, true, false); - $tags = $this->linkDB->linksCountPerTag(); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertFalse(isset($tags[$tagName])); $this->assertTrue($tags[strtolower($tagName)] > 0); @@ -154,7 +157,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase public function testDeleteLink404() { $tagName = 'nopenope'; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertFalse(isset($tags[$tagName])); $env = Environment::mock([ 'REQUEST_METHOD' => 'DELETE', diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index a2525c17..b9a81f9b 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -2,8 +2,10 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -49,17 +51,19 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase const NB_FIELDS_TAG = 2; /** - * Before each test, instantiate a new Api with its config, plugins and links. + * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $history = new History('sandbox/history.php'); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new LinkDB(self::$testDatastore, true, false); + $this->container['db'] = new BookmarkFileService($this->conf, $history, true); $this->container['history'] = null; $this->controller = new Tags($this->container); diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index 98628c98..53a3326d 100644 --- a/tests/api/controllers/tags/GetTagsTest.php +++ b/tests/api/controllers/tags/GetTagsTest.php @@ -1,8 +1,10 @@ conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $history = new History('sandbox/history.php'); + + $this->bookmarkService = new BookmarkFileService($this->conf, $history, true); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->linkDB = new LinkDB(self::$testDatastore, true, false); - $this->container['db'] = $this->linkDB; + $this->container['db'] = $this->bookmarkService; $this->container['history'] = null; $this->controller = new Tags($this->container); @@ -83,7 +88,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase */ public function testGetTagsAll() { - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); @@ -136,7 +141,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase */ public function testGetTagsLimitAll() { - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => 'limit=all' @@ -170,7 +175,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase */ public function testGetTagsVisibilityPrivate() { - $tags = $this->linkDB->linksCountPerTag([], 'private'); + $tags = $this->bookmarkService->bookmarksCountPerTag([], 'private'); $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => 'visibility=private' @@ -190,7 +195,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase */ public function testGetTagsVisibilityPublic() { - $tags = $this->linkDB->linksCountPerTag([], 'public'); + $tags = $this->bookmarkService->bookmarksCountPerTag([], 'public'); $env = Environment::mock( [ 'REQUEST_METHOD' => 'GET', diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 86106fc7..2a3cc15a 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -3,6 +3,7 @@ namespace Shaarli\Api\Controllers; use Shaarli\Api\Exceptions\ApiBadParametersException; +use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; @@ -44,9 +45,9 @@ class PutTagTest extends \PHPUnit\Framework\TestCase protected $container; /** - * @var LinkDB instance. + * @var BookmarkFileService instance. */ - protected $linkDB; + protected $bookmarkService; /** * @var Tags controller instance. @@ -59,22 +60,22 @@ class PutTagTest extends \PHPUnit\Framework\TestCase const NB_FIELDS_TAG = 2; /** - * Before every test, instantiate a new Api with its config, plugins and links. + * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ public function setUp() { - $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->linkDB = new LinkDB(self::$testDatastore, true, false); - $this->container['db'] = $this->linkDB; + $this->container['db'] = $this->bookmarkService; $this->container['history'] = $this->history; $this->controller = new Tags($this->container); @@ -109,7 +110,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase $this->assertEquals($newName, $data['name']); $this->assertEquals(2, $data['occurrences']); - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertNotTrue(isset($tags[$tagName])); $this->assertEquals(2, $tags[$newName]); @@ -133,7 +134,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase $tagName = 'gnu'; $newName = 'w3c'; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(1, $tags[$newName]); $this->assertEquals(2, $tags[$tagName]); @@ -151,7 +152,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase $this->assertEquals($newName, $data['name']); $this->assertEquals(3, $data['occurrences']); - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertNotTrue(isset($tags[$tagName])); $this->assertEquals(3, $tags[$newName]); } @@ -167,7 +168,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase $tagName = 'gnu'; $newName = ''; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(2, $tags[$tagName]); $env = Environment::mock([ @@ -185,7 +186,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase try { $this->controller->putTag($request, new Response(), ['tagName' => $tagName]); } catch (ApiBadParametersException $e) { - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(2, $tags[$tagName]); throw $e; } -- cgit v1.2.3