namespacing: \Shaarli\Bookmark\LinkDB

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
VirtualTam 2018-12-03 01:10:39 +01:00
parent a0c4dbd91c
commit f24896b237
32 changed files with 115 additions and 77 deletions

View file

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
/** /**
* Class LinkFilter. * Class LinkFilter.
* *

View file

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
/** /**
* Get cURL callback function for CURLOPT_WRITEFUNCTION * Get cURL callback function for CURLOPT_WRITEFUNCTION
* *

View file

@ -1,6 +1,7 @@
<?php <?php
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History; use Shaarli\History;
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser; use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;

View file

@ -1,4 +1,6 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigJson; use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigPhp; use Shaarli\Config\ConfigPhp;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;

View file

@ -127,7 +127,7 @@ class ApiMiddleware
*/ */
protected function setLinkDb($conf) protected function setLinkDb($conf)
{ {
$linkDb = new \LinkDB( $linkDb = new \Shaarli\Bookmark\LinkDB(
$conf->get('resource.datastore'), $conf->get('resource.datastore'),
true, true,
$conf->get('privacy.hide_public_links'), $conf->get('privacy.hide_public_links'),

View file

@ -25,7 +25,7 @@ abstract class ApiController
protected $conf; protected $conf;
/** /**
* @var \LinkDB * @var \Shaarli\Bookmark\LinkDB
*/ */
protected $linkDb; protected $linkDb;

View file

@ -1,5 +1,13 @@
<?php <?php
namespace Shaarli\Bookmark;
use ArrayAccess;
use Countable;
use DateTime;
use Iterator;
use LinkFilter;
use LinkNotFoundException;
use Shaarli\Exceptions\IOException; use Shaarli\Exceptions\IOException;
use Shaarli\FileUtils; use Shaarli\FileUtils;
@ -99,10 +107,10 @@ class LinkDB implements Iterator, Countable, ArrayAccess
* *
* Checks if the datastore exists; else, attempts to create a dummy one. * Checks if the datastore exists; else, attempts to create a dummy one.
* *
* @param string $datastore datastore file path. * @param string $datastore datastore file path.
* @param boolean $isLoggedIn is the user logged in? * @param boolean $isLoggedIn is the user logged in?
* @param boolean $hidePublicLinks if true all links are private. * @param boolean $hidePublicLinks if true all links are private.
* @param string $redirector link redirector set in user settings. * @param string $redirector link redirector set in user settings.
* @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true). * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
*/ */
public function __construct( public function __construct(
@ -112,6 +120,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess
$redirector = '', $redirector = '',
$redirectorEncode = true $redirectorEncode = true
) { ) {
$this->datastore = $datastore; $this->datastore = $datastore;
$this->loggedIn = $isLoggedIn; $this->loggedIn = $isLoggedIn;
$this->hidePublicLinks = $hidePublicLinks; $this->hidePublicLinks = $hidePublicLinks;
@ -141,7 +150,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess
if (!isset($value['id']) || empty($value['url'])) { if (!isset($value['id']) || empty($value['url'])) {
die(t('Internal Error: A link should always have an id and URL.')); die(t('Internal Error: A link should always have an id and URL.'));
} }
if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) { if (($offset !== null && !is_int($offset)) || !is_int($value['id'])) {
die(t('You must specify an integer as a key.')); die(t('You must specify an integer as a key.'));
} }
if ($offset !== null && $offset !== $value['id']) { if ($offset !== null && $offset !== $value['id']) {
@ -251,31 +260,31 @@ class LinkDB implements Iterator, Countable, ArrayAccess
$this->links = array(); $this->links = array();
$link = array( $link = array(
'id' => 1, 'id' => 1,
'title'=> t('The personal, minimalist, super-fast, database free, bookmarking service'), 'title' => t('The personal, minimalist, super-fast, database free, bookmarking service'),
'url'=>'https://shaarli.readthedocs.io', 'url' => 'https://shaarli.readthedocs.io',
'description'=>t( 'description' => t(
'Welcome to Shaarli! This is your first public bookmark. ' 'Welcome to Shaarli! This is your first public bookmark. '
.'To edit or delete me, you must first login. . 'To edit or delete me, you must first login.
To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page. To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page.
You use the community supported version of the original Shaarli project, by Sebastien Sauvage.' You use the community supported version of the original Shaarli project, by Sebastien Sauvage.'
), ),
'private'=>0, 'private' => 0,
'created'=> new DateTime(), 'created' => new DateTime(),
'tags'=>'opensource software' 'tags' => 'opensource software'
); );
$link['shorturl'] = link_small_hash($link['created'], $link['id']); $link['shorturl'] = link_small_hash($link['created'], $link['id']);
$this->links[1] = $link; $this->links[1] = $link;
$link = array( $link = array(
'id' => 0, 'id' => 0,
'title'=> t('My secret stuff... - Pastebin.com'), 'title' => t('My secret stuff... - Pastebin.com'),
'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', 'url' => 'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=',
'description'=> t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'), 'description' => t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'),
'private'=>1, 'private' => 1,
'created'=> new DateTime('1 minute ago'), 'created' => new DateTime('1 minute ago'),
'tags'=>'secretstuff', 'tags' => 'secretstuff',
); );
$link['shorturl'] = link_small_hash($link['created'], $link['id']); $link['shorturl'] = link_small_hash($link['created'], $link['id']);
$this->links[0] = $link; $this->links[0] = $link;
@ -301,7 +310,7 @@ You use the community supported version of the original Shaarli project, by Seba
$toremove = array(); $toremove = array();
foreach ($this->links as $key => &$link) { foreach ($this->links as $key => &$link) {
if (! $this->loggedIn && $link['private'] != 0) { if (!$this->loggedIn && $link['private'] != 0) {
// Transition for not upgraded databases. // Transition for not upgraded databases.
unset($this->links[$key]); unset($this->links[$key]);
continue; continue;
@ -311,7 +320,7 @@ You use the community supported version of the original Shaarli project, by Seba
sanitizeLink($link); sanitizeLink($link);
// Remove private tags if the user is not logged in. // Remove private tags if the user is not logged in.
if (! $this->loggedIn) { if (!$this->loggedIn) {
$link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']); $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']);
} }
@ -328,10 +337,10 @@ You use the community supported version of the original Shaarli project, by Seba
} }
// To be able to load links before running the update, and prepare the update // To be able to load links before running the update, and prepare the update
if (! isset($link['created'])) { if (!isset($link['created'])) {
$link['id'] = $link['linkdate']; $link['id'] = $link['linkdate'];
$link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']); $link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']);
if (! empty($link['updated'])) { if (!empty($link['updated'])) {
$link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']); $link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']);
} }
$link['shorturl'] = smallHash($link['linkdate']); $link['shorturl'] = smallHash($link['linkdate']);
@ -417,12 +426,12 @@ You use the community supported version of the original Shaarli project, by Seba
/** /**
* Filter links according to search parameters. * Filter links according to search parameters.
* *
* @param array $filterRequest Search request content. Supported keys: * @param array $filterRequest Search request content. Supported keys:
* - searchtags: list of tags * - searchtags: list of tags
* - searchterm: term search * - searchterm: term search
* @param bool $casesensitive Optional: Perform case sensitive filter * @param bool $casesensitive Optional: Perform case sensitive filter
* @param string $visibility return only all/private/public links * @param string $visibility return only all/private/public links
* @param string $untaggedonly return only untagged links * @param string $untaggedonly return only untagged links
* *
* @return array filtered links, all links if no suitable filter was provided. * @return array filtered links, all links if no suitable filter was provided.
*/ */
@ -432,6 +441,7 @@ You use the community supported version of the original Shaarli project, by Seba
$visibility = 'all', $visibility = 'all',
$untaggedonly = false $untaggedonly = false
) { ) {
// Filter link database according to parameters. // Filter link database according to parameters.
$searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : '';
$searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : '';
@ -448,7 +458,7 @@ You use the community supported version of the original Shaarli project, by Seba
* Returns the list tags appearing in the links with the given tags * Returns the list tags appearing in the links with the given tags
* *
* @param array $filteringTags tags selecting the links to consider * @param array $filteringTags tags selecting the links to consider
* @param string $visibility process only all/private/public links * @param string $visibility process only all/private/public links
* *
* @return array tag => linksCount * @return array tag => linksCount
*/ */
@ -490,7 +500,7 @@ You use the community supported version of the original Shaarli project, by Seba
* Rename or delete a tag across all links. * Rename or delete a tag across all links.
* *
* @param string $from Tag to rename * @param string $from Tag to rename
* @param string $to New tag. If none is provided, the from tag will be deleted * @param string $to New tag. If none is provided, the from tag will be deleted
* *
* @return array|bool List of altered links or false on error * @return array|bool List of altered links or false on error
*/ */

View file

@ -1,6 +1,7 @@
<?php <?php
namespace Shaarli\Feed; namespace Shaarli\Feed;
/** /**
* Simple cache system, mainly for the RSS/ATOM feeds * Simple cache system, mainly for the RSS/ATOM feeds
*/ */

View file

@ -2,7 +2,7 @@
namespace Shaarli\Feed; namespace Shaarli\Feed;
use DateTime; use DateTime;
use LinkDB; use Shaarli\Bookmark\LinkDB;
/** /**
* FeedBuilder class. * FeedBuilder class.
@ -32,7 +32,7 @@ class FeedBuilder
public static $DEFAULT_NB_LINKS = 50; public static $DEFAULT_NB_LINKS = 50;
/** /**
* @var LinkDB instance. * @var \Shaarli\Bookmark\LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -79,11 +79,12 @@ class FeedBuilder
/** /**
* Feed constructor. * Feed constructor.
* *
* @param LinkDB $linkDB LinkDB instance. * @param \Shaarli\Bookmark\LinkDB $linkDB LinkDB instance.
* @param string $feedType Type of feed. * @param string $feedType Type of feed.
* @param array $serverInfo $_SERVER. * @param array $serverInfo $_SERVER.
* @param array $userInput $_GET. * @param array $userInput $_GET.
* @param boolean $isLoggedIn True if the user is currently logged in, false otherwise. * @param boolean $isLoggedIn True if the user is currently logged in,
* false otherwise.
*/ */
public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn) public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn)
{ {

View file

@ -4,7 +4,7 @@ namespace Shaarli\Render;
use ApplicationUtils; use ApplicationUtils;
use Exception; use Exception;
use LinkDB; use Shaarli\Bookmark\LinkDB;
use RainTPL; use RainTPL;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Thumbnailer; use Shaarli\Thumbnailer;

View file

@ -35,6 +35,7 @@
"Shaarli\\Api\\": "application/api/", "Shaarli\\Api\\": "application/api/",
"Shaarli\\Api\\Controllers\\": "application/api/controllers", "Shaarli\\Api\\Controllers\\": "application/api/controllers",
"Shaarli\\Api\\Exceptions\\": "application/api/exceptions", "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
"Shaarli\\Bookmark\\": "application/bookmark",
"Shaarli\\Config\\": "application/config/", "Shaarli\\Config\\": "application/config/",
"Shaarli\\Config\\Exception\\": "application/config/exception", "Shaarli\\Config\\Exception\\": "application/config/exception",
"Shaarli\\Exceptions\\": "application/exceptions", "Shaarli\\Exceptions\\": "application/exceptions",

View file

@ -63,7 +63,6 @@ require_once 'application/http/HttpUtils.php';
require_once 'application/http/UrlUtils.php'; require_once 'application/http/UrlUtils.php';
require_once 'application/FileUtils.php'; require_once 'application/FileUtils.php';
require_once 'application/History.php'; require_once 'application/History.php';
require_once 'application/LinkDB.php';
require_once 'application/LinkFilter.php'; require_once 'application/LinkFilter.php';
require_once 'application/LinkUtils.php'; require_once 'application/LinkUtils.php';
require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/NetscapeBookmarkUtils.php';
@ -72,6 +71,8 @@ require_once 'application/Utils.php';
require_once 'application/PluginManager.php'; require_once 'application/PluginManager.php';
require_once 'application/Router.php'; require_once 'application/Router.php';
require_once 'application/Updater.php'; require_once 'application/Updater.php';
use \Shaarli\Bookmark\LinkDB;
use \Shaarli\Config\ConfigManager; use \Shaarli\Config\ConfigManager;
use \Shaarli\Feed\CachedPage; use \Shaarli\Feed\CachedPage;
use \Shaarli\Feed\FeedBuilder; use \Shaarli\Feed\FeedBuilder;

View file

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
require_once 'application/LinkFilter.php'; require_once 'application/LinkFilter.php';
/** /**

View file

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/NetscapeBookmarkUtils.php';
/** /**

View file

@ -2,6 +2,7 @@
require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/NetscapeBookmarkUtils.php';
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History; use Shaarli\History;

View file

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
require_once 'application/Updater.php'; require_once 'application/Updater.php';
/** /**

View file

@ -1,4 +1,6 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigJson; use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Config\ConfigPhp; use Shaarli\Config\ConfigPhp;

View file

@ -53,7 +53,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = null; $this->container['history'] = null;
$this->controller = new Info($this->container); $this->controller = new Info($this->container);

View file

@ -32,7 +32,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \LinkDB instance. * @var \Shaarli\Bookmark\LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -59,7 +59,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
$this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf = new ConfigManager('tests/utils/config/configJson');
$this->refDB = new \ReferenceLinkDB(); $this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore); $this->refDB->write(self::$testDatastore);
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \Shaarli\History(self::$testHistory); $this->history = new \Shaarli\History(self::$testHistory);
@ -96,7 +96,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(204, $response->getStatusCode()); $this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody()); $this->assertEmpty((string) $response->getBody());
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->assertFalse(isset($this->linkDB[$id])); $this->assertFalse(isset($this->linkDB[$id]));
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];

View file

@ -61,7 +61,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = null; $this->container['history'] = null;
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -108,7 +108,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('sTuff', $data['tags'][0]); $this->assertEquals('sTuff', $data['tags'][0]);
$this->assertEquals(false, $data['private']); $this->assertEquals(false, $data['private']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
$data['created'] $data['created']
); );
$this->assertEmpty($data['updated']); $this->assertEmpty($data['updated']);

View file

@ -60,7 +60,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = null; $this->container['history'] = null;
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -114,7 +114,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('sTuff', $first['tags'][0]); $this->assertEquals('sTuff', $first['tags'][0]);
$this->assertEquals(false, $first['private']); $this->assertEquals(false, $first['private']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
$first['created'] $first['created']
); );
$this->assertEmpty($first['updated']); $this->assertEmpty($first['updated']);
@ -125,7 +125,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
// Update date // Update date
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
$link['updated'] $link['updated']
); );
} }

View file

@ -74,7 +74,7 @@ class PostLinkTest extends TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = new \Shaarli\History(self::$testHistory); $this->container['history'] = new \Shaarli\History(self::$testHistory);
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -210,11 +210,11 @@ class PostLinkTest extends TestCase
$this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
$this->assertEquals(false, $data['private']); $this->assertEquals(false, $data['private']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
\DateTime::createFromFormat(\DateTime::ATOM, $data['created']) \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
); );
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
\DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
); );
} }

View file

@ -66,7 +66,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = new \Shaarli\History(self::$testHistory); $this->container['history'] = new \Shaarli\History(self::$testHistory);
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -198,11 +198,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
$this->assertEquals(false, $data['private']); $this->assertEquals(false, $data['private']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
\DateTime::createFromFormat(\DateTime::ATOM, $data['created']) \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
); );
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
\DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
); );
} }

View file

@ -32,7 +32,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \LinkDB instance. * @var \Shaarli\Bookmark\LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -59,7 +59,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
$this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf = new ConfigManager('tests/utils/config/configJson');
$this->refDB = new \ReferenceLinkDB(); $this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore); $this->refDB->write(self::$testDatastore);
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \Shaarli\History(self::$testHistory); $this->history = new \Shaarli\History(self::$testHistory);
@ -97,7 +97,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(204, $response->getStatusCode()); $this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody()); $this->assertEmpty((string) $response->getBody());
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$tags = $this->linkDB->linksCountPerTag(); $tags = $this->linkDB->linksCountPerTag();
$this->assertFalse(isset($tags[$tagName])); $this->assertFalse(isset($tags[$tagName]));
@ -131,7 +131,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(204, $response->getStatusCode()); $this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody()); $this->assertEmpty((string) $response->getBody());
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$tags = $this->linkDB->linksCountPerTag(); $tags = $this->linkDB->linksCountPerTag();
$this->assertFalse(isset($tags[$tagName])); $this->assertFalse(isset($tags[$tagName]));
$this->assertTrue($tags[strtolower($tagName)] > 0); $this->assertTrue($tags[strtolower($tagName)] > 0);

View file

@ -59,7 +59,7 @@ class GetTagNameTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = new \LinkDB(self::$testDatastore, true, false); $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['history'] = null; $this->container['history'] = null;
$this->controller = new Tags($this->container); $this->controller = new Tags($this->container);

View file

@ -38,7 +38,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
protected $container; protected $container;
/** /**
* @var \LinkDB instance. * @var \Shaarli\Bookmark\LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -63,7 +63,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['db'] = $this->linkDB; $this->container['db'] = $this->linkDB;
$this->container['history'] = null; $this->container['history'] = null;

View file

@ -43,7 +43,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
protected $container; protected $container;
/** /**
* @var \LinkDB instance. * @var \Shaarli\Bookmark\LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -72,7 +72,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
$this->container['db'] = $this->linkDB; $this->container['db'] = $this->linkDB;
$this->container['history'] = $this->history; $this->container['history'] = $this->history;

View file

@ -3,9 +3,15 @@
* Link datastore tests * Link datastore tests
*/ */
namespace Shaarli\Bookmark;
use DateTime;
use LinkNotFoundException;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
require_once 'application/feed/Cache.php'; require_once 'application/feed/Cache.php';
require_once 'application/FileUtils.php';
require_once 'application/LinkDB.php';
require_once 'application/Utils.php'; require_once 'application/Utils.php';
require_once 'tests/utils/ReferenceLinkDB.php'; require_once 'tests/utils/ReferenceLinkDB.php';
@ -13,7 +19,7 @@ require_once 'tests/utils/ReferenceLinkDB.php';
/** /**
* Unitary tests for LinkDB * Unitary tests for LinkDB
*/ */
class LinkDBTest extends PHPUnit_Framework_TestCase class LinkDBTest extends \PHPUnit\Framework\TestCase
{ {
// datastore to test write operations // datastore to test write operations
protected static $testDatastore = 'sandbox/datastore.php'; protected static $testDatastore = 'sandbox/datastore.php';
@ -73,7 +79,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
*/ */
protected static function getMethod($name) protected static function getMethod($name)
{ {
$class = new ReflectionClass('LinkDB'); $class = new ReflectionClass('Shaarli\Bookmark\LinkDB');
$method = $class->getMethod($name); $method = $class->getMethod($name);
$method->setAccessible(true); $method->setAccessible(true);
return $method; return $method;
@ -187,12 +193,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
$link = array( $link = array(
'id' => 42, 'id' => 42,
'title'=>'an additional link', 'title' => 'an additional link',
'url'=>'http://dum.my', 'url' => 'http://dum.my',
'description'=>'One more', 'description' => 'One more',
'private'=>0, 'private' => 0,
'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'),
'tags'=>'unit test' 'tags' => 'unit test'
); );
$testDB[$link['id']] = $link; $testDB[$link['id']] = $link;
$testDB->save('tests'); $testDB->save('tests');

View file

@ -3,11 +3,9 @@
namespace Shaarli\Feed; namespace Shaarli\Feed;
use DateTime; use DateTime;
use LinkDB; use Shaarli\Bookmark\LinkDB;
use ReferenceLinkDB; use ReferenceLinkDB;
require_once 'application/LinkDB.php';
/** /**
* FeedBuilderTest class. * FeedBuilderTest class.
* *

View file

@ -5,7 +5,6 @@
namespace Shaarli\Http; namespace Shaarli\Http;
/** /**
* Unitary tests for URL utilities * Unitary tests for URL utilities
*/ */

View file

@ -1,4 +1,6 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
require_once 'plugins/isso/isso.php'; require_once 'plugins/isso/isso.php';

View file

@ -1,4 +1,7 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
/** /**
* Populates a reference datastore to test LinkDB * Populates a reference datastore to test LinkDB
*/ */