Merge pull request #1248 from virtualtam/refactor/namespacing

Ensure all PHP classes are properly namespaced
This commit is contained in:
Aurélien Tamisier 2019-01-18 21:26:03 +01:00 committed by GitHub
commit ff3b5dc554
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
122 changed files with 1081 additions and 857 deletions

View file

@ -1,4 +1,9 @@
<?php <?php
namespace Shaarli;
use Exception;
use Shaarli\Config\ConfigManager;
/** /**
* Shaarli (application) utilities * Shaarli (application) utilities
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
require_once 'exceptions/IOException.php'; namespace Shaarli;
use Shaarli\Exceptions\IOException;
/** /**
* Class FileUtils * Class FileUtils

View file

@ -1,4 +1,8 @@
<?php <?php
namespace Shaarli;
use DateTime;
use Exception;
/** /**
* Class History * Class History
@ -66,7 +70,7 @@ class History
* History constructor. * History constructor.
* *
* @param string $historyFilePath History file path. * @param string $historyFilePath History file path.
* @param int $retentionTime History content rentention time in seconds. * @param int $retentionTime History content retention time in seconds.
* *
* @throws Exception if something goes wrong. * @throws Exception if something goes wrong.
*/ */

View file

@ -3,7 +3,6 @@
namespace Shaarli; namespace Shaarli;
use Gettext\GettextTranslator; use Gettext\GettextTranslator;
use Gettext\Merge;
use Gettext\Translations; use Gettext\Translations;
use Gettext\Translator; use Gettext\Translator;
use Gettext\TranslatorInterface; use Gettext\TranslatorInterface;

View file

@ -1,4 +1,5 @@
<?php <?php
namespace Shaarli;
/** /**
* Class Router * Class Router

View file

@ -3,9 +3,9 @@
namespace Shaarli; namespace Shaarli;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use WebThumbnailer\Application\ConfigManager as WTConfigManager;
use WebThumbnailer\Exception\WebThumbnailerException; use WebThumbnailer\Exception\WebThumbnailerException;
use WebThumbnailer\WebThumbnailer; use WebThumbnailer\WebThumbnailer;
use WebThumbnailer\Application\ConfigManager as WTConfigManager;
/** /**
* Class Thumbnailer * Class Thumbnailer

View file

@ -1,9 +1,8 @@
<?php <?php
namespace Shaarli\Api; namespace Shaarli\Api;
use Shaarli\Api\Exceptions\ApiException;
use Shaarli\Api\Exceptions\ApiAuthorizationException; use Shaarli\Api\Exceptions\ApiAuthorizationException;
use Shaarli\Api\Exceptions\ApiException;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Request; use Slim\Http\Request;
@ -127,7 +126,7 @@ protected function checkToken($request)
*/ */
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

@ -1,8 +1,8 @@
<?php <?php
namespace Shaarli\Api; namespace Shaarli\Api;
use Shaarli\Base64Url;
use Shaarli\Api\Exceptions\ApiAuthorizationException; use Shaarli\Api\Exceptions\ApiAuthorizationException;
use Shaarli\Http\Base64Url;
/** /**
* REST API utilities * REST API utilities

View file

@ -2,8 +2,9 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use \Slim\Container; use Slim\Container;
/** /**
* Abstract Class ApiController * Abstract Class ApiController
@ -25,12 +26,12 @@ abstract class ApiController
protected $conf; protected $conf;
/** /**
* @var \LinkDB * @var LinkDB
*/ */
protected $linkDb; protected $linkDb;
/** /**
* @var \History * @var HistoryController
*/ */
protected $history; protected $history;

View file

@ -14,7 +14,7 @@
* *
* @package Shaarli\Api\Controllers * @package Shaarli\Api\Controllers
*/ */
class History extends ApiController class HistoryController extends ApiController
{ {
/** /**
* Service providing operation regarding Shaarli datastore and settings. * Service providing operation regarding Shaarli datastore and settings.

View file

@ -4,7 +4,6 @@
use Shaarli\Api\ApiUtils; use Shaarli\Api\ApiUtils;
use Shaarli\Api\Exceptions\ApiBadParametersException; use Shaarli\Api\Exceptions\ApiBadParametersException;
use Shaarli\Api\Exceptions\ApiLinkNotFoundException;
use Shaarli\Api\Exceptions\ApiTagNotFoundException; use Shaarli\Api\Exceptions\ApiTagNotFoundException;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;

View file

@ -2,8 +2,6 @@
namespace Shaarli\Api\Exceptions; namespace Shaarli\Api\Exceptions;
use Slim\Http\Response;
/** /**
* Class ApiLinkNotFoundException * Class ApiLinkNotFoundException
* *

View file

@ -2,8 +2,6 @@
namespace Shaarli\Api\Exceptions; namespace Shaarli\Api\Exceptions;
use Slim\Http\Response;
/** /**
* Class ApiTagNotFoundException * Class ApiTagNotFoundException
* *

View file

@ -1,4 +1,15 @@
<?php <?php
namespace Shaarli\Bookmark;
use ArrayAccess;
use Countable;
use DateTime;
use Iterator;
use Shaarli\Bookmark\Exception\LinkNotFoundException;
use Shaarli\Exceptions\IOException;
use Shaarli\FileUtils;
/** /**
* Data storage for links. * Data storage for links.
* *
@ -108,6 +119,7 @@ public function __construct(
$redirector = '', $redirector = '',
$redirectorEncode = true $redirectorEncode = true
) { ) {
$this->datastore = $datastore; $this->datastore = $datastore;
$this->loggedIn = $isLoggedIn; $this->loggedIn = $isLoggedIn;
$this->hidePublicLinks = $hidePublicLinks; $this->hidePublicLinks = $hidePublicLinks;
@ -418,7 +430,7 @@ public function filterDay($request)
* - 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 bool $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.
*/ */
@ -428,6 +440,7 @@ public function filterSearch(
$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']) : '';

View file

@ -1,5 +1,10 @@
<?php <?php
namespace Shaarli\Bookmark;
use Exception;
use Shaarli\Bookmark\Exception\LinkNotFoundException;
/** /**
* Class LinkFilter. * Class LinkFilter.
* *
@ -132,7 +137,7 @@ private function noFilter($visibility = 'all')
* *
* @return array $filtered array containing permalink data. * @return array $filtered array containing permalink data.
* *
* @throws LinkNotFoundException if the smallhash doesn't match any link. * @throws \Shaarli\Bookmark\Exception\LinkNotFoundException if the smallhash doesn't match any link.
*/ */
private function filterSmallHash($smallHash) private function filterSmallHash($smallHash)
{ {
@ -250,7 +255,9 @@ private function filterFulltext($searchterms, $visibility = 'all')
/** /**
* generate a regex fragment out of a tag * generate a regex fragment out of a tag
*
* @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
*
* @return string generated regex fragment * @return string generated regex fragment
*/ */
private static function tag2regex($tag) private static function tag2regex($tag)
@ -440,14 +447,3 @@ public static function tagsStrToArray($tags, $casesensitive)
return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY); return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
} }
} }
class LinkNotFoundException extends Exception
{
/**
* LinkNotFoundException constructor.
*/
public function __construct()
{
$this->message = t('The link you are trying to reach does not exist or has been deleted.');
}
}

View file

@ -1,11 +1,13 @@
<?php <?php
use Shaarli\Bookmark\LinkDB;
/** /**
* Get cURL callback function for CURLOPT_WRITEFUNCTION * Get cURL callback function for CURLOPT_WRITEFUNCTION
* *
* @param string $charset to extract from the downloaded page (reference) * @param string $charset to extract from the downloaded page (reference)
* @param string $title to extract from the downloaded page (reference) * @param string $title to extract from the downloaded page (reference)
* @param string $curlGetInfo Optionnaly overrides curl_getinfo function * @param string $curlGetInfo Optionally overrides curl_getinfo function
* *
* @return Closure * @return Closure
*/ */

View file

@ -0,0 +1,15 @@
<?php
namespace Shaarli\Bookmark\Exception;
use Exception;
class LinkNotFoundException extends Exception
{
/**
* LinkNotFoundException constructor.
*/
public function __construct()
{
$this->message = t('The link you are trying to reach does not exist or has been deleted.');
}
}

View file

@ -47,7 +47,7 @@ public function write($filepath, $conf)
$print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
$data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
if (!file_put_contents($filepath, $data)) { if (!file_put_contents($filepath, $data)) {
throw new \IOException( throw new \Shaarli\Exceptions\IOException(
$filepath, $filepath,
t('Shaarli could not create the config file. '. t('Shaarli could not create the config file. '.
'Please make sure Shaarli has the right to write in the folder is it installed in.') 'Please make sure Shaarli has the right to write in the folder is it installed in.')

View file

@ -207,7 +207,7 @@ public function exists($setting)
* *
* @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
* @throws UnauthorizedConfigException: user is not authorize to change configuration. * @throws UnauthorizedConfigException: user is not authorize to change configuration.
* @throws \IOException: an error occurred while writing the new config file. * @throws \Shaarli\Exceptions\IOException: an error occurred while writing the new config file.
*/ */
public function write($isLoggedIn) public function write($isLoggedIn)
{ {

View file

@ -27,7 +27,7 @@ class ConfigPhp implements ConfigIO
/** /**
* Map legacy config keys with the new ones. * Map legacy config keys with the new ones.
* If ConfigPhp is used, getting <newkey> will actually look for <legacykey>. * If ConfigPhp is used, getting <newkey> will actually look for <legacykey>.
* The Updater will use this array to transform keys when switching to JSON. * The updater will use this array to transform keys when switching to JSON.
* *
* @var array current key => legacy key. * @var array current key => legacy key.
*/ */
@ -124,7 +124,7 @@ public function write($filepath, $conf)
if (!file_put_contents($filepath, $configStr) if (!file_put_contents($filepath, $configStr)
|| strcmp(file_get_contents($filepath), $configStr) != 0 || strcmp(file_get_contents($filepath), $configStr) != 0
) { ) {
throw new \IOException( throw new \Shaarli\Exceptions\IOException(
$filepath, $filepath,
t('Shaarli could not create the config file. '. t('Shaarli could not create the config file. '.
'Please make sure Shaarli has the right to write in the folder is it installed in.') 'Please make sure Shaarli has the right to write in the folder is it installed in.')

View file

@ -1,4 +1,7 @@
<?php <?php
namespace Shaarli\Exceptions;
use Exception;
/** /**
* Exception class thrown when a filesystem access failure happens * Exception class thrown when a filesystem access failure happens

View file

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

View file

@ -1,4 +1,7 @@
<?php <?php
namespace Shaarli\Feed;
use DateTime;
/** /**
* FeedBuilder class. * FeedBuilder class.
@ -28,7 +31,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;
@ -38,12 +41,12 @@ class FeedBuilder
protected $feedType; protected $feedType;
/** /**
* @var array $_SERVER. * @var array $_SERVER
*/ */
protected $serverInfo; protected $serverInfo;
/** /**
* @var array $_GET. * @var array $_GET
*/ */
protected $userInput; protected $userInput;
@ -75,11 +78,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)
{ {
@ -164,7 +168,6 @@ protected function buildItem($link, $pageaddr)
$link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
} else { } else {
$link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM); $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
;
} }
// Save the more recent item. // Save the more recent item.
@ -224,10 +227,10 @@ public function getTypeLanguage()
{ {
// Use the locale do define the language, if available. // Use the locale do define the language, if available.
if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) {
$length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2;
return str_replace('_', '-', substr($this->locale, 0, $length)); return str_replace('_', '-', substr($this->locale, 0, $length));
} }
return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en'; return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en';
} }
/** /**

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Shaarli; namespace Shaarli\Http;
/** /**
* URL-safe Base64 operations * URL-safe Base64 operations

View file

@ -1,4 +1,7 @@
<?php <?php
use Shaarli\Http\Url;
/** /**
* GET an HTTP URL to retrieve its content * GET an HTTP URL to retrieve its content
* Uses the cURL library or a fallback method * Uses the cURL library or a fallback method
@ -38,7 +41,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF
$cleanUrl = $urlObj->idnToAscii(); $cleanUrl = $urlObj->idnToAscii();
if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) { if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
return array(array(0 => 'Invalid HTTP Url'), false); return array(array(0 => 'Invalid HTTP UrlUtils'), false);
} }
$userAgent = $userAgent =

View file

@ -1,91 +1,6 @@
<?php <?php
/**
* Converts an array-represented URL to a string
*
* Source: http://php.net/manual/en/function.parse-url.php#106731
*
* @see http://php.net/manual/en/function.parse-url.php
*
* @param array $parsedUrl an array-represented URL
*
* @return string the string representation of the URL
*/
function unparse_url($parsedUrl)
{
$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
$port = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
$user = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
$pass = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
$query = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
$fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment"; namespace Shaarli\Http;
}
/**
* Removes undesired query parameters and fragments
*
* @param string url Url to be cleaned
*
* @return string the string representation of this URL after cleanup
*/
function cleanup_url($url)
{
$obj_url = new Url($url);
return $obj_url->cleanup();
}
/**
* Get URL scheme.
*
* @param string url Url for which the scheme is requested
*
* @return mixed the URL scheme or false if none is provided.
*/
function get_url_scheme($url)
{
$obj_url = new Url($url);
return $obj_url->getScheme();
}
/**
* Adds a trailing slash at the end of URL if necessary.
*
* @param string $url URL to check/edit.
*
* @return string $url URL with a end trailing slash.
*/
function add_trailing_slash($url)
{
return $url . (!endsWith($url, '/') ? '/' : '');
}
/**
* Replace not whitelisted protocols by 'http://' from given URL.
*
* @param string $url URL to clean
* @param array $protocols List of allowed protocols (aside from http(s)).
*
* @return string URL with allowed protocol
*/
function whitelist_protocols($url, $protocols)
{
if (startsWith($url, '?') || startsWith($url, '/')) {
return $url;
}
$protocols = array_merge(['http', 'https'], $protocols);
$protocol = preg_match('#^(\w+):/?/?#', $url, $match);
// Protocol not allowed: we remove it and replace it with http
if ($protocol === 1 && ! in_array($match[1], $protocols)) {
$url = str_replace($match[0], 'http://', $url);
} elseif ($protocol !== 1) {
$url = 'http://' . $url;
}
return $url;
}
/** /**
* URL representation and cleanup utilities * URL representation and cleanup utilities
@ -291,7 +206,7 @@ public function getHost()
} }
/** /**
* Test if the Url is an HTTP one. * Test if the UrlUtils is an HTTP one.
* *
* @return true is HTTP, false otherwise. * @return true is HTTP, false otherwise.
*/ */

View file

@ -0,0 +1,88 @@
<?php
/**
* Converts an array-represented URL to a string
*
* Source: http://php.net/manual/en/function.parse-url.php#106731
*
* @see http://php.net/manual/en/function.parse-url.php
*
* @param array $parsedUrl an array-represented URL
*
* @return string the string representation of the URL
*/
function unparse_url($parsedUrl)
{
$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
$port = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
$user = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
$pass = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
$query = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
$fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
}
/**
* Removes undesired query parameters and fragments
*
* @param string url UrlUtils to be cleaned
*
* @return string the string representation of this URL after cleanup
*/
function cleanup_url($url)
{
$obj_url = new \Shaarli\Http\Url($url);
return $obj_url->cleanup();
}
/**
* Get URL scheme.
*
* @param string url UrlUtils for which the scheme is requested
*
* @return mixed the URL scheme or false if none is provided.
*/
function get_url_scheme($url)
{
$obj_url = new \Shaarli\Http\Url($url);
return $obj_url->getScheme();
}
/**
* Adds a trailing slash at the end of URL if necessary.
*
* @param string $url URL to check/edit.
*
* @return string $url URL with a end trailing slash.
*/
function add_trailing_slash($url)
{
return $url . (!endsWith($url, '/') ? '/' : '');
}
/**
* Replace not whitelisted protocols by 'http://' from given URL.
*
* @param string $url URL to clean
* @param array $protocols List of allowed protocols (aside from http(s)).
*
* @return string URL with allowed protocol
*/
function whitelist_protocols($url, $protocols)
{
if (startsWith($url, '?') || startsWith($url, '/')) {
return $url;
}
$protocols = array_merge(['http', 'https'], $protocols);
$protocol = preg_match('#^(\w+):/?/?#', $url, $match);
// Protocol not allowed: we remove it and replace it with http
if ($protocol === 1 && ! in_array($match[1], $protocols)) {
$url = str_replace($match[0], 'http://', $url);
} elseif ($protocol !== 1) {
$url = 'http://' . $url;
}
return $url;
}

View file

@ -1,9 +1,16 @@
<?php <?php
use Psr\Log\LogLevel; namespace Shaarli\Netscape;
use Shaarli\Config\ConfigManager;
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser; use DateTime;
use DateTimeZone;
use Exception;
use Katzgrau\KLogger\Logger; use Katzgrau\KLogger\Logger;
use Psr\Log\LogLevel;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
/** /**
* Utilities to import and export bookmarks using the Netscape format * Utilities to import and export bookmarks using the Netscape format

View file

@ -1,4 +1,8 @@
<?php <?php
namespace Shaarli\Plugin;
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\Exception\PluginFileNotFoundException;
/** /**
* Class PluginManager * Class PluginManager
@ -9,12 +13,14 @@ class PluginManager
{ {
/** /**
* List of authorized plugins from configuration file. * List of authorized plugins from configuration file.
*
* @var array $authorizedPlugins * @var array $authorizedPlugins
*/ */
private $authorizedPlugins; private $authorizedPlugins;
/** /**
* List of loaded plugins. * List of loaded plugins.
*
* @var array $loadedPlugins * @var array $loadedPlugins
*/ */
private $loadedPlugins = array(); private $loadedPlugins = array();
@ -31,12 +37,14 @@ class PluginManager
/** /**
* Plugins subdirectory. * Plugins subdirectory.
*
* @var string $PLUGINS_PATH * @var string $PLUGINS_PATH
*/ */
public static $PLUGINS_PATH = 'plugins'; public static $PLUGINS_PATH = 'plugins';
/** /**
* Plugins meta files extension. * Plugins meta files extension.
*
* @var string $META_EXT * @var string $META_EXT
*/ */
public static $META_EXT = 'meta'; public static $META_EXT = 'meta';
@ -118,7 +126,7 @@ public function executeHooks($hook, &$data, $params = array())
* @param string $pluginName plugin's name. * @param string $pluginName plugin's name.
* *
* @return void * @return void
* @throws PluginFileNotFoundException - plugin files not found. * @throws \Shaarli\Plugin\Exception\PluginFileNotFoundException - plugin files not found.
*/ */
private function loadPlugin($dir, $pluginName) private function loadPlugin($dir, $pluginName)
{ {
@ -223,22 +231,3 @@ public function getErrors()
return $this->errors; return $this->errors;
} }
} }
/**
* Class PluginFileNotFoundException
*
* Raise when plugin files can't be found.
*/
class PluginFileNotFoundException extends Exception
{
/**
* Construct exception with plugin name.
* Generate message.
*
* @param string $pluginName name of the plugin not found
*/
public function __construct($pluginName)
{
$this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Shaarli\Plugin\Exception;
use Exception;
/**
* Class PluginFileNotFoundException
*
* Raise when plugin files can't be found.
*/
class PluginFileNotFoundException extends Exception
{
/**
* Construct exception with plugin name.
* Generate message.
*
* @param string $pluginName name of the plugin not found
*/
public function __construct($pluginName)
{
$this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
}
}

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Shaarli\Render;
use Exception;
use RainTPL;
use Shaarli\ApplicationUtils;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Thumbnailer; use Shaarli\Thumbnailer;
@ -37,7 +43,9 @@ class PageBuilder
*/ */
protected $token; protected $token;
/** @var bool $isLoggedIn Whether the user is logged in **/ /**
* @var bool $isLoggedIn Whether the user is logged in
*/
protected $isLoggedIn = false; protected $isLoggedIn = false;
/** /**
@ -191,7 +199,7 @@ public function renderPage($page)
* Render a 404 page (uses the template : tpl/404.tpl) * Render a 404 page (uses the template : tpl/404.tpl)
* usage: $PAGE->render404('The link was deleted') * usage: $PAGE->render404('The link was deleted')
* *
* @param string $message A messate to display what is not found * @param string $message A message to display what is not found
*/ */
public function render404($message = '') public function render404($message = '')
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Shaarli; namespace Shaarli\Render;
/** /**
* Class ThemeUtils * Class ThemeUtils

View file

@ -1,11 +1,24 @@
<?php <?php
namespace Shaarli\Updater;
use Exception;
use RainTPL;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use Shaarli\ApplicationUtils;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Bookmark\LinkFilter;
use Shaarli\Config\ConfigJson; use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigPhp;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Config\ConfigPhp;
use Shaarli\Exceptions\IOException;
use Shaarli\Thumbnailer; use Shaarli\Thumbnailer;
use Shaarli\Updater\Exception\UpdaterException;
/** /**
* Class Updater. * Class updater.
* Used to update stuff when a new Shaarli's version is reached. * Used to update stuff when a new Shaarli's version is reached.
* Update methods are ran only once, and the stored in a JSON file. * Update methods are ran only once, and the stored in a JSON file.
*/ */
@ -83,7 +96,7 @@ public function update()
} }
if ($this->methods === null) { if ($this->methods === null) {
throw new UpdaterException(t('Couldn\'t retrieve Updater class methods.')); throw new UpdaterException(t('Couldn\'t retrieve updater class methods.'));
} }
foreach ($this->methods as $method) { foreach ($this->methods as $method) {
@ -538,96 +551,3 @@ public function updateMethodSetSticky()
return true; return true;
} }
} }
/**
* Class UpdaterException.
*/
class UpdaterException extends Exception
{
/**
* @var string Method where the error occurred.
*/
protected $method;
/**
* @var Exception The parent exception.
*/
protected $previous;
/**
* Constructor.
*
* @param string $message Force the error message if set.
* @param string $method Method where the error occurred.
* @param Exception|bool $previous Parent exception.
*/
public function __construct($message = '', $method = '', $previous = false)
{
$this->method = $method;
$this->previous = $previous;
$this->message = $this->buildMessage($message);
}
/**
* Build the exception error message.
*
* @param string $message Optional given error message.
*
* @return string The built error message.
*/
private function buildMessage($message)
{
$out = '';
if (! empty($message)) {
$out .= $message . PHP_EOL;
}
if (! empty($this->method)) {
$out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
}
if (! empty($this->previous)) {
$out .= ' '. $this->previous->getMessage();
}
return $out;
}
}
/**
* Read the updates file, and return already done updates.
*
* @param string $updatesFilepath Updates file path.
*
* @return array Already done update methods.
*/
function read_updates_file($updatesFilepath)
{
if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
$content = file_get_contents($updatesFilepath);
if (! empty($content)) {
return explode(';', $content);
}
}
return array();
}
/**
* Write updates file.
*
* @param string $updatesFilepath Updates file path.
* @param array $updates Updates array to write.
*
* @throws Exception Couldn't write version number.
*/
function write_updates_file($updatesFilepath, $updates)
{
if (empty($updatesFilepath)) {
throw new Exception(t('Updates file path is not set, can\'t write updates.'));
}
$res = file_put_contents($updatesFilepath, implode(';', $updates));
if ($res === false) {
throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* Read the updates file, and return already done updates.
*
* @param string $updatesFilepath Updates file path.
*
* @return array Already done update methods.
*/
function read_updates_file($updatesFilepath)
{
if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
$content = file_get_contents($updatesFilepath);
if (! empty($content)) {
return explode(';', $content);
}
}
return array();
}
/**
* Write updates file.
*
* @param string $updatesFilepath Updates file path.
* @param array $updates Updates array to write.
*
* @throws Exception Couldn't write version number.
*/
function write_updates_file($updatesFilepath, $updates)
{
if (empty($updatesFilepath)) {
throw new Exception(t('Updates file path is not set, can\'t write updates.'));
}
$res = file_put_contents($updatesFilepath, implode(';', $updates));
if ($res === false) {
throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Shaarli\Updater\Exception;
use Exception;
/**
* Class UpdaterException.
*/
class UpdaterException extends Exception
{
/**
* @var string Method where the error occurred.
*/
protected $method;
/**
* @var Exception The parent exception.
*/
protected $previous;
/**
* Constructor.
*
* @param string $message Force the error message if set.
* @param string $method Method where the error occurred.
* @param Exception|bool $previous Parent exception.
*/
public function __construct($message = '', $method = '', $previous = false)
{
$this->method = $method;
$this->previous = $previous;
$this->message = $this->buildMessage($message);
}
/**
* Build the exception error message.
*
* @param string $message Optional given error message.
*
* @return string The built error message.
*/
private function buildMessage($message)
{
$out = '';
if (!empty($message)) {
$out .= $message . PHP_EOL;
}
if (!empty($this->method)) {
$out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
}
if (!empty($this->previous)) {
$out .= ' ' . $this->previous->getMessage();
}
return $out;
}
}

View file

@ -16,6 +16,8 @@
}, },
"require": { "require": {
"php": ">=5.6", "php": ">=5.6",
"ext-json": "*",
"ext-zlib": "*",
"shaarli/netscape-bookmark-parser": "^2.1", "shaarli/netscape-bookmark-parser": "^2.1",
"erusev/parsedown": "^1.6", "erusev/parsedown": "^1.6",
"slim/slim": "^3.0", "slim/slim": "^3.0",
@ -28,15 +30,34 @@
"phpunit/phpunit": "^5.0", "phpunit/phpunit": "^5.0",
"squizlabs/php_codesniffer": "2.*" "squizlabs/php_codesniffer": "2.*"
}, },
"suggest": {
"ext-curl": "Allows fetching web pages and thumbnails in a more robust way",
"ext-gd": "Required for thumbnail generation",
"ext-gettext": "Enables faster translation system in gettext mode",
"ext-intl": "Provides localized text sorting",
"ext-mbstring": "Provides multibyte (Unicode) string support"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Shaarli\\": "application", "Shaarli\\": "application",
"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\\Bookmark\\Exception\\": "application/bookmark/exception",
"Shaarli\\Config\\": "application/config/", "Shaarli\\Config\\": "application/config/",
"Shaarli\\Config\\Exception\\": "application/config/exception", "Shaarli\\Config\\Exception\\": "application/config/exception",
"Shaarli\\Security\\": "application/security" "Shaarli\\Exceptions\\": "application/exceptions",
"Shaarli\\Feed\\": "application/feed",
"Shaarli\\Http\\": "application/http",
"Shaarli\\Netscape\\": "application/netscape",
"Shaarli\\Plugin\\": "application/plugin",
"Shaarli\\Plugin\\Exception\\": "application/plugin/exception",
"Shaarli\\Plugin\\Wallabag\\": "plugins/wallabag",
"Shaarli\\Render\\": "application/render",
"Shaarli\\Security\\": "application/security",
"Shaarli\\Updater\\": "application/updater",
"Shaarli\\Updater\\Exception\\": "application/updater/exception"
} }
} }
} }

111
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3876b34296fedb365517b785af8384de", "content-hash": "f8965821c946c2a1271c3f8c7e8c6eea",
"packages": [ "packages": [
{ {
"name": "arthurhoaro/web-thumbnailer", "name": "arthurhoaro/web-thumbnailer",
@ -133,16 +133,16 @@
}, },
{ {
"name": "gettext/gettext", "name": "gettext/gettext",
"version": "v4.6.1", "version": "v4.6.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/oscarotero/Gettext.git", "url": "https://github.com/oscarotero/Gettext.git",
"reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a" "reference": "93176b272d61fb58a9767be71c50d19149cb1e48"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/oscarotero/Gettext/zipball/854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", "url": "https://api.github.com/repos/oscarotero/Gettext/zipball/93176b272d61fb58a9767be71c50d19149cb1e48",
"reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", "reference": "93176b272d61fb58a9767be71c50d19149cb1e48",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -191,20 +191,20 @@
"po", "po",
"translation" "translation"
], ],
"time": "2018-08-27T15:40:19+00:00" "time": "2019-01-12T18:40:56+00:00"
}, },
{ {
"name": "gettext/languages", "name": "gettext/languages",
"version": "2.4.0", "version": "2.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/mlocati/cldr-to-gettext-plural-rules.git", "url": "https://github.com/mlocati/cldr-to-gettext-plural-rules.git",
"reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5" "reference": "78db2d17933f0765a102f368a6663f057162ddbd"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/1b74377bd0c4cd87e8d72b948f5d8867e23505a5", "url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/78db2d17933f0765a102f368a6663f057162ddbd",
"reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5", "reference": "78db2d17933f0765a102f368a6663f057162ddbd",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -252,7 +252,7 @@
"translations", "translations",
"unicode" "unicode"
], ],
"time": "2018-06-21T15:58:36+00:00" "time": "2018-11-13T22:06:07+00:00"
}, },
{ {
"name": "katzgrau/klogger", "name": "katzgrau/klogger",
@ -542,16 +542,16 @@
}, },
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.0.2", "version": "1.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -585,7 +585,7 @@
"psr", "psr",
"psr-3" "psr-3"
], ],
"time": "2016-10-10T12:19:37+00:00" "time": "2018-11-20T15:27:04+00:00"
}, },
{ {
"name": "pubsubhubbub/publisher", "name": "pubsubhubbub/publisher",
@ -2023,16 +2023,16 @@
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
"version": "2.9.1", "version": "2.9.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" "reference": "2acf168de78487db620ab4bc524135a13cfe6745"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745",
"reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", "reference": "2acf168de78487db620ab4bc524135a13cfe6745",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2097,20 +2097,20 @@
"phpcs", "phpcs",
"standards" "standards"
], ],
"time": "2017-05-22T02:43:20+00:00" "time": "2018-11-07T22:31:41+00:00"
}, },
{ {
"name": "symfony/console", "name": "symfony/console",
"version": "v3.4.17", "version": "v3.4.21",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/console.git", "url": "https://github.com/symfony/console.git",
"reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b" "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", "url": "https://api.github.com/repos/symfony/console/zipball/a700b874d3692bc8342199adfb6d3b99f62cc61a",
"reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2166,20 +2166,20 @@
], ],
"description": "Symfony Console Component", "description": "Symfony Console Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-10-02T16:33:53+00:00" "time": "2019-01-04T04:42:43+00:00"
}, },
{ {
"name": "symfony/debug", "name": "symfony/debug",
"version": "v3.4.17", "version": "v3.4.21",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/debug.git", "url": "https://github.com/symfony/debug.git",
"reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6" "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/0a612e9dfbd2ccce03eb174365f31ecdca930ff6", "url": "https://api.github.com/repos/symfony/debug/zipball/26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186",
"reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6", "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2222,20 +2222,20 @@
], ],
"description": "Symfony Debug Component", "description": "Symfony Debug Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-10-02T16:33:53+00:00" "time": "2019-01-01T13:45:19+00:00"
}, },
{ {
"name": "symfony/finder", "name": "symfony/finder",
"version": "v3.4.17", "version": "v3.4.21",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/finder.git", "url": "https://github.com/symfony/finder.git",
"reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d" "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/54ba444dddc5bd5708a34bd095ea67c6eb54644d", "url": "https://api.github.com/repos/symfony/finder/zipball/3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e",
"reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d", "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2271,11 +2271,11 @@
], ],
"description": "Symfony Finder Component", "description": "Symfony Finder Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-10-03T08:46:40+00:00" "time": "2019-01-01T13:45:19+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.9.0", "version": "v1.10.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
@ -2333,16 +2333,16 @@
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.9.0", "version": "v1.10.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" "reference": "c79c051f5b3a46be09205c73b80b346e4153e494"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "reference": "c79c051f5b3a46be09205c73b80b346e4153e494",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2388,20 +2388,20 @@
"portable", "portable",
"shim" "shim"
], ],
"time": "2018-08-06T14:22:27+00:00" "time": "2018-09-21T13:07:52+00:00"
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v3.4.17", "version": "v3.4.21",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f" "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/640b6c27fed4066d64b64d5903a86043f4a4de7f", "url": "https://api.github.com/repos/symfony/yaml/zipball/554a59a1ccbaac238a89b19c8e551a556fd0e2ea",
"reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f", "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2447,7 +2447,7 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-10-02T16:33:53+00:00" "time": "2019-01-01T13:45:19+00:00"
}, },
{ {
"name": "theseer/fdomdocument", "name": "theseer/fdomdocument",
@ -2491,20 +2491,21 @@
}, },
{ {
"name": "webmozart/assert", "name": "webmozart/assert",
"version": "1.3.0", "version": "1.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozart/assert.git",
"reference": "0df1908962e7a3071564e857d86874dad1ef204a" "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9",
"reference": "0df1908962e7a3071564e857d86874dad1ef204a", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^5.3.3 || ^7.0" "php": "^5.3.3 || ^7.0",
"symfony/polyfill-ctype": "^1.8"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.6", "phpunit/phpunit": "^4.6",
@ -2537,7 +2538,7 @@
"check", "check",
"validate" "validate"
], ],
"time": "2018-01-29T19:49:41+00:00" "time": "2018-12-25T11:19:39+00:00"
} }
], ],
"aliases": [], "aliases": [],
@ -2548,7 +2549,9 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": ">=5.6" "php": ">=5.6",
"ext-json": "*",
"ext-zlib": "*"
}, },
"platform-dev": [], "platform-dev": [],
"platform-overrides": { "platform-overrides": {

View file

@ -56,31 +56,33 @@
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// Shaarli library // Shaarli library
require_once 'application/ApplicationUtils.php'; require_once 'application/bookmark/LinkUtils.php';
require_once 'application/Cache.php';
require_once 'application/CachedPage.php';
require_once 'application/config/ConfigPlugin.php'; require_once 'application/config/ConfigPlugin.php';
require_once 'application/FeedBuilder.php'; require_once 'application/feed/Cache.php';
require_once 'application/http/HttpUtils.php';
require_once 'application/http/UrlUtils.php';
require_once 'application/updater/UpdaterUtils.php';
require_once 'application/FileUtils.php'; require_once 'application/FileUtils.php';
require_once 'application/History.php';
require_once 'application/HttpUtils.php';
require_once 'application/LinkDB.php';
require_once 'application/LinkFilter.php';
require_once 'application/LinkUtils.php';
require_once 'application/NetscapeBookmarkUtils.php';
require_once 'application/PageBuilder.php';
require_once 'application/TimeZone.php'; require_once 'application/TimeZone.php';
require_once 'application/Url.php';
require_once 'application/Utils.php'; require_once 'application/Utils.php';
require_once 'application/PluginManager.php';
require_once 'application/Router.php'; use \Shaarli\ApplicationUtils;
require_once 'application/Updater.php'; use \Shaarli\Bookmark\Exception\LinkNotFoundException;
use \Shaarli\Bookmark\LinkDB;
use \Shaarli\Config\ConfigManager; use \Shaarli\Config\ConfigManager;
use \Shaarli\Feed\CachedPage;
use \Shaarli\Feed\FeedBuilder;
use \Shaarli\History;
use \Shaarli\Languages; use \Shaarli\Languages;
use \Shaarli\Netscape\NetscapeBookmarkUtils;
use \Shaarli\Plugin\PluginManager;
use \Shaarli\Render\PageBuilder;
use \Shaarli\Render\ThemeUtils;
use \Shaarli\Router;
use \Shaarli\Security\LoginManager; use \Shaarli\Security\LoginManager;
use \Shaarli\Security\SessionManager; use \Shaarli\Security\SessionManager;
use \Shaarli\ThemeUtils;
use \Shaarli\Thumbnailer; use \Shaarli\Thumbnailer;
use \Shaarli\Updater\Updater;
// Ensure the PHP version is supported // Ensure the PHP version is supported
try { try {

View file

@ -5,6 +5,8 @@
* Adds the addlink input on the linklist page. * Adds the addlink input on the linklist page.
*/ */
use Shaarli\Router;
/** /**
* When linklist is displayed, add play videos to header's toolbar. * When linklist is displayed, add play videos to header's toolbar.
* *

View file

@ -5,6 +5,8 @@
* Add an icon in the link list for archive.org. * Add an icon in the link list for archive.org.
*/ */
use Shaarli\Plugin\PluginManager;
/** /**
* Add archive.org icon to link_plugin when rendering linklist. * Add archive.org icon to link_plugin when rendering linklist.
* *

View file

@ -15,6 +15,8 @@
*/ */
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/** /**
* In the footer hook, there is a working example of a translation extension for Shaarli. * In the footer hook, there is a working example of a translation extension for Shaarli.

View file

@ -5,6 +5,8 @@
*/ */
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/** /**
* Display an error everywhere if the plugin is enabled without configuration. * Display an error everywhere if the plugin is enabled without configuration.

View file

@ -7,6 +7,8 @@
*/ */
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/* /*
* If this tag is used on a shaare, the description won't be processed by Parsedown. * If this tag is used on a shaare, the description won't be processed by Parsedown.

View file

@ -4,6 +4,8 @@
* Adds tracking code on each page. * Adds tracking code on each page.
*/ */
use Shaarli\Plugin\PluginManager;
/** /**
* Initialization function. * Initialization function.
* It will be called when the plugin is loaded. * It will be called when the plugin is loaded.

View file

@ -6,6 +6,9 @@
* Note: this plugin adds jQuery. * Note: this plugin adds jQuery.
*/ */
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/** /**
* When linklist is displayed, add play videos to header's toolbar. * When linklist is displayed, add play videos to header's toolbar.
* *

View file

@ -11,6 +11,9 @@
use pubsubhubbub\publisher\Publisher; use pubsubhubbub\publisher\Publisher;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Feed\FeedBuilder;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/** /**
* Plugin init function - set the hub to the default appspot one. * Plugin init function - set the hub to the default appspot one.

View file

@ -5,6 +5,9 @@
* Display a QRCode icon in link list. * Display a QRCode icon in link list.
*/ */
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/** /**
* Add qrcode icon to link_plugin when rendering linklist. * Add qrcode icon to link_plugin when rendering linklist.
* *

View file

@ -1,4 +1,5 @@
<?php <?php
namespace Shaarli\Plugin\Wallabag;
/** /**
* Class WallabagInstance. * Class WallabagInstance.

View file

@ -1,11 +1,11 @@
<?php <?php
/** /**
* Plugin Wallabag. * Wallabag plugin
*/ */
require_once 'WallabagInstance.php';
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Plugin\Wallabag\WallabagInstance;
/** /**
* Init function, return an error if the server is not set. * Init function, return an error if the server is not set.

View file

@ -1,33 +1,14 @@
<?php <?php
namespace Shaarli;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
/** require_once 'tests/utils/FakeApplicationUtils.php';
* ApplicationUtils' tests
*/
require_once 'application/ApplicationUtils.php';
/**
* Fake ApplicationUtils class to avoid HTTP requests
*/
class FakeApplicationUtils extends ApplicationUtils
{
public static $VERSION_CODE = '';
/**
* Toggle HTTP requests, allow overriding the version code
*/
public static function getVersion($url, $timeout = 0)
{
return self::$VERSION_CODE;
}
}
/** /**
* Unitary tests for Shaarli utilities * Unitary tests for Shaarli utilities
*/ */
class ApplicationUtilsTest extends PHPUnit_Framework_TestCase class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
{ {
protected static $testUpdateFile = 'sandbox/update.txt'; protected static $testUpdateFile = 'sandbox/update.txt';
protected static $testVersion = '0.5.0'; protected static $testVersion = '0.5.0';

View file

@ -1,13 +1,15 @@
<?php <?php
require_once 'application/FileUtils.php'; namespace Shaarli;
use Exception;
/** /**
* Class FileUtilsTest * Class FileUtilsTest
* *
* Test file utility class. * Test file utility class.
*/ */
class FileUtilsTest extends PHPUnit_Framework_TestCase class FileUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string Test file path. * @var string Test file path.
@ -48,7 +50,7 @@ public function testSimpleWriteRead()
/** /**
* File not writable: raise an exception. * File not writable: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "sandbox/flat.db" * @expectedExceptionMessage Error accessing "sandbox/flat.db"
*/ */
public function testWriteWithoutPermission() public function testWriteWithoutPermission()
@ -61,7 +63,7 @@ public function testWriteWithoutPermission()
/** /**
* Folder non existent: raise an exception. * Folder non existent: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "nopefolder" * @expectedExceptionMessage Error accessing "nopefolder"
*/ */
public function testWriteFolderDoesNotExist() public function testWriteFolderDoesNotExist()
@ -72,7 +74,7 @@ public function testWriteFolderDoesNotExist()
/** /**
* Folder non writable: raise an exception. * Folder non writable: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "sandbox" * @expectedExceptionMessage Error accessing "sandbox"
*/ */
public function testWriteFolderPermission() public function testWriteFolderPermission()

View file

@ -1,9 +1,11 @@
<?php <?php
require_once 'application/History.php'; namespace Shaarli;
use DateTime;
use Exception;
class HistoryTest extends PHPUnit_Framework_TestCase class HistoryTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string History file path * @var string History file path

View file

@ -7,7 +7,7 @@
/** /**
* Class LanguagesTest. * Class LanguagesTest.
*/ */
class LanguagesTest extends \PHPUnit_Framework_TestCase class LanguagesTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string Config file path (without extension). * @var string Config file path (without extension).

View file

@ -1,16 +1,12 @@
<?php <?php
namespace Shaarli\Plugin;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
/**
* Plugin Manager tests
*/
require_once 'application/PluginManager.php';
/** /**
* Unit tests for Plugins * Unit tests for Plugins
*/ */
class PluginManagerTest extends PHPUnit_Framework_TestCase class PluginManagerTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Path to tests plugin. * Path to tests plugin.

View file

@ -1,15 +1,10 @@
<?php <?php
namespace Shaarli;
/**
* Router tests
*/
require_once 'application/Router.php';
/** /**
* Unit tests for Router * Unit tests for Router
*/ */
class RouterTest extends PHPUnit_Framework_TestCase class RouterTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test findPage: login page output. * Test findPage: login page output.

View file

@ -8,7 +8,7 @@
/** /**
* Unitary tests for timezone utilities * Unitary tests for timezone utilities
*/ */
class TimeZoneTest extends PHPUnit_Framework_TestCase class TimeZoneTest extends PHPUnit\Framework\TestCase
{ {
/** /**
* @var array of timezones * @var array of timezones

View file

@ -10,7 +10,7 @@
/** /**
* Unitary tests for Shaarli utilities * Unitary tests for Shaarli utilities
*/ */
class UtilsTest extends PHPUnit_Framework_TestCase class UtilsTest extends PHPUnit\Framework\TestCase
{ {
// Log file // Log file
protected static $testLogFile = 'tests.log'; protected static $testLogFile = 'tests.log';

View file

@ -2,7 +2,6 @@
namespace Shaarli\Api; namespace Shaarli\Api;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -18,7 +17,7 @@
* *
* @package Api * @package Api
*/ */
class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations

View file

@ -2,12 +2,12 @@
namespace Shaarli\Api; namespace Shaarli\Api;
use Shaarli\Base64Url; use Shaarli\Http\Base64Url;
/** /**
* Class ApiUtilsTest * Class ApiUtilsTest
*/ */
class ApiUtilsTest extends \PHPUnit_Framework_TestCase class ApiUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Force the timezone for ISO datetimes. * Force the timezone for ISO datetimes.

View file

@ -1,9 +1,9 @@
<?php <?php
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -11,7 +11,7 @@
require_once 'tests/utils/ReferenceHistory.php'; require_once 'tests/utils/ReferenceHistory.php';
class HistoryTest extends \PHPUnit_Framework_TestCase class HistoryTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -34,7 +34,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
protected $container; protected $container;
/** /**
* @var History controller instance. * @var HistoryController controller instance.
*/ */
protected $controller; protected $controller;
@ -49,9 +49,9 @@ public function setUp()
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = true; $this->container['db'] = true;
$this->container['history'] = new \History(self::$testHistory); $this->container['history'] = new History(self::$testHistory);
$this->controller = new History($this->container); $this->controller = new HistoryController($this->container);
} }
/** /**
@ -78,35 +78,35 @@ public function testGetHistory()
$this->assertEquals($this->refHistory->count(), count($data)); $this->assertEquals($this->refHistory->count(), count($data));
$this->assertEquals(\History::DELETED, $data[0]['event']); $this->assertEquals(History::DELETED, $data[0]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
$data[0]['datetime'] $data[0]['datetime']
); );
$this->assertEquals(124, $data[0]['id']); $this->assertEquals(124, $data[0]['id']);
$this->assertEquals(\History::SETTINGS, $data[1]['event']); $this->assertEquals(History::SETTINGS, $data[1]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
$data[1]['datetime'] $data[1]['datetime']
); );
$this->assertNull($data[1]['id']); $this->assertNull($data[1]['id']);
$this->assertEquals(\History::UPDATED, $data[2]['event']); $this->assertEquals(History::UPDATED, $data[2]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM),
$data[2]['datetime'] $data[2]['datetime']
); );
$this->assertEquals(123, $data[2]['id']); $this->assertEquals(123, $data[2]['id']);
$this->assertEquals(\History::CREATED, $data[3]['event']); $this->assertEquals(History::CREATED, $data[3]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM),
$data[3]['datetime'] $data[3]['datetime']
); );
$this->assertEquals(124, $data[3]['id']); $this->assertEquals(124, $data[3]['id']);
$this->assertEquals(\History::CREATED, $data[4]['event']); $this->assertEquals(History::CREATED, $data[4]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
$data[4]['datetime'] $data[4]['datetime']
@ -131,7 +131,7 @@ public function testGetHistoryLimit()
$this->assertEquals(1, count($data)); $this->assertEquals(1, count($data));
$this->assertEquals(\History::DELETED, $data[0]['event']); $this->assertEquals(History::DELETED, $data[0]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
$data[0]['datetime'] $data[0]['datetime']
@ -156,7 +156,7 @@ public function testGetHistoryOffset()
$this->assertEquals(1, count($data)); $this->assertEquals(1, count($data));
$this->assertEquals(\History::CREATED, $data[0]['event']); $this->assertEquals(History::CREATED, $data[0]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
$data[0]['datetime'] $data[0]['datetime']
@ -181,7 +181,7 @@ public function testGetHistorySince()
$this->assertEquals(1, count($data)); $this->assertEquals(1, count($data));
$this->assertEquals(\History::DELETED, $data[0]['event']); $this->assertEquals(History::DELETED, $data[0]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
$data[0]['datetime'] $data[0]['datetime']
@ -206,7 +206,7 @@ public function testGetHistorySinceOffsetLimit()
$this->assertEquals(1, count($data)); $this->assertEquals(1, count($data));
$this->assertEquals(\History::SETTINGS, $data[0]['event']); $this->assertEquals(History::SETTINGS, $data[0]['event']);
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
$data[0]['datetime'] $data[0]['datetime']

View file

@ -2,7 +2,6 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -15,7 +14,7 @@
* *
* @package Api\Controllers * @package Api\Controllers
*/ */
class InfoTest extends \PHPUnit_Framework_TestCase class InfoTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -53,7 +52,7 @@ public function setUp()
$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

@ -3,13 +3,15 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
class DeleteLinkTest extends \PHPUnit_Framework_TestCase class DeleteLinkTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \LinkDB instance. * @var LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
/** /**
* @var \History instance. * @var HistoryController instance.
*/ */
protected $history; protected $history;
@ -59,10 +61,10 @@ public function setUp()
$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 LinkDB(self::$testDatastore, true, false);
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \History(self::$testHistory); $this->history = new History(self::$testHistory);
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = $this->linkDB; $this->container['db'] = $this->linkDB;
@ -96,11 +98,11 @@ public function testDeleteLinkValid()
$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 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];
$this->assertEquals(\History::DELETED, $historyEntry['event']); $this->assertEquals(History::DELETED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
@ -110,7 +112,7 @@ public function testDeleteLinkValid()
/** /**
* Test DELETE link endpoint: reach not existing ID. * Test DELETE link endpoint: reach not existing ID.
* *
* @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
*/ */
public function testDeleteLink404() public function testDeleteLink404()
{ {

View file

@ -3,7 +3,6 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -18,7 +17,7 @@
* *
* @package Shaarli\Api\Controllers * @package Shaarli\Api\Controllers
*/ */
class GetLinkIdTest extends \PHPUnit_Framework_TestCase class GetLinkIdTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -61,7 +60,7 @@ public function setUp()
$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 +107,7 @@ public function testGetLinkId()
$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

@ -1,8 +1,8 @@
<?php <?php
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -17,7 +17,7 @@
* *
* @package Shaarli\Api\Controllers * @package Shaarli\Api\Controllers
*/ */
class GetLinksTest extends \PHPUnit_Framework_TestCase class GetLinksTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -60,7 +60,7 @@ public function setUp()
$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 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 @@ public function testGetLinks()
$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(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 @@ public function testGetLinks()
// Update date // Update date
$this->assertEquals( $this->assertEquals(
\DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
$link['updated'] $link['updated']
); );
} }

View file

@ -4,6 +4,7 @@
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -40,7 +41,7 @@ class PostLinkTest extends TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \History instance. * @var HistoryController instance.
*/ */
protected $history; protected $history;
@ -70,12 +71,12 @@ public function setUp()
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \History(self::$testHistory); $this->history = new History(self::$testHistory);
$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 \History(self::$testHistory); $this->container['history'] = new History(self::$testHistory);
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -121,7 +122,7 @@ public function testPostLinkMinimal()
$data = json_decode((string) $response->getBody(), true); $data = json_decode((string) $response->getBody(), true);
$this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(self::NB_FIELDS_LINK, count($data));
$this->assertEquals(43, $data['id']); $this->assertEquals(43, $data['id']);
$this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
$this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']);
$this->assertEquals('?' . $data['shorturl'], $data['title']); $this->assertEquals('?' . $data['shorturl'], $data['title']);
$this->assertEquals('', $data['description']); $this->assertEquals('', $data['description']);
@ -133,7 +134,7 @@ public function testPostLinkMinimal()
$this->assertEquals('', $data['updated']); $this->assertEquals('', $data['updated']);
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];
$this->assertEquals(\History::CREATED, $historyEntry['event']); $this->assertEquals(History::CREATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
@ -166,7 +167,7 @@ public function testPostLinkFull()
$data = json_decode((string) $response->getBody(), true); $data = json_decode((string) $response->getBody(), true);
$this->assertEquals(self::NB_FIELDS_LINK, count($data)); $this->assertEquals(self::NB_FIELDS_LINK, count($data));
$this->assertEquals(43, $data['id']); $this->assertEquals(43, $data['id']);
$this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
$this->assertEquals('http://' . $link['url'], $data['url']); $this->assertEquals('http://' . $link['url'], $data['url']);
$this->assertEquals($link['title'], $data['title']); $this->assertEquals($link['title'], $data['title']);
$this->assertEquals($link['description'], $data['description']); $this->assertEquals($link['description'], $data['description']);
@ -210,11 +211,11 @@ public function testPostLinkDuplicate()
$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

@ -4,12 +4,13 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
class PutLinkTest extends \PHPUnit_Framework_TestCase class PutLinkTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -32,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \History instance. * @var HistoryController instance.
*/ */
protected $history; protected $history;
@ -62,12 +63,12 @@ public function setUp()
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \History(self::$testHistory); $this->history = new History(self::$testHistory);
$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 \History(self::$testHistory); $this->container['history'] = new History(self::$testHistory);
$this->controller = new Links($this->container); $this->controller = new Links($this->container);
@ -119,7 +120,7 @@ public function testPutLinkMinimal()
); );
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
@ -198,11 +199,11 @@ public function testPutLinkDuplicate()
$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

@ -3,13 +3,15 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
class DeleteTagTest extends \PHPUnit_Framework_TestCase class DeleteTagTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -32,12 +34,12 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \LinkDB instance. * @var LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
/** /**
* @var \History instance. * @var HistoryController instance.
*/ */
protected $history; protected $history;
@ -59,10 +61,10 @@ public function setUp()
$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 LinkDB(self::$testDatastore, true, false);
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \History(self::$testHistory); $this->history = new History(self::$testHistory);
$this->container = new Container(); $this->container = new Container();
$this->container['conf'] = $this->conf; $this->container['conf'] = $this->conf;
$this->container['db'] = $this->linkDB; $this->container['db'] = $this->linkDB;
@ -97,18 +99,18 @@ public function testDeleteTagValid()
$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 LinkDB(self::$testDatastore, true, false);
$tags = $this->linkDB->linksCountPerTag(); $tags = $this->linkDB->linksCountPerTag();
$this->assertFalse(isset($tags[$tagName])); $this->assertFalse(isset($tags[$tagName]));
// 2 links affected // 2 links affected
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
$historyEntry = $this->history->getHistory()[1]; $historyEntry = $this->history->getHistory()[1];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
@ -131,13 +133,13 @@ public function testDeleteTagCaseSensitivity()
$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 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);
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );

View file

@ -2,8 +2,8 @@
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -16,7 +16,7 @@
* *
* @package Shaarli\Api\Controllers * @package Shaarli\Api\Controllers
*/ */
class GetTagNameTest extends \PHPUnit_Framework_TestCase class GetTagNameTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -59,7 +59,7 @@ public function setUp()
$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 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

@ -1,8 +1,8 @@
<?php <?php
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -15,7 +15,7 @@
* *
* @package Shaarli\Api\Controllers * @package Shaarli\Api\Controllers
*/ */
class GetTagsTest extends \PHPUnit_Framework_TestCase class GetTagsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -38,7 +38,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
protected $container; protected $container;
/** /**
* @var \LinkDB instance. * @var LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -63,7 +63,7 @@ public function setUp()
$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 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

@ -1,16 +1,17 @@
<?php <?php
namespace Shaarli\Api\Controllers; namespace Shaarli\Api\Controllers;
use Shaarli\Api\Exceptions\ApiBadParametersException; use Shaarli\Api\Exceptions\ApiBadParametersException;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
class PutTagTest extends \PHPUnit_Framework_TestCase class PutTagTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -33,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
protected $refDB = null; protected $refDB = null;
/** /**
* @var \History instance. * @var HistoryController instance.
*/ */
protected $history; protected $history;
@ -43,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
protected $container; protected $container;
/** /**
* @var \LinkDB instance. * @var LinkDB instance.
*/ */
protected $linkDB; protected $linkDB;
@ -68,11 +69,11 @@ public function setUp()
$refHistory = new \ReferenceHistory(); $refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory); $refHistory->write(self::$testHistory);
$this->history = new \History(self::$testHistory); $this->history = new History(self::$testHistory);
$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 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;
@ -113,12 +114,12 @@ public function testPutLinkValid()
$this->assertEquals(2, $tags[$newName]); $this->assertEquals(2, $tags[$newName]);
$historyEntry = $this->history->getHistory()[0]; $historyEntry = $this->history->getHistory()[0];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );
$historyEntry = $this->history->getHistory()[1]; $historyEntry = $this->history->getHistory()[1];
$this->assertEquals(\History::UPDATED, $historyEntry['event']); $this->assertEquals(History::UPDATED, $historyEntry['event']);
$this->assertTrue( $this->assertTrue(
(new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
); );

View file

@ -3,9 +3,14 @@
* Link datastore tests * Link datastore tests
*/ */
require_once 'application/Cache.php'; namespace Shaarli\Bookmark;
require_once 'application/FileUtils.php';
require_once 'application/LinkDB.php'; use DateTime;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
require_once 'application/feed/Cache.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 +18,7 @@
/** /**
* 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 +78,7 @@ protected function setUp()
*/ */
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;
@ -100,7 +105,7 @@ public function testConstructLoggedOut()
/** /**
* Attempt to instantiate a LinkDB whereas the datastore is not writable * Attempt to instantiate a LinkDB whereas the datastore is not writable
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessageRegExp /Error accessing "null"/ * @expectedExceptionMessageRegExp /Error accessing "null"/
*/ */
public function testConstructDatastoreNotWriteable() public function testConstructDatastoreNotWriteable()
@ -451,7 +456,7 @@ public function testFilterHashValid()
/** /**
* Test filterHash() with an invalid smallhash. * Test filterHash() with an invalid smallhash.
* *
* @expectedException LinkNotFoundException * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/ */
public function testFilterHashInValid1() public function testFilterHashInValid1()
{ {
@ -462,7 +467,7 @@ public function testFilterHashInValid1()
/** /**
* Test filterHash() with an empty smallhash. * Test filterHash() with an empty smallhash.
* *
* @expectedException LinkNotFoundException * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/ */
public function testFilterHashInValid() public function testFilterHashInValid()
{ {

View file

@ -1,11 +1,14 @@
<?php <?php
require_once 'application/LinkFilter.php'; namespace Shaarli\Bookmark;
use Exception;
use ReferenceLinkDB;
/** /**
* Class LinkFilterTest. * Class LinkFilterTest.
*/ */
class LinkFilterTest extends PHPUnit_Framework_TestCase class LinkFilterTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string Test datastore path. * @var string Test datastore path.
@ -27,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
protected static $linkDB; protected static $linkDB;
/** /**
* Instanciate linkFilter with ReferenceLinkDB data. * Instantiate linkFilter with ReferenceLinkDB data.
*/ */
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
@ -79,10 +82,14 @@ public function testFilter()
count( count(
self::$linkFilter->filter( self::$linkFilter->filter(
LinkFilter::$FILTER_TAG, LinkFilter::$FILTER_TAG,
/*$request=*/'', /*$request=*/
/*$casesensitive=*/false, '',
/*$visibility=*/'all', /*$casesensitive=*/
/*$untaggedonly=*/true false,
/*$visibility=*/
'all',
/*$untaggedonly=*/
true
) )
) )
); );
@ -227,7 +234,7 @@ public function testFilterSmallHash()
/** /**
* No link for this hash * No link for this hash
* *
* @expectedException LinkNotFoundException * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/ */
public function testFilterUnknownSmallHash() public function testFilterUnknownSmallHash()
{ {

View file

@ -1,11 +1,15 @@
<?php <?php
require_once 'application/LinkUtils.php'; namespace Shaarli\Bookmark;
use ReferenceLinkDB;
require_once 'tests/utils/CurlUtils.php';
/** /**
* Class LinkUtilsTest. * Class LinkUtilsTest.
*/ */
class LinkUtilsTest extends PHPUnit_Framework_TestCase class LinkUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test html_extract_title() when the title is found. * Test html_extract_title() when the title is found.
@ -327,95 +331,3 @@ private function getHashtagLink($hashtag, $index = '')
return str_replace('$1', $hashtag, $hashtagLink); return str_replace('$1', $hashtag, $hashtagLink);
} }
} }
// old style mock: PHPUnit doesn't allow function mock
/**
* Returns code 200 or html content type.
*
* @param resource $ch cURL resource
* @param int $type cURL info type
*
* @return int|string 200 or 'text/html'
*/
function ut_curl_getinfo_ok($ch, $type)
{
switch ($type) {
case CURLINFO_RESPONSE_CODE:
return 200;
case CURLINFO_CONTENT_TYPE:
return 'text/html; charset=utf-8';
}
}
/**
* Returns code 200 or html content type without charset.
*
* @param resource $ch cURL resource
* @param int $type cURL info type
*
* @return int|string 200 or 'text/html'
*/
function ut_curl_getinfo_no_charset($ch, $type)
{
switch ($type) {
case CURLINFO_RESPONSE_CODE:
return 200;
case CURLINFO_CONTENT_TYPE:
return 'text/html';
}
}
/**
* Invalid response code.
*
* @param resource $ch cURL resource
* @param int $type cURL info type
*
* @return int|string 404 or 'text/html'
*/
function ut_curl_getinfo_rc_ko($ch, $type)
{
switch ($type) {
case CURLINFO_RESPONSE_CODE:
return 404;
case CURLINFO_CONTENT_TYPE:
return 'text/html; charset=utf-8';
}
}
/**
* Invalid content type.
*
* @param resource $ch cURL resource
* @param int $type cURL info type
*
* @return int|string 200 or 'text/plain'
*/
function ut_curl_getinfo_ct_ko($ch, $type)
{
switch ($type) {
case CURLINFO_RESPONSE_CODE:
return 200;
case CURLINFO_CONTENT_TYPE:
return 'text/plain';
}
}
/**
* Invalid response code and content type.
*
* @param resource $ch cURL resource
* @param int $type cURL info type
*
* @return int|string 404 or 'text/plain'
*/
function ut_curl_getinfo_rs_ct_ko($ch, $type)
{
switch ($type) {
case CURLINFO_RESPONSE_CODE:
return 404;
case CURLINFO_CONTENT_TYPE:
return 'text/plain';
}
}

View file

@ -4,7 +4,7 @@
/** /**
* Class ConfigJsonTest * Class ConfigJsonTest
*/ */
class ConfigJsonTest extends \PHPUnit_Framework_TestCase class ConfigJsonTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var ConfigJson * @var ConfigJson
@ -111,7 +111,7 @@ public function testOverwrite()
/** /**
* Write to invalid path. * Write to invalid path.
* *
* @expectedException \IOException * @expectedException \Shaarli\Exceptions\IOException
*/ */
public function testWriteInvalidArray() public function testWriteInvalidArray()
{ {
@ -122,7 +122,7 @@ public function testWriteInvalidArray()
/** /**
* Write to invalid path. * Write to invalid path.
* *
* @expectedException \IOException * @expectedException \Shaarli\Exceptions\IOException
*/ */
public function testWriteInvalidBlank() public function testWriteInvalidBlank()
{ {

View file

@ -7,7 +7,7 @@
* Note: it only test the manager with ConfigJson, * Note: it only test the manager with ConfigJson,
* ConfigPhp is only a workaround to handle the transition to JSON type. * ConfigPhp is only a workaround to handle the transition to JSON type.
*/ */
class ConfigManagerTest extends \PHPUnit_Framework_TestCase class ConfigManagerTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var ConfigManager * @var ConfigManager

View file

@ -4,7 +4,7 @@
/** /**
* Class ConfigPhpTest * Class ConfigPhpTest
*/ */
class ConfigPhpTest extends \PHPUnit_Framework_TestCase class ConfigPhpTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var ConfigPhp * @var ConfigPhp

View file

@ -8,7 +8,7 @@
/** /**
* Unitary tests for Shaarli config related functions * Unitary tests for Shaarli config related functions
*/ */
class ConfigPluginTest extends \PHPUnit_Framework_TestCase class ConfigPluginTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test save_plugin_config with valid data. * Test save_plugin_config with valid data.

View file

@ -2,16 +2,17 @@
/** /**
* Cache tests * Cache tests
*/ */
namespace Shaarli\Feed;
// required to access $_SESSION array // required to access $_SESSION array
session_start(); session_start();
require_once 'application/Cache.php'; require_once 'application/feed/Cache.php';
/** /**
* Unitary tests for cached pages * Unitary tests for cached pages
*/ */
class CacheTest extends PHPUnit_Framework_TestCase class CacheTest extends \PHPUnit\Framework\TestCase
{ {
// test cache directory // test cache directory
protected static $testCacheDir = 'sandbox/dummycache'; protected static $testCacheDir = 'sandbox/dummycache';

View file

@ -2,13 +2,12 @@
/** /**
* PageCache tests * PageCache tests
*/ */
namespace Shaarli\Feed;
require_once 'application/CachedPage.php';
/** /**
* Unitary tests for cached pages * Unitary tests for cached pages
*/ */
class CachedPageTest extends PHPUnit_Framework_TestCase class CachedPageTest extends \PHPUnit\Framework\TestCase
{ {
// test cache directory // test cache directory
protected static $testCacheDir = 'sandbox/pagecache'; protected static $testCacheDir = 'sandbox/pagecache';

View file

@ -1,14 +1,17 @@
<?php <?php
require_once 'application/FeedBuilder.php'; namespace Shaarli\Feed;
require_once 'application/LinkDB.php';
use DateTime;
use ReferenceLinkDB;
use Shaarli\Bookmark\LinkDB;
/** /**
* FeedBuilderTest class. * FeedBuilderTest class.
* *
* Unit tests for FeedBuilder. * Unit tests for FeedBuilder.
*/ */
class FeedBuilderTest extends PHPUnit_Framework_TestCase class FeedBuilderTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string locale Basque (Spain). * @var string locale Basque (Spain).

View file

@ -3,12 +3,14 @@
* HttpUtils' tests * HttpUtils' tests
*/ */
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for client_ip_id() * Unitary tests for client_ip_id()
*/ */
class ClientIpIdTest extends PHPUnit_Framework_TestCase class ClientIpIdTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Get a remote client ID based on its IP * Get a remote client ID based on its IP

View file

@ -3,12 +3,14 @@
* HttpUtils' tests * HttpUtils' tests
*/ */
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for get_http_response() * Unitary tests for get_http_response()
*/ */
class GetHttpUrlTest extends PHPUnit_Framework_TestCase class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Get an invalid local URL * Get an invalid local URL
@ -17,12 +19,12 @@ public function testGetInvalidLocalUrl()
{ {
// Local // Local
list($headers, $content) = get_http_response('/non/existent', 1); list($headers, $content) = get_http_response('/non/existent', 1);
$this->assertEquals('Invalid HTTP Url', $headers[0]); $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
$this->assertFalse($content); $this->assertFalse($content);
// Non HTTP // Non HTTP
list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1); list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
$this->assertEquals('Invalid HTTP Url', $headers[0]); $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
$this->assertFalse($content); $this->assertFalse($content);
} }

View file

@ -1,11 +1,13 @@
<?php <?php
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for getIpAddressFromProxy() * Unitary tests for getIpAddressFromProxy()
*/ */
class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
{ {
/** /**

View file

@ -3,12 +3,14 @@
* HttpUtils' tests * HttpUtils' tests
*/ */
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for index_url() * Unitary tests for index_url()
*/ */
class IndexUrlTest extends PHPUnit_Framework_TestCase class IndexUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* If on the main page, remove "index.php" from the URL resource * If on the main page, remove "index.php" from the URL resource

View file

@ -1,12 +1,15 @@
<?php <?php
namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Class IsHttpsTest * Class IsHttpsTest
* *
* Test class for is_https() function. * Test class for is_https() function.
*/ */
class IsHttpsTest extends PHPUnit_Framework_TestCase class IsHttpsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**

View file

@ -3,12 +3,14 @@
* HttpUtils' tests * HttpUtils' tests
*/ */
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for page_url() * Unitary tests for page_url()
*/ */
class PageUrlTest extends PHPUnit_Framework_TestCase class PageUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* If on the main page, remove "index.php" from the URL resource * If on the main page, remove "index.php" from the URL resource

View file

@ -3,12 +3,14 @@
* HttpUtils' tests * HttpUtils' tests
*/ */
require_once 'application/HttpUtils.php'; namespace Shaarli\Http;
require_once 'application/http/HttpUtils.php';
/** /**
* Unitary tests for server_url() * Unitary tests for server_url()
*/ */
class ServerUrlTest extends PHPUnit_Framework_TestCase class ServerUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Detect if the server uses SSL * Detect if the server uses SSL

View file

@ -1,14 +1,14 @@
<?php <?php
/** /**
* Url's tests * UrlUtils's tests
*/ */
require_once 'application/Url.php'; namespace Shaarli\Http;
/** /**
* Unitary tests for URL utilities * Unitary tests for URL utilities
*/ */
class UrlTest extends PHPUnit_Framework_TestCase class UrlTest extends \PHPUnit\Framework\TestCase
{ {
// base URL for tests // base URL for tests
protected static $baseUrl = 'http://domain.tld:3000'; protected static $baseUrl = 'http://domain.tld:3000';

View file

@ -3,9 +3,11 @@
* Unitary tests for cleanup_url() * Unitary tests for cleanup_url()
*/ */
require_once 'application/Url.php'; namespace Shaarli\Http;
class CleanupUrlTest extends PHPUnit_Framework_TestCase require_once 'application/http/UrlUtils.php';
class CleanupUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string reference URL * @var string reference URL

View file

@ -3,12 +3,14 @@
* Unitary tests for get_url_scheme() * Unitary tests for get_url_scheme()
*/ */
require_once 'application/Url.php'; namespace Shaarli\Http;
class GetUrlSchemeTest extends PHPUnit_Framework_TestCase require_once 'application/http/UrlUtils.php';
class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Get empty scheme string for empty Url * Get empty scheme string for empty UrlUtils
*/ */
public function testGetUrlSchemeEmpty() public function testGetUrlSchemeEmpty()
{ {
@ -16,7 +18,7 @@ public function testGetUrlSchemeEmpty()
} }
/** /**
* Get normal scheme of Url * Get normal scheme of UrlUtils
*/ */
public function testGetUrlScheme() public function testGetUrlScheme()
{ {

View file

@ -1,14 +1,16 @@
<?php <?php
/** /**
* Unpares Url's tests * Unpares UrlUtils's tests
*/ */
require_once 'application/Url.php'; namespace Shaarli\Http;
require_once 'application/http/UrlUtils.php';
/** /**
* Unitary tests for unparse_url() * Unitary tests for unparse_url()
*/ */
class UnparseUrlTest extends PHPUnit_Framework_TestCase class UnparseUrlTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Thanks for building nothing * Thanks for building nothing

View file

@ -1,15 +1,15 @@
<?php <?php
require_once 'application/Url.php'; namespace Shaarli\Http;
use Shaarli\Config\ConfigManager; require_once 'application/http/UrlUtils.php';
/** /**
* Class WhitelistProtocolsTest * Class WhitelistProtocolsTest
* *
* Test whitelist_protocols() function of Url. * Test whitelist_protocols() function of UrlUtils.
*/ */
class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test whitelist_protocols() on a note (relative URL). * Test whitelist_protocols() on a note (relative URL).

View file

@ -12,7 +12,7 @@
* *
* @package Shaarli * @package Shaarli
*/ */
class LanguagesFrTest extends \PHPUnit_Framework_TestCase class LanguagesFrTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string Config file path (without extension). * @var string Config file path (without extension).

View file

@ -1,11 +1,14 @@
<?php <?php
namespace Shaarli\Netscape;
require_once 'application/NetscapeBookmarkUtils.php'; use Shaarli\Bookmark\LinkDB;
require_once 'tests/utils/ReferenceLinkDB.php';
/** /**
* Netscape bookmark export * Netscape bookmark export
*/ */
class BookmarkExportTest extends PHPUnit_Framework_TestCase class BookmarkExportTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations
@ -13,7 +16,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
protected static $testDatastore = 'sandbox/datastore.php'; protected static $testDatastore = 'sandbox/datastore.php';
/** /**
* @var ReferenceLinkDB instance. * @var \ReferenceLinkDB instance.
*/ */
protected static $refDb = null; protected static $refDb = null;
@ -27,7 +30,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
*/ */
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
self::$refDb = new ReferenceLinkDB(); self::$refDb = new \ReferenceLinkDB();
self::$refDb->write(self::$testDatastore); self::$refDb->write(self::$testDatastore);
self::$linkDb = new LinkDB(self::$testDatastore, true, false); self::$linkDb = new LinkDB(self::$testDatastore, true, false);
} }

View file

@ -1,8 +1,10 @@
<?php <?php
namespace Shaarli\Netscape;
require_once 'application/NetscapeBookmarkUtils.php'; use DateTime;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\History;
/** /**
* Utility function to load a file's metadata in a $_FILES-like array * Utility function to load a file's metadata in a $_FILES-like array
@ -26,7 +28,7 @@ function file2array($filename)
/** /**
* Netscape bookmark import * Netscape bookmark import
*/ */
class BookmarkImportTest extends PHPUnit_Framework_TestCase class BookmarkImportTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @var string datastore to test write operations * @var string datastore to test write operations

Some files were not shown because too many files have changed in this diff Show more