X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fapi%2Fcontrollers%2Ftags%2FGetTagsTest.php;h=3459fdfae361deb737f9e40786e6102a367d223b;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=cf066bc348d1d46f513fdb1d5caa34af17c5b541;hpb=d3f42ca487287447efb81061609644108044a038;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index cf066bc3..3459fdfa 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); @@ -73,17 +78,17 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } /** - * Test basic getLinks service: returns all tags. + * Test basic getTags service: returns all tags. */ public function testGetTagsAll() { - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); @@ -102,12 +107,12 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase $this->assertEquals('cartoon', $data[1]['name']); $this->assertEquals(3, $data[1]['occurrences']); // Case insensitive - $this->assertEquals(self::NB_FIELDS_TAG, count($data[2])); - $this->assertEquals('sTuff', $data[2]['name']); - $this->assertEquals(2, $data[2]['occurrences']); + $this->assertEquals(self::NB_FIELDS_TAG, count($data[5])); + $this->assertEquals('sTuff', $data[5]['name']); + $this->assertEquals(2, $data[5]['occurrences']); // End $this->assertEquals(self::NB_FIELDS_TAG, count($data[count($data) - 1])); - $this->assertEquals('ut', $data[count($data) - 1]['name']); + $this->assertEquals('w3c', $data[count($data) - 1]['name']); $this->assertEquals(1, $data[count($data) - 1]['occurrences']); } @@ -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' @@ -181,7 +186,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase $data = json_decode((string) $response->getBody(), true); $this->assertEquals(count($tags), count($data)); $this->assertEquals(self::NB_FIELDS_TAG, count($data[0])); - $this->assertEquals('css', $data[0]['name']); + $this->assertEquals('Mercurial', $data[0]['name']); $this->assertEquals(1, $data[0]['occurrences']); } @@ -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',