<?php
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;
*
* @package Shaarli\Api\Controllers
*/
-class GetTagsTest extends \PHPUnit_Framework_TestCase
+class GetTagsTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string datastore to test write operations
protected $container;
/**
- * @var \LinkDB instance.
+ * @var BookmarkFileService instance.
*/
- protected $linkDB;
+ protected $bookmarkService;
/**
* @var Tags controller instance.
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');
+ $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);
}
/**
- * 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',
]);
$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']);
}
*/
public function testGetTagsLimitAll()
{
- $tags = $this->linkDB->linksCountPerTag();
+ $tags = $this->bookmarkService->bookmarksCountPerTag();
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => 'limit=all'
*/
public function testGetTagsVisibilityPrivate()
{
- $tags = $this->linkDB->linksCountPerTag([], 'private');
+ $tags = $this->bookmarkService->bookmarksCountPerTag([], 'private');
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => 'visibility=private'
$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']);
}
*/
public function testGetTagsVisibilityPublic()
{
- $tags = $this->linkDB->linksCountPerTag([], 'public');
+ $tags = $this->bookmarkService->bookmarksCountPerTag([], 'public');
$env = Environment::mock(
[
'REQUEST_METHOD' => 'GET',