<?php
-
namespace Shaarli\Api\Controllers;
-
use Shaarli\Api\Exceptions\ApiBadParametersException;
+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;
use Slim\Http\Response;
-class PutTagTest extends \PHPUnit_Framework_TestCase
+class PutTagTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string datastore to test write operations
protected $refDB = null;
/**
- * @var \History instance.
+ * @var HistoryController instance.
*/
protected $history;
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.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->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);
$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]);
$historyEntry = $this->history->getHistory()[0];
- $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+ $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
);
$historyEntry = $this->history->getHistory()[1];
- $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+ $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
);
$tagName = 'gnu';
$newName = 'w3c';
- $tags = $this->linkDB->linksCountPerTag();
+ $tags = $this->bookmarkService->bookmarksCountPerTag();
$this->assertEquals(1, $tags[$newName]);
$this->assertEquals(2, $tags[$tagName]);
$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]);
}
$tagName = 'gnu';
$newName = '';
- $tags = $this->linkDB->linksCountPerTag();
+ $tags = $this->bookmarkService->bookmarksCountPerTag();
$this->assertEquals(2, $tags[$tagName]);
$env = Environment::mock([
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;
}