diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index a3b2dcb..7fe3cb3 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -1,4 +1,9 @@ get('resource.theme'), - ) as $path) { - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not readable'); + 'application', + 'inc', + 'plugins', + $rainTplDir, + $rainTplDir . '/' . $conf->get('resource.theme'), + ) as $path) { + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not readable'); } } // Check cache and data directories are readable and writable foreach (array( - $conf->get('resource.thumbnails_cache'), - $conf->get('resource.data_dir'), - $conf->get('resource.page_cache'), - $conf->get('resource.raintpl_tmp'), - ) as $path) { - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not readable'); + $conf->get('resource.thumbnails_cache'), + $conf->get('resource.data_dir'), + $conf->get('resource.page_cache'), + $conf->get('resource.raintpl_tmp'), + ) as $path) { + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not readable'); } - if (! is_writable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not writable'); + if (!is_writable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not writable'); } } // Check configuration files are readable and writable foreach (array( - $conf->getConfigFileExt(), - $conf->get('resource.datastore'), - $conf->get('resource.ban_file'), - $conf->get('resource.log'), - $conf->get('resource.update_check'), - ) as $path) { - if (! is_file(realpath($path))) { + $conf->getConfigFileExt(), + $conf->get('resource.datastore'), + $conf->get('resource.ban_file'), + $conf->get('resource.log'), + $conf->get('resource.update_check'), + ) as $path) { + if (!is_file(realpath($path))) { # the file may not exist yet continue; } - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('file is not readable'); + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('file is not readable'); } - if (! is_writable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('file is not writable'); + if (!is_writable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('file is not writable'); } } diff --git a/application/FileUtils.php b/application/FileUtils.php index b89ea12..30560bf 100644 --- a/application/FileUtils.php +++ b/application/FileUtils.php @@ -1,6 +1,8 @@ historyFilePath)) { + if (!is_file($this->historyFilePath)) { FileUtils::writeFlatDB($this->historyFilePath, []); } - if (! is_writable($this->historyFilePath)) { + if (!is_writable($this->historyFilePath)) { throw new Exception(t('History file isn\'t readable or writable')); } } @@ -191,7 +195,7 @@ class History */ protected function write() { - $comparaison = new DateTime('-'. $this->retentionTime . ' seconds'); + $comparaison = new DateTime('-' . $this->retentionTime . ' seconds'); foreach ($this->history as $key => $value) { if ($value['datetime'] < $comparaison) { unset($this->history[$key]); diff --git a/application/Languages.php b/application/Languages.php index b9c5d0e..5cda802 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -3,7 +3,6 @@ namespace Shaarli; use Gettext\GettextTranslator; -use Gettext\Merge; use Gettext\Translations; use Gettext\Translator; use Gettext\TranslatorInterface; diff --git a/application/Router.php b/application/Router.php index beb3165..05877ac 100644 --- a/application/Router.php +++ b/application/Router.php @@ -1,4 +1,5 @@ get('resource.datastore'), true, $conf->get('privacy.hide_public_links'), diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index fc5ecaf..1824b5d 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php @@ -1,8 +1,8 @@ datastore = $datastore; $this->loggedIn = $isLoggedIn; $this->hidePublicLinks = $hidePublicLinks; @@ -137,7 +149,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess if (!isset($value['id']) || empty($value['url'])) { die(t('Internal Error: A link should always have an id and URL.')); } - if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) { + if (($offset !== null && !is_int($offset)) || !is_int($value['id'])) { die(t('You must specify an integer as a key.')); } if ($offset !== null && $offset !== $value['id']) { @@ -247,31 +259,31 @@ class LinkDB implements Iterator, Countable, ArrayAccess $this->links = array(); $link = array( 'id' => 1, - 'title'=> t('The personal, minimalist, super-fast, database free, bookmarking service'), - 'url'=>'https://shaarli.readthedocs.io', - 'description'=>t( + 'title' => t('The personal, minimalist, super-fast, database free, bookmarking service'), + 'url' => 'https://shaarli.readthedocs.io', + 'description' => t( 'Welcome to Shaarli! This is your first public bookmark. ' - .'To edit or delete me, you must first login. + . 'To edit or delete me, you must first login. To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page. You use the community supported version of the original Shaarli project, by Sebastien Sauvage.' ), - 'private'=>0, - 'created'=> new DateTime(), - 'tags'=>'opensource software' + 'private' => 0, + 'created' => new DateTime(), + 'tags' => 'opensource software' ); $link['shorturl'] = link_small_hash($link['created'], $link['id']); $this->links[1] = $link; $link = array( 'id' => 0, - 'title'=> t('My secret stuff... - Pastebin.com'), - 'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', - 'description'=> t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'), - 'private'=>1, - 'created'=> new DateTime('1 minute ago'), - 'tags'=>'secretstuff', + 'title' => t('My secret stuff... - Pastebin.com'), + 'url' => 'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', + 'description' => t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'), + 'private' => 1, + 'created' => new DateTime('1 minute ago'), + 'tags' => 'secretstuff', ); $link['shorturl'] = link_small_hash($link['created'], $link['id']); $this->links[0] = $link; @@ -297,7 +309,7 @@ You use the community supported version of the original Shaarli project, by Seba $toremove = array(); foreach ($this->links as $key => &$link) { - if (! $this->loggedIn && $link['private'] != 0) { + if (!$this->loggedIn && $link['private'] != 0) { // Transition for not upgraded databases. unset($this->links[$key]); continue; @@ -307,7 +319,7 @@ You use the community supported version of the original Shaarli project, by Seba sanitizeLink($link); // Remove private tags if the user is not logged in. - if (! $this->loggedIn) { + if (!$this->loggedIn) { $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']); } @@ -324,10 +336,10 @@ You use the community supported version of the original Shaarli project, by Seba } // To be able to load links before running the update, and prepare the update - if (! isset($link['created'])) { + if (!isset($link['created'])) { $link['id'] = $link['linkdate']; $link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']); - if (! empty($link['updated'])) { + if (!empty($link['updated'])) { $link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']); } $link['shorturl'] = smallHash($link['linkdate']); @@ -413,12 +425,12 @@ You use the community supported version of the original Shaarli project, by Seba /** * Filter links according to search parameters. * - * @param array $filterRequest Search request content. Supported keys: + * @param array $filterRequest Search request content. Supported keys: * - searchtags: list of tags * - searchterm: term search - * @param bool $casesensitive Optional: Perform case sensitive filter - * @param string $visibility return only all/private/public links - * @param string $untaggedonly return only untagged links + * @param bool $casesensitive Optional: Perform case sensitive filter + * @param string $visibility return only all/private/public links + * @param bool $untaggedonly return only untagged links * * @return array filtered links, all links if no suitable filter was provided. */ @@ -428,6 +440,7 @@ You use the community supported version of the original Shaarli project, by Seba $visibility = 'all', $untaggedonly = false ) { + // Filter link database according to parameters. $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; @@ -443,8 +456,8 @@ You use the community supported version of the original Shaarli project, by Seba /** * Returns the list tags appearing in the links with the given tags * - * @param array $filteringTags tags selecting the links to consider - * @param string $visibility process only all/private/public links + * @param array $filteringTags tags selecting the links to consider + * @param string $visibility process only all/private/public links * * @return array tag => linksCount */ diff --git a/application/LinkFilter.php b/application/bookmark/LinkFilter.php similarity index 93% rename from application/LinkFilter.php rename to application/bookmark/LinkFilter.php index 8f14797..9b96630 100644 --- a/application/LinkFilter.php +++ b/application/bookmark/LinkFilter.php @@ -1,5 +1,10 @@ links as $key => $value) { if ($value['private'] && $visibility === 'private') { $out[$key] = $value; - } elseif (! $value['private'] && $visibility === 'public') { + } elseif (!$value['private'] && $visibility === 'public') { $out[$key] = $value; } } @@ -132,7 +137,7 @@ class LinkFilter * * @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) { @@ -169,7 +174,7 @@ class LinkFilter * - see https://github.com/shaarli/Shaarli/issues/75 for examples * * @param string $searchterms search query. - * @param string $visibility Optional: return only all/private/public links. + * @param string $visibility Optional: return only all/private/public links. * * @return array search results. */ @@ -207,7 +212,7 @@ class LinkFilter foreach ($this->links as $id => $link) { // ignore non private links when 'privatonly' is on. if ($visibility !== 'all') { - if (! $link['private'] && $visibility === 'private') { + if (!$link['private'] && $visibility === 'private') { continue; } elseif ($link['private'] && $visibility === 'public') { continue; @@ -250,7 +255,9 @@ class LinkFilter /** * generate a regex fragment out of a tag + * * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard + * * @return string generated regex fragment */ private static function tag2regex($tag) @@ -334,7 +341,7 @@ class LinkFilter // check level of visibility // ignore non private links when 'privateonly' is on. if ($visibility !== 'all') { - if (! $link['private'] && $visibility === 'private') { + if (!$link['private'] && $visibility === 'private') { continue; } elseif ($link['private'] && $visibility === 'public') { continue; @@ -377,7 +384,7 @@ class LinkFilter $filtered = []; foreach ($this->links as $key => $link) { if ($visibility !== 'all') { - if (! $link['private'] && $visibility === 'private') { + if (!$link['private'] && $visibility === 'private') { continue; } elseif ($link['private'] && $visibility === 'public') { continue; @@ -406,7 +413,7 @@ class LinkFilter */ public function filterDay($day) { - if (! checkDateFormat('Ymd', $day)) { + if (!checkDateFormat('Ymd', $day)) { throw new Exception('Invalid date format'); } @@ -440,14 +447,3 @@ class LinkFilter 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.'); - } -} diff --git a/application/LinkUtils.php b/application/bookmark/LinkUtils.php similarity index 97% rename from application/LinkUtils.php rename to application/bookmark/LinkUtils.php index d56e019..de5b61c 100644 --- a/application/LinkUtils.php +++ b/application/bookmark/LinkUtils.php @@ -1,11 +1,13 @@ message = t('The link you are trying to reach does not exist or has been deleted.'); + } +} diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php index 8c8d561..4509357 100644 --- a/application/config/ConfigJson.php +++ b/application/config/ConfigJson.php @@ -47,7 +47,7 @@ class ConfigJson implements ConfigIO $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); if (!file_put_contents($filepath, $data)) { - throw new \IOException( + throw new \Shaarli\Exceptions\IOException( $filepath, t('Shaarli could not create the config file. '. 'Please make sure Shaarli has the right to write in the folder is it installed in.') diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index 32aaea4..e6c3507 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -207,7 +207,7 @@ class ConfigManager * * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. * @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) { diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php index 9625fe1..cad3459 100644 --- a/application/config/ConfigPhp.php +++ b/application/config/ConfigPhp.php @@ -27,7 +27,7 @@ class ConfigPhp implements ConfigIO /** * Map legacy config keys with the new ones. * If ConfigPhp is used, getting will actually look for . - * 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. */ @@ -124,7 +124,7 @@ class ConfigPhp implements ConfigIO if (!file_put_contents($filepath, $configStr) || strcmp(file_get_contents($filepath), $configStr) != 0 ) { - throw new \IOException( + throw new \Shaarli\Exceptions\IOException( $filepath, t('Shaarli could not create the config file. '. 'Please make sure Shaarli has the right to write in the folder is it installed in.') diff --git a/application/exceptions/IOException.php b/application/exceptions/IOException.php index 18e46b7..2aa25e5 100644 --- a/application/exceptions/IOException.php +++ b/application/exceptions/IOException.php @@ -1,4 +1,7 @@ path = $path; $this->message = empty($message) ? t('Error accessing') : $message; - $this->message .= ' "' . $this->path .'"'; + $this->message .= ' "' . $this->path . '"'; } } diff --git a/application/Cache.php b/application/feed/Cache.php similarity index 100% rename from application/Cache.php rename to application/feed/Cache.php diff --git a/application/CachedPage.php b/application/feed/CachedPage.php similarity index 93% rename from application/CachedPage.php rename to application/feed/CachedPage.php index e11cc52..d809bdd 100644 --- a/application/CachedPage.php +++ b/application/feed/CachedPage.php @@ -1,4 +1,7 @@ cacheDir = $cacheDir; - $this->filename = $this->cacheDir.'/'.sha1($url).'.cache'; + $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache'; $this->shouldBeCached = $shouldBeCached; } diff --git a/application/FeedBuilder.php b/application/feed/FeedBuilder.php similarity index 84% rename from application/FeedBuilder.php rename to application/feed/FeedBuilder.php index 73fafcb..b66f2f9 100644 --- a/application/FeedBuilder.php +++ b/application/feed/FeedBuilder.php @@ -1,4 +1,7 @@ hideDates || $this->isLoggedIn; // Remove leading slash from REQUEST_URI. $data['self_link'] = escape(server_url($this->serverInfo)) - . escape($this->serverInfo['REQUEST_URI']); + . escape($this->serverInfo['REQUEST_URI']); $data['index_url'] = $pageaddr; $data['usepermalinks'] = $this->usePermalinks === true; $data['links'] = $linkDisplayed; @@ -142,18 +146,18 @@ class FeedBuilder */ protected function buildItem($link, $pageaddr) { - $link['guid'] = $pageaddr .'?'. $link['shorturl']; + $link['guid'] = $pageaddr . '?' . $link['shorturl']; // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = $pageaddr . $link['url']; } if ($this->usePermalinks === true) { - $permalink = ''. t('Direct link') .''; + $permalink = '' . t('Direct link') . ''; } else { - $permalink = ''. t('Permalink') .''; + $permalink = '' . t('Permalink') . ''; } - $link['description'] = format_description($link['description'], '', false, $pageaddr); - $link['description'] .= PHP_EOL .'
— '. $permalink; + $link['description'] = format_description($link['description'], '', false, $pageaddr); + $link['description'] .= PHP_EOL . '
— ' . $permalink; $pubDate = $link['created']; $link['pub_iso_date'] = $this->getIsoDate($pubDate); @@ -164,7 +168,6 @@ class FeedBuilder $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); } else { $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM); - ; } // Save the more recent item. @@ -223,11 +226,11 @@ class FeedBuilder public function getTypeLanguage() { // Use the locale do define the language, if available. - if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { - $length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; + if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { + $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2; 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'; } /** @@ -287,7 +290,7 @@ class FeedBuilder } $intNb = intval($this->userInput['nb']); - if (! is_int($intNb) || $intNb == 0) { + if (!is_int($intNb) || $intNb == 0) { return self::$DEFAULT_NB_LINKS; } diff --git a/application/Base64Url.php b/application/http/Base64Url.php similarity index 96% rename from application/Base64Url.php rename to application/http/Base64Url.php index 54d0fcd..33fa7c1 100644 --- a/application/Base64Url.php +++ b/application/http/Base64Url.php @@ -1,6 +1,6 @@ idnToAscii(); 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 = diff --git a/application/Url.php b/application/http/Url.php similarity index 63% rename from application/Url.php rename to application/http/Url.php index 3b7f19c..90444a2 100644 --- a/application/Url.php +++ b/application/http/Url.php @@ -1,91 +1,6 @@ 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; -} +namespace Shaarli\Http; /** * URL representation and cleanup utilities @@ -182,7 +97,7 @@ class Url } return $input; } - + /** * Returns a string representation of this URL */ @@ -196,7 +111,7 @@ class Url */ protected function cleanupQuery() { - if (! isset($this->parts['query'])) { + if (!isset($this->parts['query'])) { return; } @@ -224,7 +139,7 @@ class Url */ protected function cleanupFragment() { - if (! isset($this->parts['fragment'])) { + if (!isset($this->parts['fragment'])) { return; } @@ -257,7 +172,7 @@ class Url public function idnToAscii() { $out = $this->cleanup(); - if (! function_exists('idn_to_ascii') || ! isset($this->parts['host'])) { + if (!function_exists('idn_to_ascii') || !isset($this->parts['host'])) { return $out; } $asciiHost = idn_to_ascii($this->parts['host'], 0, INTL_IDNA_VARIANT_UTS46); @@ -291,7 +206,7 @@ class Url } /** - * Test if the Url is an HTTP one. + * Test if the UrlUtils is an HTTP one. * * @return true is HTTP, false otherwise. */ diff --git a/application/http/UrlUtils.php b/application/http/UrlUtils.php new file mode 100644 index 0000000..4bc84b8 --- /dev/null +++ b/application/http/UrlUtils.php @@ -0,0 +1,88 @@ +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; +} diff --git a/application/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php similarity index 90% rename from application/NetscapeBookmarkUtils.php rename to application/netscape/NetscapeBookmarkUtils.php index 84dd2b2..2fb1a4a 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/netscape/NetscapeBookmarkUtils.php @@ -1,9 +1,16 @@ get('resource.data_dir'), - ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, + !$conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, [ 'prefix' => 'import.', 'extension' => 'log', @@ -193,7 +200,7 @@ class NetscapeBookmarkUtils } // Add a new link - @ used for UNIX timestamps - $newLinkDate = new DateTime('@'.strval($bkm['time'])); + $newLinkDate = new DateTime('@' . strval($bkm['time'])); $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get())); $newLink['created'] = $newLinkDate; $newLink['id'] = $linkDb->getNextId(); diff --git a/application/PluginManager.php b/application/plugin/PluginManager.php similarity index 87% rename from application/PluginManager.php rename to application/plugin/PluginManager.php index 1ed4db4..f7b24a8 100644 --- a/application/PluginManager.php +++ b/application/plugin/PluginManager.php @@ -1,4 +1,8 @@ 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); - } -} diff --git a/application/plugin/exception/PluginFileNotFoundException.php b/application/plugin/exception/PluginFileNotFoundException.php new file mode 100644 index 0000000..e5386f0 --- /dev/null +++ b/application/plugin/exception/PluginFileNotFoundException.php @@ -0,0 +1,23 @@ +message = sprintf(t('Plugin "%s" files not found.'), $pluginName); + } +} diff --git a/application/PageBuilder.php b/application/render/PageBuilder.php similarity index 92% rename from application/PageBuilder.php rename to application/render/PageBuilder.php index 2ca9583..0569b67 100644 --- a/application/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -1,5 +1,11 @@ conf->get('credentials.salt')) ); $this->tpl->assign('index_url', index_url($_SERVER)); - $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; + $visibility = !empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; $this->tpl->assign('visibility', $visibility); $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); @@ -126,7 +134,7 @@ class PageBuilder $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width')); $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height')); - if (! empty($_SESSION['warnings'])) { + if (!empty($_SESSION['warnings'])) { $this->tpl->assign('global_warnings', $_SESSION['warnings']); unset($_SESSION['warnings']); } @@ -189,16 +197,16 @@ class PageBuilder /** * 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 = '') { if (empty($message)) { $message = t('The page you are trying to reach does not exist or has been deleted.'); } - header($_SERVER['SERVER_PROTOCOL'] .' '. t('404 Not Found')); + header($_SERVER['SERVER_PROTOCOL'] . ' ' . t('404 Not Found')); $this->tpl->assign('error_message', $message); $this->renderPage('404'); } diff --git a/application/ThemeUtils.php b/application/render/ThemeUtils.php similarity index 96% rename from application/ThemeUtils.php rename to application/render/ThemeUtils.php index 16f2f6a..86096c6 100644 --- a/application/ThemeUtils.php +++ b/application/render/ThemeUtils.php @@ -1,6 +1,6 @@ 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) { // Not an update method or already done, pass. - if (! startsWith($method->getName(), 'updateMethod') + if (!startsWith($method->getName(), 'updateMethod') || in_array($method->getName(), $this->doneUpdates) ) { continue; @@ -139,7 +152,7 @@ class Updater } } $this->conf->write($this->isLoggedIn); - unlink($this->conf->get('resource.data_dir').'/options.php'); + unlink($this->conf->get('resource.data_dir') . '/options.php'); } return true; @@ -174,10 +187,10 @@ class Updater $subConfig = array('config', 'plugins'); foreach ($subConfig as $sub) { foreach ($oldConfig[$sub] as $key => $value) { - if (isset($legacyMap[$sub .'.'. $key])) { - $configKey = $legacyMap[$sub .'.'. $key]; + if (isset($legacyMap[$sub . '.' . $key])) { + $configKey = $legacyMap[$sub . '.' . $key]; } else { - $configKey = $sub .'.'. $key; + $configKey = $sub . '.' . $key; } $this->conf->set($configKey, $value); } @@ -233,7 +246,7 @@ class Updater return true; } - $save = $this->conf->get('resource.data_dir') .'/datastore.'. date('YmdHis') .'.php'; + $save = $this->conf->get('resource.data_dir') . '/datastore.' . date('YmdHis') . '.php'; copy($this->conf->get('resource.datastore'), $save); $links = array(); @@ -307,7 +320,7 @@ class Updater // We run the update only if this folder still contains the template files. $tplDir = $this->conf->get('resource.raintpl_tpl'); $tplFile = $tplDir . '/linklist.html'; - if (! file_exists($tplFile)) { + if (!file_exists($tplFile)) { return true; } @@ -331,7 +344,7 @@ class Updater */ public function updateMethodMoveUserCss() { - if (! is_file('inc/user.css')) { + if (!is_file('inc/user.css')) { return true; } @@ -367,11 +380,11 @@ class Updater */ public function updateMethodPiwikUrl() { - if (! $this->conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) { + if (!$this->conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) { return true; } - $this->conf->set('plugins.PIWIK_URL', 'http://'. $this->conf->get('plugins.PIWIK_URL')); + $this->conf->set('plugins.PIWIK_URL', 'http://' . $this->conf->get('plugins.PIWIK_URL')); $this->conf->write($this->isLoggedIn); return true; @@ -481,11 +494,11 @@ class Updater return true; } - if (! $this->conf->exists('general.download_max_size')) { - $this->conf->set('general.download_max_size', 1024*1024*4); + if (!$this->conf->exists('general.download_max_size')) { + $this->conf->set('general.download_max_size', 1024 * 1024 * 4); } - if (! $this->conf->exists('general.download_timeout')) { + if (!$this->conf->exists('general.download_timeout')) { $this->conf->set('general.download_timeout', 30); } @@ -538,96 +551,3 @@ class Updater 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 . '.')); - } -} diff --git a/application/updater/UpdaterUtils.php b/application/updater/UpdaterUtils.php new file mode 100644 index 0000000..34d4f42 --- /dev/null +++ b/application/updater/UpdaterUtils.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/composer.json b/composer.json index dccf83b..a52b5f7 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,8 @@ }, "require": { "php": ">=5.6", + "ext-json": "*", + "ext-zlib": "*", "shaarli/netscape-bookmark-parser": "^2.1", "erusev/parsedown": "^1.6", "slim/slim": "^3.0", @@ -28,15 +30,34 @@ "phpunit/phpunit": "^5.0", "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": { "psr-4": { "Shaarli\\": "application", "Shaarli\\Api\\": "application/api/", "Shaarli\\Api\\Controllers\\": "application/api/controllers", "Shaarli\\Api\\Exceptions\\": "application/api/exceptions", + "Shaarli\\Bookmark\\": "application/bookmark", + "Shaarli\\Bookmark\\Exception\\": "application/bookmark/exception", "Shaarli\\Config\\": "application/config/", "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" } } } diff --git a/composer.lock b/composer.lock index c43dad6..53fb217 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3876b34296fedb365517b785af8384de", + "content-hash": "f8965821c946c2a1271c3f8c7e8c6eea", "packages": [ { "name": "arthurhoaro/web-thumbnailer", @@ -133,16 +133,16 @@ }, { "name": "gettext/gettext", - "version": "v4.6.1", + "version": "v4.6.2", "source": { "type": "git", "url": "https://github.com/oscarotero/Gettext.git", - "reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a" + "reference": "93176b272d61fb58a9767be71c50d19149cb1e48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/oscarotero/Gettext/zipball/854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", - "reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", + "url": "https://api.github.com/repos/oscarotero/Gettext/zipball/93176b272d61fb58a9767be71c50d19149cb1e48", + "reference": "93176b272d61fb58a9767be71c50d19149cb1e48", "shasum": "" }, "require": { @@ -191,20 +191,20 @@ "po", "translation" ], - "time": "2018-08-27T15:40:19+00:00" + "time": "2019-01-12T18:40:56+00:00" }, { "name": "gettext/languages", - "version": "2.4.0", + "version": "2.5.0", "source": { "type": "git", "url": "https://github.com/mlocati/cldr-to-gettext-plural-rules.git", - "reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5" + "reference": "78db2d17933f0765a102f368a6663f057162ddbd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/1b74377bd0c4cd87e8d72b948f5d8867e23505a5", - "reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5", + "url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/78db2d17933f0765a102f368a6663f057162ddbd", + "reference": "78db2d17933f0765a102f368a6663f057162ddbd", "shasum": "" }, "require": { @@ -252,7 +252,7 @@ "translations", "unicode" ], - "time": "2018-06-21T15:58:36+00:00" + "time": "2018-11-13T22:06:07+00:00" }, { "name": "katzgrau/klogger", @@ -542,16 +542,16 @@ }, { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "shasum": "" }, "require": { @@ -585,7 +585,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2018-11-20T15:27:04+00:00" }, { "name": "pubsubhubbub/publisher", @@ -2023,16 +2023,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.1", + "version": "2.9.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" + "reference": "2acf168de78487db620ab4bc524135a13cfe6745" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745", + "reference": "2acf168de78487db620ab4bc524135a13cfe6745", "shasum": "" }, "require": { @@ -2097,20 +2097,20 @@ "phpcs", "standards" ], - "time": "2017-05-22T02:43:20+00:00" + "time": "2018-11-07T22:31:41+00:00" }, { "name": "symfony/console", - "version": "v3.4.17", + "version": "v3.4.21", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b" + "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", - "reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", + "url": "https://api.github.com/repos/symfony/console/zipball/a700b874d3692bc8342199adfb6d3b99f62cc61a", + "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a", "shasum": "" }, "require": { @@ -2166,20 +2166,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-10-02T16:33:53+00:00" + "time": "2019-01-04T04:42:43+00:00" }, { "name": "symfony/debug", - "version": "v3.4.17", + "version": "v3.4.21", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6" + "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/0a612e9dfbd2ccce03eb174365f31ecdca930ff6", - "reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6", + "url": "https://api.github.com/repos/symfony/debug/zipball/26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186", + "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186", "shasum": "" }, "require": { @@ -2222,20 +2222,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-10-02T16:33:53+00:00" + "time": "2019-01-01T13:45:19+00:00" }, { "name": "symfony/finder", - "version": "v3.4.17", + "version": "v3.4.21", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d" + "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/54ba444dddc5bd5708a34bd095ea67c6eb54644d", - "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d", + "url": "https://api.github.com/repos/symfony/finder/zipball/3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e", + "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e", "shasum": "" }, "require": { @@ -2271,11 +2271,11 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-10-03T08:46:40+00:00" + "time": "2019-01-01T13:45:19+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.9.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -2333,16 +2333,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.9.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", - "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", "shasum": "" }, "require": { @@ -2388,20 +2388,20 @@ "portable", "shim" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2018-09-21T13:07:52+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.17", + "version": "v3.4.21", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f" + "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/640b6c27fed4066d64b64d5903a86043f4a4de7f", - "reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f", + "url": "https://api.github.com/repos/symfony/yaml/zipball/554a59a1ccbaac238a89b19c8e551a556fd0e2ea", + "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea", "shasum": "" }, "require": { @@ -2447,7 +2447,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-10-02T16:33:53+00:00" + "time": "2019-01-01T13:45:19+00:00" }, { "name": "theseer/fdomdocument", @@ -2491,20 +2491,21 @@ }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -2537,7 +2538,7 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2018-12-25T11:19:39+00:00" } ], "aliases": [], @@ -2548,7 +2549,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6" + "php": ">=5.6", + "ext-json": "*", + "ext-zlib": "*" }, "platform-dev": [], "platform-overrides": { diff --git a/index.php b/index.php index acfcc66..633ab89 100644 --- a/index.php +++ b/index.php @@ -56,31 +56,33 @@ require_once 'inc/rain.tpl.class.php'; require_once __DIR__ . '/vendor/autoload.php'; // Shaarli library -require_once 'application/ApplicationUtils.php'; -require_once 'application/Cache.php'; -require_once 'application/CachedPage.php'; +require_once 'application/bookmark/LinkUtils.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/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/Url.php'; require_once 'application/Utils.php'; -require_once 'application/PluginManager.php'; -require_once 'application/Router.php'; -require_once 'application/Updater.php'; + +use \Shaarli\ApplicationUtils; +use \Shaarli\Bookmark\Exception\LinkNotFoundException; +use \Shaarli\Bookmark\LinkDB; use \Shaarli\Config\ConfigManager; +use \Shaarli\Feed\CachedPage; +use \Shaarli\Feed\FeedBuilder; +use \Shaarli\History; 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\SessionManager; -use \Shaarli\ThemeUtils; use \Shaarli\Thumbnailer; +use \Shaarli\Updater\Updater; // Ensure the PHP version is supported try { diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php index 8c05a23..8bf4ed4 100644 --- a/plugins/addlink_toolbar/addlink_toolbar.php +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -5,6 +5,8 @@ * Adds the addlink input on the linklist page. */ +use Shaarli\Router; + /** * When linklist is displayed, add play videos to header's toolbar. * diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index 5dcea5a..0ee1c73 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -5,6 +5,8 @@ * Add an icon in the link list for archive.org. */ +use Shaarli\Plugin\PluginManager; + /** * Add archive.org icon to link_plugin when rendering linklist. * diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index ca520d1..95ea7fe 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -15,6 +15,8 @@ */ 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. diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index 378c11a..dab75dd 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php @@ -5,6 +5,8 @@ */ use Shaarli\Config\ConfigManager; +use Shaarli\Plugin\PluginManager; +use Shaarli\Router; /** * Display an error everywhere if the plugin is enabled without configuration. diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php index 8823af9..628970d 100644 --- a/plugins/markdown/markdown.php +++ b/plugins/markdown/markdown.php @@ -7,6 +7,8 @@ */ 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. diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php index ca00c2b..17b1aec 100644 --- a/plugins/piwik/piwik.php +++ b/plugins/piwik/piwik.php @@ -4,6 +4,8 @@ * Adds tracking code on each page. */ +use Shaarli\Plugin\PluginManager; + /** * Initialization function. * It will be called when the plugin is loaded. diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php index c6d6b0c..0341ed5 100644 --- a/plugins/playvideos/playvideos.php +++ b/plugins/playvideos/playvideos.php @@ -6,6 +6,9 @@ * Note: this plugin adds jQuery. */ +use Shaarli\Plugin\PluginManager; +use Shaarli\Router; + /** * When linklist is displayed, add play videos to header's toolbar. * diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 9f0342a..2878c05 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -11,6 +11,9 @@ use pubsubhubbub\publisher\Publisher; 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. diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 4b59caa..34eef8b 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -5,6 +5,9 @@ * Display a QRCode icon in link list. */ +use Shaarli\Plugin\PluginManager; +use Shaarli\Router; + /** * Add qrcode icon to link_plugin when rendering linklist. * diff --git a/plugins/wallabag/WallabagInstance.php b/plugins/wallabag/WallabagInstance.php index eb8ab61..f4a0a92 100644 --- a/plugins/wallabag/WallabagInstance.php +++ b/plugins/wallabag/WallabagInstance.php @@ -1,4 +1,5 @@ container = new Container(); $this->container['conf'] = $this->conf; $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 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->refHistory->count(), count($data)); - $this->assertEquals(\History::DELETED, $data[0]['event']); + $this->assertEquals(History::DELETED, $data[0]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), $data[0]['datetime'] ); $this->assertEquals(124, $data[0]['id']); - $this->assertEquals(\History::SETTINGS, $data[1]['event']); + $this->assertEquals(History::SETTINGS, $data[1]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), $data[1]['datetime'] ); $this->assertNull($data[1]['id']); - $this->assertEquals(\History::UPDATED, $data[2]['event']); + $this->assertEquals(History::UPDATED, $data[2]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), $data[2]['datetime'] ); $this->assertEquals(123, $data[2]['id']); - $this->assertEquals(\History::CREATED, $data[3]['event']); + $this->assertEquals(History::CREATED, $data[3]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), $data[3]['datetime'] ); $this->assertEquals(124, $data[3]['id']); - $this->assertEquals(\History::CREATED, $data[4]['event']); + $this->assertEquals(History::CREATED, $data[4]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), $data[4]['datetime'] @@ -131,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($data)); - $this->assertEquals(\History::DELETED, $data[0]['event']); + $this->assertEquals(History::DELETED, $data[0]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), $data[0]['datetime'] @@ -156,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($data)); - $this->assertEquals(\History::CREATED, $data[0]['event']); + $this->assertEquals(History::CREATED, $data[0]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), $data[0]['datetime'] @@ -181,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($data)); - $this->assertEquals(\History::DELETED, $data[0]['event']); + $this->assertEquals(History::DELETED, $data[0]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), $data[0]['datetime'] @@ -206,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($data)); - $this->assertEquals(\History::SETTINGS, $data[0]['event']); + $this->assertEquals(History::SETTINGS, $data[0]['event']); $this->assertEquals( \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), $data[0]['datetime'] diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index e437082..e70d371 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php @@ -2,7 +2,6 @@ namespace Shaarli\Api\Controllers; use Shaarli\Config\ConfigManager; - use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -15,7 +14,7 @@ use Slim\Http\Response; * * @package Api\Controllers */ -class InfoTest extends \PHPUnit_Framework_TestCase +class InfoTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -53,7 +52,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase $this->container = new Container(); $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->controller = new Info($this->container); diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 7d79713..90193e2 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php @@ -3,13 +3,15 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; use Slim\Http\Response; -class DeleteLinkTest extends \PHPUnit_Framework_TestCase +class DeleteLinkTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase protected $refDB = null; /** - * @var \LinkDB instance. + * @var LinkDB instance. */ protected $linkDB; /** - * @var \History instance. + * @var HistoryController instance. */ protected $history; @@ -59,10 +61,10 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->refDB = new \ReferenceLinkDB(); $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->write(self::$testHistory); - $this->history = new \History(self::$testHistory); + $this->history = new History(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = $this->linkDB; @@ -96,11 +98,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase $this->assertEquals(204, $response->getStatusCode()); $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])); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::DELETED, $historyEntry['event']); + $this->assertEquals(History::DELETED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); @@ -110,7 +112,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase /** * Test DELETE link endpoint: reach not existing ID. * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException + * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException */ public function testDeleteLink404() { diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index 57528d5..cb9b7f6 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -3,7 +3,6 @@ namespace Shaarli\Api\Controllers; use Shaarli\Config\ConfigManager; - use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -18,7 +17,7 @@ use Slim\Http\Response; * * @package Shaarli\Api\Controllers */ -class GetLinkIdTest extends \PHPUnit_Framework_TestCase +class GetLinkIdTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -61,7 +60,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase $this->container = new Container(); $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->controller = new Links($this->container); @@ -108,7 +107,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase $this->assertEquals('sTuff', $data['tags'][0]); $this->assertEquals(false, $data['private']); $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'] ); $this->assertEmpty($data['updated']); diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 64f0277..711a315 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -1,8 +1,8 @@ container = new Container(); $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->controller = new Links($this->container); @@ -114,7 +114,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase $this->assertEquals('sTuff', $first['tags'][0]); $this->assertEquals(false, $first['private']); $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'] ); $this->assertEmpty($first['updated']); @@ -125,7 +125,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase // Update date $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'] ); } diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 5c2b562..d683a98 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -4,6 +4,7 @@ namespace Shaarli\Api\Controllers; use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -40,7 +41,7 @@ class PostLinkTest extends TestCase protected $refDB = null; /** - * @var \History instance. + * @var HistoryController instance. */ protected $history; @@ -70,12 +71,12 @@ class PostLinkTest extends TestCase $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); - $this->history = new \History(self::$testHistory); + $this->history = new History(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); - $this->container['history'] = new \History(self::$testHistory); + $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); + $this->container['history'] = new History(self::$testHistory); $this->controller = new Links($this->container); @@ -121,7 +122,7 @@ class PostLinkTest extends TestCase $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $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('?' . $data['shorturl'], $data['title']); $this->assertEquals('', $data['description']); @@ -133,7 +134,7 @@ class PostLinkTest extends TestCase $this->assertEquals('', $data['updated']); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::CREATED, $historyEntry['event']); + $this->assertEquals(History::CREATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); @@ -166,7 +167,7 @@ class PostLinkTest extends TestCase $data = json_decode((string) $response->getBody(), true); $this->assertEquals(self::NB_FIELDS_LINK, count($data)); $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($link['title'], $data['title']); $this->assertEquals($link['description'], $data['description']); @@ -210,11 +211,11 @@ class PostLinkTest extends TestCase $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(false, $data['private']); $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']) ); $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']) ); } diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index f276b4c..cd815b6 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -4,12 +4,13 @@ namespace Shaarli\Api\Controllers; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; use Slim\Http\Response; -class PutLinkTest extends \PHPUnit_Framework_TestCase +class PutLinkTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -32,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase protected $refDB = null; /** - * @var \History instance. + * @var HistoryController instance. */ protected $history; @@ -62,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); - $this->history = new \History(self::$testHistory); + $this->history = new History(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); - $this->container['history'] = new \History(self::$testHistory); + $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); + $this->container['history'] = new History(self::$testHistory); $this->controller = new Links($this->container); @@ -119,7 +120,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase ); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); @@ -198,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); $this->assertEquals(false, $data['private']); $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']) ); $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']) ); } diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index e0787ce..84e1d56 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php @@ -3,13 +3,15 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; +use Shaarli\History; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; use Slim\Http\Response; -class DeleteTagTest extends \PHPUnit_Framework_TestCase +class DeleteTagTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -32,12 +34,12 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase protected $refDB = null; /** - * @var \LinkDB instance. + * @var LinkDB instance. */ protected $linkDB; /** - * @var \History instance. + * @var HistoryController instance. */ protected $history; @@ -59,10 +61,10 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->refDB = new \ReferenceLinkDB(); $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->write(self::$testHistory); - $this->history = new \History(self::$testHistory); + $this->history = new History(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = $this->linkDB; @@ -97,18 +99,18 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(204, $response->getStatusCode()); $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(); $this->assertFalse(isset($tags[$tagName])); // 2 links affected $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); $historyEntry = $this->history->getHistory()[1]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); @@ -131,13 +133,13 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(204, $response->getStatusCode()); $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(); $this->assertFalse(isset($tags[$tagName])); $this->assertTrue($tags[strtolower($tagName)] > 0); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index afac228..a2525c1 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -2,8 +2,8 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; - use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -16,7 +16,7 @@ use Slim\Http\Response; * * @package Shaarli\Api\Controllers */ -class GetTagNameTest extends \PHPUnit_Framework_TestCase +class GetTagNameTest extends \PHPUnit\Framework\TestCase { /** * @var string datastore to test write operations @@ -59,7 +59,7 @@ class GetTagNameTest extends \PHPUnit_Framework_TestCase $this->container = new Container(); $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->controller = new Tags($this->container); diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index 3fab31b..98628c9 100644 --- a/tests/api/controllers/tags/GetTagsTest.php +++ b/tests/api/controllers/tags/GetTagsTest.php @@ -1,8 +1,8 @@ container = new Container(); $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['history'] = null; diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 3801724..86106fc 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -1,16 +1,17 @@ write(self::$testHistory); - $this->history = new \History(self::$testHistory); + $this->history = new History(self::$testHistory); $this->container = new Container(); $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['history'] = $this->history; @@ -113,12 +114,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2, $tags[$newName]); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); $historyEntry = $this->history->getHistory()[1]; - $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); diff --git a/tests/LinkDBTest.php b/tests/bookmark/LinkDBTest.php similarity index 95% rename from tests/LinkDBTest.php rename to tests/bookmark/LinkDBTest.php index c763c0c..ff5c0b9 100644 --- a/tests/LinkDBTest.php +++ b/tests/bookmark/LinkDBTest.php @@ -3,9 +3,14 @@ * Link datastore tests */ -require_once 'application/Cache.php'; -require_once 'application/FileUtils.php'; -require_once 'application/LinkDB.php'; +namespace Shaarli\Bookmark; + +use DateTime; +use ReferenceLinkDB; +use ReflectionClass; +use Shaarli; + +require_once 'application/feed/Cache.php'; require_once 'application/Utils.php'; require_once 'tests/utils/ReferenceLinkDB.php'; @@ -13,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php'; /** * Unitary tests for LinkDB */ -class LinkDBTest extends PHPUnit_Framework_TestCase +class LinkDBTest extends \PHPUnit\Framework\TestCase { // datastore to test write operations protected static $testDatastore = 'sandbox/datastore.php'; @@ -73,7 +78,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase */ protected static function getMethod($name) { - $class = new ReflectionClass('LinkDB'); + $class = new ReflectionClass('Shaarli\Bookmark\LinkDB'); $method = $class->getMethod($name); $method->setAccessible(true); return $method; @@ -100,7 +105,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Attempt to instantiate a LinkDB whereas the datastore is not writable * - * @expectedException IOException + * @expectedException Shaarli\Exceptions\IOException * @expectedExceptionMessageRegExp /Error accessing "null"/ */ public function testConstructDatastoreNotWriteable() @@ -187,12 +192,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $link = array( 'id' => 42, - 'title'=>'an additional link', - 'url'=>'http://dum.my', - 'description'=>'One more', - 'private'=>0, - 'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), - 'tags'=>'unit test' + 'title' => 'an additional link', + 'url' => 'http://dum.my', + 'description' => 'One more', + 'private' => 0, + 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), + 'tags' => 'unit test' ); $testDB[$link['id']] = $link; $testDB->save('tests'); @@ -451,7 +456,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Test filterHash() with an invalid smallhash. * - * @expectedException LinkNotFoundException + * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException */ public function testFilterHashInValid1() { @@ -462,7 +467,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Test filterHash() with an empty smallhash. * - * @expectedException LinkNotFoundException + * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException */ public function testFilterHashInValid() { diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php similarity index 96% rename from tests/LinkFilterTest.php rename to tests/bookmark/LinkFilterTest.php index eb54c35..808f812 100644 --- a/tests/LinkFilterTest.php +++ b/tests/bookmark/LinkFilterTest.php @@ -1,11 +1,14 @@ filter( LinkFilter::$FILTER_TAG, - /*$request=*/'', - /*$casesensitive=*/false, - /*$visibility=*/'all', - /*$untaggedonly=*/true + /*$request=*/ + '', + /*$casesensitive=*/ + false, + /*$visibility=*/ + 'all', + /*$untaggedonly=*/ + true ) ) ); @@ -227,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase /** * No link for this hash * - * @expectedException LinkNotFoundException + * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException */ public function testFilterUnknownSmallHash() { diff --git a/tests/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php similarity index 76% rename from tests/LinkUtilsTest.php rename to tests/bookmark/LinkUtilsTest.php index 5407159..1b8688e 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php @@ -1,11 +1,15 @@ stuff'. $title .''; + $html = 'stuff' . $title . ''; $this->assertEquals($title, html_extract_title($html)); - $html = ''. $title .'blablaanother'; + $html = '' . $title . 'blablaanother'; $this->assertEquals($title, html_extract_title($html)); } @@ -34,7 +38,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase public function testHeadersExtractExistentCharset() { $charset = 'x-MacCroatian'; - $headers = 'text/html; charset='. $charset; + $headers = 'text/html; charset=' . $charset; $this->assertEquals(strtolower($charset), header_extract_charset($headers)); } @@ -56,7 +60,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase public function testHtmlExtractExistentCharset() { $charset = 'x-MacCroatian'; - $html = 'stuff2'; + $html = 'stuff2'; $this->assertEquals(strtolower($charset), html_extract_charset($html)); } @@ -84,8 +88,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase 'Content-Type: text/html; charset=utf-8', 'Status: 200 OK', 'end' => 'th=device-width">' - .'Refactoring · GitHub' - .'' - .'Refactoring · GitHub' - .'', 'end' => 'th=device-width">' - .'Refactoring · GitHub' - .'' - .'http://hello.there/is=someone#here otherstuff'; + . 'http://hello.there/is=someone#here otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; $expectedText = 'stuff ' - .'http://hello.there/is=someone#here(please) otherstuff'; + . 'http://hello.there/is=someone#here(please) otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; $expectedText = 'stuff ' - .'http://hello.there/is=someone#here(please)&no otherstuff'; + . 'http://hello.there/is=someone#here(please)&no otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); } @@ -242,7 +246,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase { $text = 'stuff http://hello.there/is=someone#here otherstuff'; $redirector = 'http://redirector.to'; - $expectedText = 'stuff http://hello.there/is=someone#here otherstuff'; @@ -257,7 +261,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase { $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; $redirector = 'http://redirector.to'; - $expectedText = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; @@ -270,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase */ public function testSpace2nbsp() { - $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; - $expectedText = '  Are you   thrilled  by flags   ?'. PHP_EOL .' Really?'; + $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?'; + $expectedText = '  Are you   thrilled  by flags   ?' . PHP_EOL . ' Really?'; $processedText = space2nbsp($text); $this->assertEquals($expectedText, $processedText); } @@ -317,105 +321,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase * Util function to build an hashtag link. * * @param string $hashtag Hashtag name. - * @param string $index Index URL. + * @param string $index Index URL. * * @return string HTML hashtag link. */ private function getHashtagLink($hashtag, $index = '') { - $hashtagLink = '#$1'; + $hashtagLink = '#$1'; 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'; - } -} diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index d237bc8..95ad060 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -4,7 +4,7 @@ namespace Shaarli\Config; /** * Class ConfigJsonTest */ -class ConfigJsonTest extends \PHPUnit_Framework_TestCase +class ConfigJsonTest extends \PHPUnit\Framework\TestCase { /** * @var ConfigJson @@ -111,7 +111,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase /** * Write to invalid path. * - * @expectedException \IOException + * @expectedException \Shaarli\Exceptions\IOException */ public function testWriteInvalidArray() { @@ -122,7 +122,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase /** * Write to invalid path. * - * @expectedException \IOException + * @expectedException \Shaarli\Exceptions\IOException */ public function testWriteInvalidBlank() { diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 4a4e94a..33830bc 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -7,7 +7,7 @@ namespace Shaarli\Config; * Note: it only test the manager with ConfigJson, * 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 diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index be23eea..67d878c 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -4,7 +4,7 @@ namespace Shaarli\Config; /** * Class ConfigPhpTest */ -class ConfigPhpTest extends \PHPUnit_Framework_TestCase +class ConfigPhpTest extends \PHPUnit\Framework\TestCase { /** * @var ConfigPhp diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php index deb02c9..d7a70e6 100644 --- a/tests/config/ConfigPluginTest.php +++ b/tests/config/ConfigPluginTest.php @@ -8,7 +8,7 @@ require_once 'application/config/ConfigPlugin.php'; /** * 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. diff --git a/tests/CacheTest.php b/tests/feed/CacheTest.php similarity index 68% rename from tests/CacheTest.php rename to tests/feed/CacheTest.php index f60fad9..c0a9f26 100644 --- a/tests/CacheTest.php +++ b/tests/feed/CacheTest.php @@ -2,16 +2,17 @@ /** * Cache tests */ +namespace Shaarli\Feed; // required to access $_SESSION array session_start(); -require_once 'application/Cache.php'; +require_once 'application/feed/Cache.php'; /** * Unitary tests for cached pages */ -class CacheTest extends PHPUnit_Framework_TestCase +class CacheTest extends \PHPUnit\Framework\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/dummycache'; @@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase */ public function setUp() { - if (! is_dir(self::$testCacheDir)) { + if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); } else { - array_map('unlink', glob(self::$testCacheDir.'/*')); + array_map('unlink', glob(self::$testCacheDir . '/*')); } foreach (self::$pages as $page) { - file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); + file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page); } - file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); + file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere'); } /** @@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase */ public function tearDown() { - array_map('unlink', glob(self::$testCacheDir.'/*')); + array_map('unlink', glob(self::$testCacheDir . '/*')); rmdir(self::$testCacheDir); } @@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase { purgeCachedPages(self::$testCacheDir); foreach (self::$pages as $page) { - $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache'); } - $this->assertFileExists(self::$testCacheDir.'/intru.der'); + $this->assertFileExists(self::$testCacheDir . '/intru.der'); } /** @@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase ini_set('error_log', '/dev/null'); $this->assertEquals( 'Cannot purge sandbox/dummycache_missing: no directory', - purgeCachedPages(self::$testCacheDir.'_missing') + purgeCachedPages(self::$testCacheDir . '_missing') ); ini_set('error_log', $oldlog); } @@ -83,7 +84,7 @@ class CacheTest extends PHPUnit_Framework_TestCase invalidateCaches(self::$testCacheDir); foreach (self::$pages as $page) { - $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache'); } $this->assertArrayNotHasKey('tags', $_SESSION); diff --git a/tests/CachedPageTest.php b/tests/feed/CachedPageTest.php similarity index 92% rename from tests/CachedPageTest.php rename to tests/feed/CachedPageTest.php index 51565cd..0bcc144 100644 --- a/tests/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -2,13 +2,12 @@ /** * PageCache tests */ - -require_once 'application/CachedPage.php'; +namespace Shaarli\Feed; /** * Unitary tests for cached pages */ -class CachedPageTest extends PHPUnit_Framework_TestCase +class CachedPageTest extends \PHPUnit\Framework\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/pagecache'; @@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase */ public static function setUpBeforeClass() { - if (! is_dir(self::$testCacheDir)) { + if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); } - self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache'; + self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache'; } /** diff --git a/tests/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php similarity index 97% rename from tests/FeedBuilderTest.php rename to tests/feed/FeedBuilderTest.php index 4ca58e5..b496cb4 100644 --- a/tests/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php @@ -1,14 +1,17 @@ assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); - $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); + $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); $this->assertEquals($pub, $up); $this->assertContains('Stallman has a beard', $link['description']); $this->assertContains('Permalink', $link['description']); diff --git a/tests/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php similarity index 89% rename from tests/HttpUtils/ClientIpIdTest.php rename to tests/http/HttpUtils/ClientIpIdTest.php index c15ac5c..982e57e 100644 --- a/tests/HttpUtils/ClientIpIdTest.php +++ b/tests/http/HttpUtils/ClientIpIdTest.php @@ -3,12 +3,14 @@ * HttpUtils' tests */ -require_once 'application/HttpUtils.php'; +namespace Shaarli\Http; + +require_once 'application/http/HttpUtils.php'; /** * 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 diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php similarity index 85% rename from tests/HttpUtils/GetHttpUrlTest.php rename to tests/http/HttpUtils/GetHttpUrlTest.php index ea53de5..3dc5bc9 100644 --- a/tests/HttpUtils/GetHttpUrlTest.php +++ b/tests/http/HttpUtils/GetHttpUrlTest.php @@ -3,12 +3,14 @@ * HttpUtils' tests */ -require_once 'application/HttpUtils.php'; +namespace Shaarli\Http; + +require_once 'application/http/HttpUtils.php'; /** * Unitary tests for get_http_response() */ -class GetHttpUrlTest extends PHPUnit_Framework_TestCase +class GetHttpUrlTest extends \PHPUnit\Framework\TestCase { /** * Get an invalid local URL @@ -17,12 +19,12 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase { // Local 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); // Non HTTP 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); } diff --git a/tests/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php similarity index 91% rename from tests/HttpUtils/GetIpAdressFromProxyTest.php rename to tests/http/HttpUtils/GetIpAdressFromProxyTest.php index 7af5bd9..fe3a639 100644 --- a/tests/HttpUtils/GetIpAdressFromProxyTest.php +++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php @@ -1,11 +1,13 @@ cleanup(); $this->assertEquals(self::$baseUrl, $url->toString()); } @@ -38,7 +38,7 @@ class UrlTest extends PHPUnit_Framework_TestCase public function testConstruct() { $ref = 'http://username:password@hostname:9090/path' - .'?arg1=value1&arg2=value2#anchor'; + . '?arg1=value1&arg2=value2#anchor'; $url = new Url($ref); $this->assertEquals($ref, $url->toString()); } @@ -52,7 +52,7 @@ class UrlTest extends PHPUnit_Framework_TestCase $this->assertUrlIsCleaned(); // URL with no annoying elements - $ref = self::$baseUrl.'?p1=val1&p2=1234#edit'; + $ref = self::$baseUrl . '?p1=val1&p2=1234#edit'; $url = new Url($ref); $this->assertEquals($ref, $url->cleanup()); } @@ -115,26 +115,26 @@ class UrlTest extends PHPUnit_Framework_TestCase // ditch annoying query params and fragment, keep useful params $url = new Url( self::$baseUrl - .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' + . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' ); - $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); + $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup()); // ditch annoying query params, keep useful params and fragment $url = new Url( self::$baseUrl - .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' + . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' ); $this->assertEquals( - self::$baseUrl.'?my=stuff&is=kept#again', + self::$baseUrl . '?my=stuff&is=kept#again', $url->cleanup() ); // test firefox reader url $url = new Url( - 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') + 'about://reader?url=' . urlencode(self::$baseUrl . '?my=stuff&is=kept') ); - $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); + $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup()); } /** diff --git a/tests/Url/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php similarity index 96% rename from tests/Url/CleanupUrlTest.php rename to tests/http/UrlUtils/CleanupUrlTest.php index 2479194..6c4d124 100644 --- a/tests/Url/CleanupUrlTest.php +++ b/tests/http/UrlUtils/CleanupUrlTest.php @@ -3,9 +3,11 @@ * 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 diff --git a/tests/Url/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php similarity index 76% rename from tests/Url/GetUrlSchemeTest.php rename to tests/http/UrlUtils/GetUrlSchemeTest.php index 18b932d..2b97f7b 100644 --- a/tests/Url/GetUrlSchemeTest.php +++ b/tests/http/UrlUtils/GetUrlSchemeTest.php @@ -3,12 +3,14 @@ * 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() { @@ -16,7 +18,7 @@ class GetUrlSchemeTest extends PHPUnit_Framework_TestCase } /** - * Get normal scheme of Url + * Get normal scheme of UrlUtils */ public function testGetUrlScheme() { diff --git a/tests/Url/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php similarity index 76% rename from tests/Url/UnparseUrlTest.php rename to tests/http/UrlUtils/UnparseUrlTest.php index e314b48..040d8c5 100644 --- a/tests/Url/UnparseUrlTest.php +++ b/tests/http/UrlUtils/UnparseUrlTest.php @@ -1,14 +1,16 @@ write(self::$testDatastore); self::$linkDb = new LinkDB(self::$testDatastore, true, false); } diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php similarity index 99% rename from tests/NetscapeBookmarkUtils/BookmarkImportTest.php rename to tests/netscape/BookmarkImportTest.php index f0a958c..ccafc16 100644 --- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php @@ -1,8 +1,10 @@ conf->setConfigFile('tests/utils/config/configPhp'); $this->conf->reset(); - $optionsFile = 'tests/Updater/options.php'; + $optionsFile = 'tests/updater/options.php'; $options = 'conf->setConfigFile('tests/Updater/config'); + $this->conf->setConfigFile('tests/updater/config'); // merge configs $updater = new Updater(array(), array(), $this->conf, true); - // This writes a new config file in tests/Updater/config.php + // This writes a new config file in tests/updater/config.php $updater->updateMethodMergeDeprecatedConfigFile(); // make sure updated field is changed @@ -216,7 +223,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testRenameDashTags() { - $refDB = new ReferenceLinkDB(); + $refDB = new \ReferenceLinkDB(); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); @@ -362,7 +369,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 'private' => true, ), ); - $refDB = new ReferenceLinkDB(); + $refDB = new \ReferenceLinkDB(); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); @@ -426,7 +433,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testDatastoreIdsNothingToDo() { - $refDB = new ReferenceLinkDB(); + $refDB = new \ReferenceLinkDB(); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); @@ -763,7 +770,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 1 => ['id' => 1] + $blank, 2 => ['id' => 2] + $blank, ]; - $refDB = new ReferenceLinkDB(); + $refDB = new \ReferenceLinkDB(); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); @@ -794,7 +801,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; 1 => ['id' => 1, 'sticky' => true] + $blank, 2 => ['id' => 2] + $blank, ]; - $refDB = new ReferenceLinkDB(); + $refDB = new \ReferenceLinkDB(); $refDB->setLinks($links); $refDB->write(self::$testDatastore); $linkDB = new LinkDB(self::$testDatastore, true, false); diff --git a/tests/utils/CurlUtils.php b/tests/utils/CurlUtils.php new file mode 100644 index 0000000..1cc4907 --- /dev/null +++ b/tests/utils/CurlUtils.php @@ -0,0 +1,94 @@ +