]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1248 from virtualtam/refactor/namespacing
authorAurélien Tamisier <virtualtam+github@flibidi.net>
Fri, 18 Jan 2019 20:26:03 +0000 (21:26 +0100)
committerGitHub <noreply@github.com>
Fri, 18 Jan 2019 20:26:03 +0000 (21:26 +0100)
Ensure all PHP classes are properly namespaced

122 files changed:
application/ApplicationUtils.php
application/FileUtils.php
application/History.php
application/Languages.php
application/Router.php
application/Thumbnailer.php
application/api/ApiMiddleware.php
application/api/ApiUtils.php
application/api/controllers/ApiController.php
application/api/controllers/HistoryController.php [moved from application/api/controllers/History.php with 97% similarity]
application/api/controllers/Tags.php
application/api/exceptions/ApiLinkNotFoundException.php
application/api/exceptions/ApiTagNotFoundException.php
application/bookmark/LinkDB.php [moved from application/LinkDB.php with 91% similarity]
application/bookmark/LinkFilter.php [moved from application/LinkFilter.php with 93% similarity]
application/bookmark/LinkUtils.php [moved from application/LinkUtils.php with 97% similarity]
application/bookmark/exception/LinkNotFoundException.php [new file with mode: 0644]
application/config/ConfigJson.php
application/config/ConfigManager.php
application/config/ConfigPhp.php
application/exceptions/IOException.php
application/feed/Cache.php [moved from application/Cache.php with 100% similarity]
application/feed/CachedPage.php [moved from application/CachedPage.php with 93% similarity]
application/feed/FeedBuilder.php [moved from application/FeedBuilder.php with 84% similarity]
application/http/Base64Url.php [moved from application/Base64Url.php with 96% similarity]
application/http/HttpUtils.php [moved from application/HttpUtils.php with 99% similarity]
application/http/Url.php [moved from application/Url.php with 63% similarity]
application/http/UrlUtils.php [new file with mode: 0644]
application/netscape/NetscapeBookmarkUtils.php [moved from application/NetscapeBookmarkUtils.php with 90% similarity]
application/plugin/PluginManager.php [moved from application/PluginManager.php with 87% similarity]
application/plugin/exception/PluginFileNotFoundException.php [new file with mode: 0644]
application/render/PageBuilder.php [moved from application/PageBuilder.php with 92% similarity]
application/render/ThemeUtils.php [moved from application/ThemeUtils.php with 96% similarity]
application/updater/Updater.php [moved from application/Updater.php with 82% similarity]
application/updater/UpdaterUtils.php [new file with mode: 0644]
application/updater/exception/UpdaterException.php [new file with mode: 0644]
composer.json
composer.lock
index.php
plugins/addlink_toolbar/addlink_toolbar.php
plugins/archiveorg/archiveorg.php
plugins/demo_plugin/demo_plugin.php
plugins/isso/isso.php
plugins/markdown/markdown.php
plugins/piwik/piwik.php
plugins/playvideos/playvideos.php
plugins/pubsubhubbub/pubsubhubbub.php
plugins/qrcode/qrcode.php
plugins/wallabag/WallabagInstance.php
plugins/wallabag/wallabag.php
tests/ApplicationUtilsTest.php
tests/FileUtilsTest.php
tests/HistoryTest.php
tests/LanguagesTest.php
tests/PluginManagerTest.php
tests/RouterTest.php
tests/TimeZoneTest.php
tests/UtilsTest.php
tests/api/ApiMiddlewareTest.php
tests/api/ApiUtilsTest.php
tests/api/controllers/history/HistoryTest.php
tests/api/controllers/info/InfoTest.php
tests/api/controllers/links/DeleteLinkTest.php
tests/api/controllers/links/GetLinkIdTest.php
tests/api/controllers/links/GetLinksTest.php
tests/api/controllers/links/PostLinkTest.php
tests/api/controllers/links/PutLinkTest.php
tests/api/controllers/tags/DeleteTagTest.php
tests/api/controllers/tags/GetTagNameTest.php
tests/api/controllers/tags/GetTagsTest.php
tests/api/controllers/tags/PutTagTest.php
tests/bookmark/LinkDBTest.php [moved from tests/LinkDBTest.php with 95% similarity]
tests/bookmark/LinkFilterTest.php [moved from tests/LinkFilterTest.php with 96% similarity]
tests/bookmark/LinkUtilsTest.php [moved from tests/LinkUtilsTest.php with 76% similarity]
tests/config/ConfigJsonTest.php
tests/config/ConfigManagerTest.php
tests/config/ConfigPhpTest.php
tests/config/ConfigPluginTest.php
tests/feed/CacheTest.php [moved from tests/CacheTest.php with 68% similarity]
tests/feed/CachedPageTest.php [moved from tests/CachedPageTest.php with 92% similarity]
tests/feed/FeedBuilderTest.php [moved from tests/FeedBuilderTest.php with 97% similarity]
tests/http/HttpUtils/ClientIpIdTest.php [moved from tests/HttpUtils/ClientIpIdTest.php with 89% similarity]
tests/http/HttpUtils/GetHttpUrlTest.php [moved from tests/HttpUtils/GetHttpUrlTest.php with 85% similarity]
tests/http/HttpUtils/GetIpAdressFromProxyTest.php [moved from tests/HttpUtils/GetIpAdressFromProxyTest.php with 91% similarity]
tests/http/HttpUtils/IndexUrlTest.php [moved from tests/HttpUtils/IndexUrlTest.php with 92% similarity]
tests/http/HttpUtils/IsHttpsTest.php [moved from tests/HttpUtils/IsHttpsTest.php with 89% similarity]
tests/http/HttpUtils/PageUrlTest.php [moved from tests/HttpUtils/PageUrlTest.php with 93% similarity]
tests/http/HttpUtils/ServerUrlTest.php [moved from tests/HttpUtils/ServerUrlTest.php with 97% similarity]
tests/http/UrlTest.php [moved from tests/Url/UrlTest.php with 87% similarity]
tests/http/UrlUtils/CleanupUrlTest.php [moved from tests/Url/CleanupUrlTest.php with 96% similarity]
tests/http/UrlUtils/GetUrlSchemeTest.php [moved from tests/Url/GetUrlSchemeTest.php with 76% similarity]
tests/http/UrlUtils/UnparseUrlTest.php [moved from tests/Url/UnparseUrlTest.php with 76% similarity]
tests/http/UrlUtils/WhitelistProtocolsTest.php [moved from tests/Url/WhitelistProtocolsTest.php with 91% similarity]
tests/languages/fr/LanguagesFrTest.php
tests/netscape/BookmarkExportTest.php [moved from tests/NetscapeBookmarkUtils/BookmarkExportTest.php with 93% similarity]
tests/netscape/BookmarkImportTest.php [moved from tests/NetscapeBookmarkUtils/BookmarkImportTest.php with 99% similarity]
tests/netscape/input/empty.htm [moved from tests/NetscapeBookmarkUtils/input/empty.htm with 100% similarity]
tests/netscape/input/internet_explorer_encoding.htm [moved from tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm with 100% similarity]
tests/netscape/input/lowercase_doctype.htm [moved from tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm with 100% similarity]
tests/netscape/input/netscape_basic.htm [moved from tests/NetscapeBookmarkUtils/input/netscape_basic.htm with 100% similarity]
tests/netscape/input/netscape_nested.htm [moved from tests/NetscapeBookmarkUtils/input/netscape_nested.htm with 100% similarity]
tests/netscape/input/no_doctype.htm [moved from tests/NetscapeBookmarkUtils/input/no_doctype.htm with 100% similarity]
tests/netscape/input/same_date.htm [moved from tests/NetscapeBookmarkUtils/input/same_date.htm with 100% similarity]
tests/plugins/PluginAddlinkTest.php
tests/plugins/PluginArchiveorgTest.php
tests/plugins/PluginIssoTest.php
tests/plugins/PluginMarkdownTest.php
tests/plugins/PluginPlayvideosTest.php
tests/plugins/PluginPubsubhubbubTest.php
tests/plugins/PluginQrcodeTest.php
tests/plugins/PluginWallabagTest.php
tests/plugins/WallabagInstanceTest.php
tests/render/ThemeUtilsTest.php [moved from tests/ThemeUtilsTest.php with 93% similarity]
tests/security/LoginManagerTest.php
tests/security/SessionManagerTest.php
tests/updater/DummyUpdater.php [moved from tests/Updater/DummyUpdater.php with 87% similarity]
tests/updater/UpdaterTest.php [moved from tests/Updater/UpdaterTest.php with 97% similarity]
tests/utils/CurlUtils.php [new file with mode: 0644]
tests/utils/FakeApplicationUtils.php [new file with mode: 0644]
tests/utils/ReferenceHistory.php
tests/utils/ReferenceLinkDB.php
tests/utils/config/configPhp.php

index a3b2dcb18effa309c6d776961913cfe6f1385de0..7fe3cb3245a9791f2a0324a3f6fd3ec377421cfc 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+namespace Shaarli;
+
+use Exception;
+use Shaarli\Config\ConfigManager;
+
 /**
  * Shaarli (application) utilities
  */
@@ -51,7 +56,7 @@ class ApplicationUtils
                 return false;
             }
         } else {
-            if (! is_file($remote)) {
+            if (!is_file($remote)) {
                 return false;
             }
             $data = file_get_contents($remote);
@@ -97,7 +102,7 @@ class ApplicationUtils
         // Do not check versions for visitors
         // Do not check if the user doesn't want to
         // Do not check with dev version
-        if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') {
+        if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') {
             return false;
         }
 
@@ -111,7 +116,7 @@ class ApplicationUtils
             return false;
         }
 
-        if (! in_array($branch, self::$GIT_BRANCHES)) {
+        if (!in_array($branch, self::$GIT_BRANCHES)) {
             throw new Exception(
                 'Invalid branch selected for updates: "' . $branch . '"'
             );
@@ -123,7 +128,7 @@ class ApplicationUtils
             self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE
         );
 
-        if (! $latestVersion) {
+        if (!$latestVersion) {
             // Only update the file's modification date
             file_put_contents($updateFile, $currentVersion);
             return false;
@@ -152,9 +157,9 @@ class ApplicationUtils
         if (version_compare($curVersion, $minVersion) < 0) {
             $msg = t(
                 'Your PHP version is obsolete!'
-                 . ' Shaarli requires at least PHP %s, and thus cannot run.'
-                 . ' Your PHP version has known security vulnerabilities and should be'
-                 . ' updated as soon as possible.'
+                . ' Shaarli requires at least PHP %s, and thus cannot run.'
+                . ' Your PHP version has known security vulnerabilities and should be'
+                . ' updated as soon as possible.'
             );
             throw new Exception(sprintf($msg, $minVersion));
         }
@@ -174,50 +179,50 @@ class ApplicationUtils
 
         // Check script and template directories are readable
         foreach (array(
-            'application',
-            'inc',
-            'plugins',
-            $rainTplDir,
-            $rainTplDir.'/'.$conf->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');
             }
         }
 
index b89ea12bcc26cb7e67b09eaa60f11abf9b0c552a..30560bfc3a929a272a7932c893a7212f5d598da1 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
-require_once 'exceptions/IOException.php';
+namespace Shaarli;
+
+use Shaarli\Exceptions\IOException;
 
 /**
  * Class FileUtils
@@ -44,7 +46,7 @@ class FileUtils
 
         return file_put_contents(
             $file,
-            self::$phpPrefix.base64_encode(gzdeflate(serialize($content))).self::$phpSuffix
+            self::$phpPrefix . base64_encode(gzdeflate(serialize($content))) . self::$phpSuffix
         );
     }
 
@@ -62,7 +64,7 @@ class FileUtils
     {
         // Note that gzinflate is faster than gzuncompress.
         // See: http://www.php.net/manual/en/function.gzdeflate.php#96439
-        if (! is_readable($file)) {
+        if (!is_readable($file)) {
             return $default;
         }
 
index 35ec016a9be27c374dec0e96cbcd0d27e20a119a..a58466528050e2efb4aee4dbccb59f3629e42041 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+namespace Shaarli;
+
+use DateTime;
+use Exception;
 
 /**
  * Class History
@@ -66,7 +70,7 @@ class History
      * History constructor.
      *
      * @param string $historyFilePath History file path.
-     * @param int    $retentionTime   History content rentention time in seconds.
+     * @param int    $retentionTime   History content retention time in seconds.
      *
      * @throws Exception if something goes wrong.
      */
@@ -166,11 +170,11 @@ class History
      */
     protected function check()
     {
-        if (! is_file($this->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]);
index b9c5d0e8c3cbf627a590516d448ab9c85343a4fb..5cda802e0c1faaf57058e0dca653cc713c90c0c3 100644 (file)
@@ -3,7 +3,6 @@
 namespace Shaarli;
 
 use Gettext\GettextTranslator;
-use Gettext\Merge;
 use Gettext\Translations;
 use Gettext\Translator;
 use Gettext\TranslatorInterface;
index beb3165b49e128e1a8cb5f60bbb0427fa3a80b5e..05877acdb6d2bfd88979b16bae18ade4ca737b6e 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace Shaarli;
 
 /**
  * Class Router
@@ -75,43 +76,43 @@ class Router
             return self::$PAGE_LINKLIST;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
+        if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
             return self::$PAGE_LOGIN;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_PICWALL)) {
+        if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) {
             return self::$PAGE_PICWALL;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) {
+        if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
             return self::$PAGE_TAGCLOUD;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_TAGLIST)) {
+        if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) {
             return self::$PAGE_TAGLIST;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) {
+        if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
             return self::$PAGE_OPENSEARCH;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_DAILY)) {
+        if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
             return self::$PAGE_DAILY;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_FEED_ATOM)) {
+        if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) {
             return self::$PAGE_FEED_ATOM;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_FEED_RSS)) {
+        if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) {
             return self::$PAGE_FEED_RSS;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_THUMBS_UPDATE)) {
+        if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) {
             return self::$PAGE_THUMBS_UPDATE;
         }
 
-        if (startsWith($query, 'do='. self::$AJAX_THUMB_UPDATE)) {
+        if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) {
             return self::$AJAX_THUMB_UPDATE;
         }
 
@@ -120,23 +121,23 @@ class Router
             return self::$PAGE_LINKLIST;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_TOOLS)) {
+        if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) {
             return self::$PAGE_TOOLS;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
+        if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
             return self::$PAGE_CHANGEPASSWORD;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) {
+        if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) {
             return self::$PAGE_CONFIGURE;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) {
+        if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) {
             return self::$PAGE_CHANGETAG;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) {
+        if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) {
             return self::$PAGE_ADDLINK;
         }
 
@@ -148,27 +149,27 @@ class Router
             return self::$PAGE_DELETELINK;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_PINLINK)) {
+        if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
             return self::$PAGE_PINLINK;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
+        if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) {
             return self::$PAGE_EXPORT;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_IMPORT)) {
+        if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) {
             return self::$PAGE_IMPORT;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) {
+        if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) {
             return self::$PAGE_PLUGINSADMIN;
         }
 
-        if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) {
+        if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) {
             return self::$PAGE_SAVE_PLUGINSADMIN;
         }
 
-        if (startsWith($query, 'do='. self::$GET_TOKEN)) {
+        if (startsWith($query, 'do=' . self::$GET_TOKEN)) {
             return self::$GET_TOKEN;
         }
 
index 37ed97a18bf521f6b6e66b0bc4e32a5083a8f01d..a23f98e9df226204efeb5166bc5e3bbab4f348c9 100644 (file)
@@ -3,9 +3,9 @@
 namespace Shaarli;
 
 use Shaarli\Config\ConfigManager;
+use WebThumbnailer\Application\ConfigManager as WTConfigManager;
 use WebThumbnailer\Exception\WebThumbnailerException;
 use WebThumbnailer\WebThumbnailer;
-use WebThumbnailer\Application\ConfigManager as WTConfigManager;
 
 /**
  * Class Thumbnailer
index 66eac133649cf8c020c64164f7864b43ddf33a40..5ffb8c6d06653fc527df1caca85d58004d41def8 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 namespace Shaarli\Api;
 
-use Shaarli\Api\Exceptions\ApiException;
 use Shaarli\Api\Exceptions\ApiAuthorizationException;
-
+use Shaarli\Api\Exceptions\ApiException;
 use Shaarli\Config\ConfigManager;
 use Slim\Container;
 use Slim\Http\Request;
@@ -127,7 +126,7 @@ class ApiMiddleware
      */
     protected function setLinkDb($conf)
     {
-        $linkDb = new \LinkDB(
+        $linkDb = new \Shaarli\Bookmark\LinkDB(
             $conf->get('resource.datastore'),
             true,
             $conf->get('privacy.hide_public_links'),
index fc5ecaf1e75931d3a2006dae957be7129bb7df1e..1824b5d08171f19c27ebb28d3831eacbfc040538 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace Shaarli\Api;
 
-use Shaarli\Base64Url;
 use Shaarli\Api\Exceptions\ApiAuthorizationException;
+use Shaarli\Http\Base64Url;
 
 /**
  * REST API utilities
@@ -12,7 +12,7 @@ class ApiUtils
     /**
      * Validates a JWT token authenticity.
      *
-     * @param string $token JWT token extracted from the headers.
+     * @param string $token  JWT token extracted from the headers.
      * @param string $secret API secret set in the settings.
      *
      * @throws ApiAuthorizationException the token is not valid.
@@ -50,7 +50,7 @@ class ApiUtils
     /**
      * Format a Link for the REST API.
      *
-     * @param array $link Link data read from the datastore.
+     * @param array  $link     Link data read from the datastore.
      * @param string $indexUrl Shaarli's index URL (used for relative URL).
      *
      * @return array Link data formatted for the REST API.
index 9edefcf627f1f4fe7026f07f7e438bdd3d68080e..a6e7cbab23565007a71f85ac2338f54a930bae6f 100644 (file)
@@ -2,8 +2,9 @@
 
 namespace Shaarli\Api\Controllers;
 
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
-use \Slim\Container;
+use Slim\Container;
 
 /**
  * Abstract Class ApiController
@@ -25,12 +26,12 @@ abstract class ApiController
     protected $conf;
 
     /**
-     * @var \LinkDB
+     * @var LinkDB
      */
     protected $linkDb;
 
     /**
-     * @var \History
+     * @var HistoryController
      */
     protected $history;
 
similarity index 97%
rename from application/api/controllers/History.php
rename to application/api/controllers/HistoryController.php
index 4582e8b27f8597a1a03c482161c58a1febf7706d..9afcfa264430cd7af5910357bfcd07fbea797301 100644 (file)
@@ -14,7 +14,7 @@ use Slim\Http\Response;
  *
  * @package Shaarli\Api\Controllers
  */
-class History extends ApiController
+class HistoryController extends ApiController
 {
     /**
      * Service providing operation regarding Shaarli datastore and settings.
index 6dd78750f37240e21fc437f1a410a171cd1020cf..82f3ef746dde8cd88ead34ac02c02f0b037e696e 100644 (file)
@@ -4,7 +4,6 @@ namespace Shaarli\Api\Controllers;
 
 use Shaarli\Api\ApiUtils;
 use Shaarli\Api\Exceptions\ApiBadParametersException;
-use Shaarli\Api\Exceptions\ApiLinkNotFoundException;
 use Shaarli\Api\Exceptions\ApiTagNotFoundException;
 use Slim\Http\Request;
 use Slim\Http\Response;
index c727f4f0c9eec47e2fad40849b1fb418ef4b9adf..7c2bb56ed781b3a2b76e0a66b688b384e706ee2c 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace Shaarli\Api\Exceptions;
 
-use Slim\Http\Response;
-
 /**
  * Class ApiLinkNotFoundException
  *
index eee152fe273375d3b5bd765f198552e363e21ee8..66ace8bfa51c5ea8906f57fb8bd9c905e143f84b 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace Shaarli\Api\Exceptions;
 
-use Slim\Http\Response;
-
 /**
  * Class ApiTagNotFoundException
  *
similarity index 91%
rename from application/LinkDB.php
rename to application/bookmark/LinkDB.php
index 4bbc2950e223ab86817cd8fa63c74a866bc7db03..c13a11417b5fb66af9a7df5597ad2f2a09298936 100644 (file)
@@ -1,4 +1,15 @@
 <?php
+
+namespace Shaarli\Bookmark;
+
+use ArrayAccess;
+use Countable;
+use DateTime;
+use Iterator;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
+use Shaarli\Exceptions\IOException;
+use Shaarli\FileUtils;
+
 /**
  * Data storage for links.
  *
@@ -108,6 +119,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess
         $redirector = '',
         $redirectorEncode = true
     ) {
+    
         $this->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
      */
similarity index 93%
rename from application/LinkFilter.php
rename to application/bookmark/LinkFilter.php
index 8f147974e9d5cf232f3cf3f509b3401fcf5e6b84..9b96630737008cb2075886e339b85d6b2bbeb109 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+namespace Shaarli\Bookmark;
+
+use Exception;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
+
 /**
  * Class LinkFilter.
  *
@@ -10,22 +15,22 @@ class LinkFilter
     /**
      * @var string permalinks.
      */
-    public static $FILTER_HASH   = 'permalink';
+    public static $FILTER_HASH = 'permalink';
 
     /**
      * @var string text search.
      */
-    public static $FILTER_TEXT   = 'fulltext';
+    public static $FILTER_TEXT = 'fulltext';
 
     /**
      * @var string tag filter.
      */
-    public static $FILTER_TAG    = 'tags';
+    public static $FILTER_TAG = 'tags';
 
     /**
      * @var string filter by day.
      */
-    public static $FILTER_DAY    = 'FILTER_DAY';
+    public static $FILTER_DAY = 'FILTER_DAY';
 
     /**
      * @var string Allowed characters for hashtags (regex syntax).
@@ -58,7 +63,7 @@ class LinkFilter
      */
     public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
     {
-        if (! in_array($visibility, ['all', 'public', 'private'])) {
+        if (!in_array($visibility, ['all', 'public', 'private'])) {
             $visibility = 'all';
         }
 
@@ -117,7 +122,7 @@ class LinkFilter
         foreach ($this->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.');
-    }
-}
similarity index 97%
rename from application/LinkUtils.php
rename to application/bookmark/LinkUtils.php
index d56e019f4246f40d94f7a2eb5b8f715d10c7f1a1..de5b61cbcaf6e8467d57eb9c49aa009d0a832754 100644 (file)
@@ -1,11 +1,13 @@
 <?php
 
+use Shaarli\Bookmark\LinkDB;
+
 /**
  * Get cURL callback function for CURLOPT_WRITEFUNCTION
  *
  * @param string $charset     to extract from the downloaded page (reference)
  * @param string $title       to extract from the downloaded page (reference)
- * @param string $curlGetInfo Optionnaly overrides curl_getinfo function
+ * @param string $curlGetInfo Optionally overrides curl_getinfo function
  *
  * @return Closure
  */
@@ -196,7 +198,7 @@ function space2nbsp($text)
  *
  * @param string $description shaare's description.
  * @param string $redirector  if a redirector is set, use it to gerenate links.
- * @param bool   $urlEncode  Use `urlencode()` on the URL after the redirector or not.
+ * @param bool   $urlEncode   Use `urlencode()` on the URL after the redirector or not.
  * @param string $indexUrl    URL to Shaarli's index.
 
  * @return string formatted description.
diff --git a/application/bookmark/exception/LinkNotFoundException.php b/application/bookmark/exception/LinkNotFoundException.php
new file mode 100644 (file)
index 0000000..f941442
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace Shaarli\Bookmark\Exception;
+
+use Exception;
+
+class LinkNotFoundException extends Exception
+{
+    /**
+     * LinkNotFoundException constructor.
+     */
+    public function __construct()
+    {
+        $this->message = t('The link you are trying to reach does not exist or has been deleted.');
+    }
+}
index 8c8d5610efb145c49c3b319514f7e3ba0dab68ca..4509357ce887ea8a28334a68c50f999294780243 100644 (file)
@@ -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.')
index 32aaea48e870ab13af7714c5a53d84cf0356d613..e6c3507329dc7e39a162c6fc4ec1103da8fadff2 100644 (file)
@@ -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)
     {
index 9625fe1a98156397b0210b80cf95bce8dd3a7821..cad3459462b2f396039ddd8c085794fe555114be 100644 (file)
@@ -27,7 +27,7 @@ class ConfigPhp implements ConfigIO
     /**
      * Map legacy config keys with the new ones.
      * If ConfigPhp is used, getting <newkey> will actually look for <legacykey>.
-     * The Updater will use this array to transform keys when switching to JSON.
+     * The updater will use this array to transform keys when switching to JSON.
      *
      * @var array current key => legacy key.
      */
@@ -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.')
index 18e46b77a2291999eb9b3ee8656de4c4cb17efe6..2aa25e5c55be709b4dfeb2c8c1451ef437597a40 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+namespace Shaarli\Exceptions;
+
+use Exception;
 
 /**
  * Exception class thrown when a filesystem access failure happens
@@ -17,6 +20,6 @@ class IOException extends Exception
     {
         $this->path = $path;
         $this->message = empty($message) ? t('Error accessing') : $message;
-        $this->message .= ' "' . $this->path .'"';
+        $this->message .= ' "' . $this->path . '"';
     }
 }
similarity index 93%
rename from application/CachedPage.php
rename to application/feed/CachedPage.php
index e11cc52d01e3aeac07142c476d76e35bf7b88229..d809bdd962ca901c54536309d17068652ff5f3bd 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+namespace Shaarli\Feed;
+
 /**
  * Simple cache system, mainly for the RSS/ATOM feeds
  */
@@ -24,7 +27,7 @@ class CachedPage
     {
         // TODO: check write access to the cache directory
         $this->cacheDir = $cacheDir;
-        $this->filename = $this->cacheDir.'/'.sha1($url).'.cache';
+        $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache';
         $this->shouldBeCached = $shouldBeCached;
     }
 
similarity index 84%
rename from application/FeedBuilder.php
rename to application/feed/FeedBuilder.php
index 73fafcbed31cb733ac0bf99611313d861a1b60a0..b66f2f918edd494f1d11090892fbcfda7d073e59 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+namespace Shaarli\Feed;
+
+use DateTime;
 
 /**
  * FeedBuilder class.
@@ -28,7 +31,7 @@ class FeedBuilder
     public static $DEFAULT_NB_LINKS = 50;
 
     /**
-     * @var LinkDB instance.
+     * @var \Shaarli\Bookmark\LinkDB instance.
      */
     protected $linkDB;
 
@@ -38,12 +41,12 @@ class FeedBuilder
     protected $feedType;
 
     /**
-     * @var array $_SERVER.
+     * @var array $_SERVER
      */
     protected $serverInfo;
 
     /**
-     * @var array $_GET.
+     * @var array $_GET
      */
     protected $userInput;
 
@@ -75,11 +78,12 @@ class FeedBuilder
     /**
      * Feed constructor.
      *
-     * @param LinkDB  $linkDB        LinkDB instance.
-     * @param string  $feedType      Type of feed.
-     * @param array   $serverInfo    $_SERVER.
-     * @param array   $userInput     $_GET.
-     * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise.
+     * @param \Shaarli\Bookmark\LinkDB $linkDB     LinkDB instance.
+     * @param string                   $feedType   Type of feed.
+     * @param array                    $serverInfo $_SERVER.
+     * @param array                    $userInput  $_GET.
+     * @param boolean                  $isLoggedIn True if the user is currently logged in,
+     *                                             false otherwise.
      */
     public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn)
     {
@@ -124,7 +128,7 @@ class FeedBuilder
         $data['show_dates'] = !$this->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 = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>';
+            $permalink = '<a href="' . $link['url'] . '" title="' . t('Direct link') . '">' . t('Direct link') . '</a>';
         } else {
-            $permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>';
+            $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
         }
-        $link['description']  = format_description($link['description'], '', false, $pageaddr);
-        $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink;
+        $link['description'] = format_description($link['description'], '', false, $pageaddr);
+        $link['description'] .= PHP_EOL . '<br>&#8212; ' . $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;
         }
 
similarity index 96%
rename from application/Base64Url.php
rename to application/http/Base64Url.php
index 54d0fcd52accef3639e94fde87d52b5b32678399..33fa7c1f8c8f3be693a4cbed58bf293be8277ae1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Shaarli;
+namespace Shaarli\Http;
 
 /**
  * URL-safe Base64 operations
similarity index 99%
rename from application/HttpUtils.php
rename to application/http/HttpUtils.php
index 9c438160dccdbe022d1f5398b41f27162774643f..2ea9195d3550bfd4bfd912ef35cb4b669a5c83c2 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use Shaarli\Http\Url;
+
 /**
  * GET an HTTP URL to retrieve its content
  * Uses the cURL library or a fallback method
@@ -38,7 +41,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF
     $cleanUrl = $urlObj->idnToAscii();
 
     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 =
similarity index 63%
rename from application/Url.php
rename to application/http/Url.php
index 3b7f19c207770679d2fff77a709210529ffa2afa..90444a2f4beaf0ad15df3be06ff36d4431d61811 100644 (file)
@@ -1,91 +1,6 @@
 <?php
-/**
- * Converts an array-represented URL to a string
- *
- * Source: http://php.net/manual/en/function.parse-url.php#106731
- *
- * @see http://php.net/manual/en/function.parse-url.php
- *
- * @param array $parsedUrl an array-represented URL
- *
- * @return string the string representation of the URL
- */
-function unparse_url($parsedUrl)
-{
-    $scheme   = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
-    $host     = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
-    $port     = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
-    $user     = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
-    $pass     = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass']  : '';
-    $pass     = ($user || $pass) ? "$pass@" : '';
-    $path     = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
-    $query    = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
-    $fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
 
-    return "$scheme$user$pass$host$port$path$query$fragment";
-}
-
-/**
- * Removes undesired query parameters and fragments
- *
- * @param string url Url to be cleaned
- *
- * @return string the string representation of this URL after cleanup
- */
-function cleanup_url($url)
-{
-    $obj_url = new Url($url);
-    return $obj_url->cleanup();
-}
-
-/**
- * Get URL scheme.
- *
- * @param string url Url for which the scheme is requested
- *
- * @return mixed the URL scheme or false if none is provided.
- */
-function get_url_scheme($url)
-{
-    $obj_url = new Url($url);
-    return $obj_url->getScheme();
-}
-
-/**
- * Adds a trailing slash at the end of URL if necessary.
- *
- * @param string $url URL to check/edit.
- *
- * @return string $url URL with a end trailing slash.
- */
-function add_trailing_slash($url)
-{
-    return $url . (!endsWith($url, '/') ? '/' : '');
-}
-
-/**
- * Replace not whitelisted protocols by 'http://' from given URL.
- *
- * @param string $url       URL to clean
- * @param array  $protocols List of allowed protocols (aside from http(s)).
- *
- * @return string URL with allowed protocol
- */
-function whitelist_protocols($url, $protocols)
-{
-    if (startsWith($url, '?') || startsWith($url, '/')) {
-        return $url;
-    }
-    $protocols = array_merge(['http', 'https'], $protocols);
-    $protocol = preg_match('#^(\w+):/?/?#', $url, $match);
-    // Protocol not allowed: we remove it and replace it with http
-    if ($protocol === 1 && ! in_array($match[1], $protocols)) {
-        $url = str_replace($match[0], 'http://', $url);
-    } elseif ($protocol !== 1) {
-        $url = 'http://' . $url;
-    }
-    return $url;
-}
+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 (file)
index 0000000..4bc84b8
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Converts an array-represented URL to a string
+ *
+ * Source: http://php.net/manual/en/function.parse-url.php#106731
+ *
+ * @see http://php.net/manual/en/function.parse-url.php
+ *
+ * @param array $parsedUrl an array-represented URL
+ *
+ * @return string the string representation of the URL
+ */
+function unparse_url($parsedUrl)
+{
+    $scheme   = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
+    $host     = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
+    $port     = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
+    $user     = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
+    $pass     = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass']  : '';
+    $pass     = ($user || $pass) ? "$pass@" : '';
+    $path     = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
+    $query    = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
+    $fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
+
+    return "$scheme$user$pass$host$port$path$query$fragment";
+}
+
+/**
+ * Removes undesired query parameters and fragments
+ *
+ * @param string url UrlUtils to be cleaned
+ *
+ * @return string the string representation of this URL after cleanup
+ */
+function cleanup_url($url)
+{
+    $obj_url = new \Shaarli\Http\Url($url);
+    return $obj_url->cleanup();
+}
+
+/**
+ * Get URL scheme.
+ *
+ * @param string url UrlUtils for which the scheme is requested
+ *
+ * @return mixed the URL scheme or false if none is provided.
+ */
+function get_url_scheme($url)
+{
+    $obj_url = new \Shaarli\Http\Url($url);
+    return $obj_url->getScheme();
+}
+
+/**
+ * Adds a trailing slash at the end of URL if necessary.
+ *
+ * @param string $url URL to check/edit.
+ *
+ * @return string $url URL with a end trailing slash.
+ */
+function add_trailing_slash($url)
+{
+    return $url . (!endsWith($url, '/') ? '/' : '');
+}
+
+/**
+ * Replace not whitelisted protocols by 'http://' from given URL.
+ *
+ * @param string $url       URL to clean
+ * @param array  $protocols List of allowed protocols (aside from http(s)).
+ *
+ * @return string URL with allowed protocol
+ */
+function whitelist_protocols($url, $protocols)
+{
+    if (startsWith($url, '?') || startsWith($url, '/')) {
+        return $url;
+    }
+    $protocols = array_merge(['http', 'https'], $protocols);
+    $protocol = preg_match('#^(\w+):/?/?#', $url, $match);
+    // Protocol not allowed: we remove it and replace it with http
+    if ($protocol === 1 && ! in_array($match[1], $protocols)) {
+        $url = str_replace($match[0], 'http://', $url);
+    } elseif ($protocol !== 1) {
+        $url = 'http://' . $url;
+    }
+    return $url;
+}
similarity index 90%
rename from application/NetscapeBookmarkUtils.php
rename to application/netscape/NetscapeBookmarkUtils.php
index 84dd2b2083e36f8d20755fbdb2d97502c83b15cd..2fb1a4a6943674c557188e28bb5df206867f3857 100644 (file)
@@ -1,9 +1,16 @@
 <?php
 
+namespace Shaarli\Netscape;
+
+use DateTime;
+use DateTimeZone;
+use Exception;
+use Katzgrau\KLogger\Logger;
 use Psr\Log\LogLevel;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
-use Katzgrau\KLogger\Logger;
 
 /**
  * Utilities to import and export bookmarks using the Netscape format
@@ -31,8 +38,8 @@ class NetscapeBookmarkUtils
     public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl)
     {
         // see tpl/export.html for possible values
-        if (! in_array($selection, array('all', 'public', 'private'))) {
-            throw new Exception(t('Invalid export selection:') .' "'.$selection.'"');
+        if (!in_array($selection, array('all', 'public', 'private'))) {
+            throw new Exception(t('Invalid export selection:') . ' "' . $selection . '"');
         }
 
         $bookmarkLinks = array();
@@ -84,7 +91,7 @@ class NetscapeBookmarkUtils
             $status .= vsprintf(
                 t(
                     'was successfully processed in %d seconds: '
-                    .'%d links imported, %d links overwritten, %d links skipped.'
+                    . '%d links imported, %d links overwritten, %d links skipped.'
                 ),
                 [$duration, $importCount, $overwriteCount, $skipCount]
             );
@@ -95,11 +102,11 @@ class NetscapeBookmarkUtils
     /**
      * Imports Web bookmarks from an uploaded Netscape bookmark dump
      *
-     * @param array         $post      Server $_POST parameters
-     * @param array         $files     Server $_FILES parameters
-     * @param LinkDB        $linkDb    Loaded LinkDB instance
-     * @param ConfigManager $conf      instance
-     * @param History       $history   History instance
+     * @param array         $post    Server $_POST parameters
+     * @param array         $files   Server $_FILES parameters
+     * @param LinkDB        $linkDb  Loaded LinkDB instance
+     * @param ConfigManager $conf    instance
+     * @param History       $history History instance
      *
      * @return string Summary of the bookmark import status
      */
@@ -115,7 +122,7 @@ class NetscapeBookmarkUtils
         }
 
         // Overwrite existing links?
-        $overwrite = ! empty($post['overwrite']);
+        $overwrite = !empty($post['overwrite']);
 
         // Add tags to all imported links?
         if (empty($post['default_tags'])) {
@@ -138,7 +145,7 @@ class NetscapeBookmarkUtils
         );
         $logger = new Logger(
             $conf->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();
similarity index 87%
rename from application/PluginManager.php
rename to application/plugin/PluginManager.php
index 1ed4db4b30c09448227d028caf484a699bb0265a..f7b24a8e88c979031873ee1a8a59fe88503c4bf5 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+namespace Shaarli\Plugin;
+
+use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\Exception\PluginFileNotFoundException;
 
 /**
  * Class PluginManager
@@ -9,12 +13,14 @@ class PluginManager
 {
     /**
      * List of authorized plugins from configuration file.
+     *
      * @var array $authorizedPlugins
      */
     private $authorizedPlugins;
 
     /**
      * List of loaded plugins.
+     *
      * @var array $loadedPlugins
      */
     private $loadedPlugins = array();
@@ -31,12 +37,14 @@ class PluginManager
 
     /**
      * Plugins subdirectory.
+     *
      * @var string $PLUGINS_PATH
      */
     public static $PLUGINS_PATH = 'plugins';
 
     /**
      * Plugins meta files extension.
+     *
      * @var string $META_EXT
      */
     public static $META_EXT = 'meta';
@@ -84,9 +92,9 @@ class PluginManager
     /**
      * Execute all plugins registered hook.
      *
-     * @param string        $hook   name of the hook to trigger.
-     * @param array         $data   list of data to manipulate passed by reference.
-     * @param array         $params additional parameters such as page target.
+     * @param string $hook   name of the hook to trigger.
+     * @param array  $data   list of data to manipulate passed by reference.
+     * @param array  $params additional parameters such as page target.
      *
      * @return void
      */
@@ -118,7 +126,7 @@ class PluginManager
      * @param string $pluginName plugin's name.
      *
      * @return void
-     * @throws PluginFileNotFoundException - plugin files not found.
+     * @throws \Shaarli\Plugin\Exception\PluginFileNotFoundException - plugin files not found.
      */
     private function loadPlugin($dir, $pluginName)
     {
@@ -204,8 +212,8 @@ class PluginManager
 
                 $metaData[$plugin]['parameters'][$param]['value'] = '';
                 // Optional parameter description in parameter.PARAM_NAME=
-                if (isset($metaData[$plugin]['parameter.'. $param])) {
-                    $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.'. $param]);
+                if (isset($metaData[$plugin]['parameter.' . $param])) {
+                    $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.' . $param]);
                 }
             }
         }
@@ -223,22 +231,3 @@ class PluginManager
         return $this->errors;
     }
 }
-
-/**
- * Class PluginFileNotFoundException
- *
- * Raise when plugin files can't be found.
- */
-class PluginFileNotFoundException extends Exception
-{
-    /**
-     * Construct exception with plugin name.
-     * Generate message.
-     *
-     * @param string $pluginName name of the plugin not found
-     */
-    public function __construct($pluginName)
-    {
-        $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
-    }
-}
diff --git a/application/plugin/exception/PluginFileNotFoundException.php b/application/plugin/exception/PluginFileNotFoundException.php
new file mode 100644 (file)
index 0000000..e5386f0
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+namespace Shaarli\Plugin\Exception;
+
+use Exception;
+
+/**
+ * Class PluginFileNotFoundException
+ *
+ * Raise when plugin files can't be found.
+ */
+class PluginFileNotFoundException extends Exception
+{
+    /**
+     * Construct exception with plugin name.
+     * Generate message.
+     *
+     * @param string $pluginName name of the plugin not found
+     */
+    public function __construct($pluginName)
+    {
+        $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
+    }
+}
similarity index 92%
rename from application/PageBuilder.php
rename to application/render/PageBuilder.php
index 2ca95832c60eef3c234b85c3d7a102af1cf7eafa..0569b67f93e4ded88780e1d52ee2c22a4e2054e1 100644 (file)
@@ -1,5 +1,11 @@
 <?php
 
+namespace Shaarli\Render;
+
+use Exception;
+use RainTPL;
+use Shaarli\ApplicationUtils;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Thumbnailer;
 
@@ -37,7 +43,9 @@ class PageBuilder
      */
     protected $token;
 
-    /** @var bool $isLoggedIn Whether the user is logged in **/
+    /**
+     * @var bool $isLoggedIn Whether the user is logged in
+     */
     protected $isLoggedIn = false;
 
     /**
@@ -101,7 +109,7 @@ class PageBuilder
             ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->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');
     }
similarity index 96%
rename from application/ThemeUtils.php
rename to application/render/ThemeUtils.php
index 16f2f6a2742c701f79d671bcf4d89359584fc4d9..86096c64476bf655626633efb692b0a9b352eacc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Shaarli;
+namespace Shaarli\Render;
 
 /**
  * Class ThemeUtils
similarity index 82%
rename from application/Updater.php
rename to application/updater/Updater.php
index 6b94c5e34af485e8327628206cb9c19aa6c6f7f7..f12e351673640ddff963981d1232543a4f17979a 100644 (file)
@@ -1,11 +1,24 @@
 <?php
+
+namespace Shaarli\Updater;
+
+use Exception;
+use RainTPL;
+use ReflectionClass;
+use ReflectionException;
+use ReflectionMethod;
+use Shaarli\ApplicationUtils;
+use Shaarli\Bookmark\LinkDB;
+use Shaarli\Bookmark\LinkFilter;
 use Shaarli\Config\ConfigJson;
-use Shaarli\Config\ConfigPhp;
 use Shaarli\Config\ConfigManager;
+use Shaarli\Config\ConfigPhp;
+use Shaarli\Exceptions\IOException;
 use Shaarli\Thumbnailer;
+use Shaarli\Updater\Exception\UpdaterException;
 
 /**
- * Class Updater.
+ * Class updater.
  * Used to update stuff when a new Shaarli's version is reached.
  * Update methods are ran only once, and the stored in a JSON file.
  */
@@ -83,12 +96,12 @@ class Updater
         }
 
         if ($this->methods === null) {
-            throw new UpdaterException(t('Couldn\'t retrieve Updater class methods.'));
+            throw new UpdaterException(t('Couldn\'t retrieve updater class methods.'));
         }
 
         foreach ($this->methods as $method) {
             // 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 (file)
index 0000000..34d4f42
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Read the updates file, and return already done updates.
+ *
+ * @param string $updatesFilepath Updates file path.
+ *
+ * @return array Already done update methods.
+ */
+function read_updates_file($updatesFilepath)
+{
+    if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
+        $content = file_get_contents($updatesFilepath);
+        if (! empty($content)) {
+            return explode(';', $content);
+        }
+    }
+    return array();
+}
+
+/**
+ * Write updates file.
+ *
+ * @param string $updatesFilepath Updates file path.
+ * @param array  $updates         Updates array to write.
+ *
+ * @throws Exception Couldn't write version number.
+ */
+function write_updates_file($updatesFilepath, $updates)
+{
+    if (empty($updatesFilepath)) {
+        throw new Exception(t('Updates file path is not set, can\'t write updates.'));
+    }
+
+    $res = file_put_contents($updatesFilepath, implode(';', $updates));
+    if ($res === false) {
+        throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
+    }
+}
diff --git a/application/updater/exception/UpdaterException.php b/application/updater/exception/UpdaterException.php
new file mode 100644 (file)
index 0000000..20acecc
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace Shaarli\Updater\Exception;
+
+use Exception;
+
+/**
+ * Class UpdaterException.
+ */
+class UpdaterException extends Exception
+{
+    /**
+     * @var string Method where the error occurred.
+     */
+    protected $method;
+
+    /**
+     * @var Exception The parent exception.
+     */
+    protected $previous;
+
+    /**
+     * Constructor.
+     *
+     * @param string         $message  Force the error message if set.
+     * @param string         $method   Method where the error occurred.
+     * @param Exception|bool $previous Parent exception.
+     */
+    public function __construct($message = '', $method = '', $previous = false)
+    {
+        $this->method = $method;
+        $this->previous = $previous;
+        $this->message = $this->buildMessage($message);
+    }
+
+    /**
+     * Build the exception error message.
+     *
+     * @param string $message Optional given error message.
+     *
+     * @return string The built error message.
+     */
+    private function buildMessage($message)
+    {
+        $out = '';
+        if (!empty($message)) {
+            $out .= $message . PHP_EOL;
+        }
+
+        if (!empty($this->method)) {
+            $out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
+        }
+
+        if (!empty($this->previous)) {
+            $out .= '  ' . $this->previous->getMessage();
+        }
+
+        return $out;
+    }
+}
index dccf83b62b5862371b1447ea9d0fbc571721337b..a52b5f78ed24817e873ffba40d4693ad631f8da2 100644 (file)
@@ -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",
         "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"
         }
     }
 }
index c43dad6f18c9a1e459c502960463ba458d9fbd2b..53fb2175e8149b3989dd6068b348952e39111592 100644 (file)
@@ -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",
         },
         {
             "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": {
                 "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": {
                 "translations",
                 "unicode"
             ],
-            "time": "2018-06-21T15:58:36+00:00"
+            "time": "2018-11-13T22:06:07+00:00"
         },
         {
             "name": "katzgrau/klogger",
         },
         {
             "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": {
                 "psr",
                 "psr-3"
             ],
-            "time": "2016-10-10T12:19:37+00:00"
+            "time": "2018-11-20T15:27:04+00:00"
         },
         {
             "name": "pubsubhubbub/publisher",
         },
         {
             "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": {
                 "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": {
             ],
             "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": {
             ],
             "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": {
             ],
             "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",
         },
         {
             "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": {
                 "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": {
             ],
             "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",
         },
         {
             "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",
                 "check",
                 "validate"
             ],
-            "time": "2018-01-29T19:49:41+00:00"
+            "time": "2018-12-25T11:19:39+00:00"
         }
     ],
     "aliases": [],
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
-        "php": ">=5.6"
+        "php": ">=5.6",
+        "ext-json": "*",
+        "ext-zlib": "*"
     },
     "platform-dev": [],
     "platform-overrides": {
index acfcc660bad686182b9f4fe1294b39a51152de87..633ab89e6386e90eaa02f76d5a1880cb9366dccb 100644 (file)
--- 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 {
index 8c05a23176ba960f8efaf61f5194a679bb1f7f36..8bf4ed46d6cd5afded8fd8d551361b0e93bcef76 100644 (file)
@@ -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.
  *
index 5dcea5a647930b43d6226fc8033f9e51408db67c..0ee1c73c9333ef0fd9635db3ededbc64fb44521e 100644 (file)
@@ -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.
  *
index ca520d15147ce937302eb99d0a15c38c1721e2fb..95ea7fe2d029767f16c000d1672e9aa0bacf4cd4 100644 (file)
@@ -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.
index 378c11af3bfb526b57e22e76c88aa06f4408c2bd..dab75dd55c5c0b06789da06e688664ef97256b54 100644 (file)
@@ -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.
index 8823af91c77d816a015136227eb8859b4c0cef5b..628970d626ff4064b0daecc0b97fd40c855d3551 100644 (file)
@@ -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.
index ca00c2be71f33dd566be43fb2fb2f791d41e26cf..17b1aeccf9926a2a908350ce9a3c448f285f641d 100644 (file)
@@ -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.
index c6d6b0cc6815e4f5c2547efdc395a67ccde08e3d..0341ed593abd19cb0afb5db4a092e4bb34944dd6 100644 (file)
@@ -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.
  *
index 9f0342a37fa376b20cdab8dac2a655c0c178ea5b..2878c0505be296b486ab2b9ee4547a2851c7986b 100644 (file)
@@ -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.
index 4b59caa03e61db70ebeef68a4626c751ae034bb8..34eef8be3fe88ca23c0f00cdeaa9c444795075be 100644 (file)
@@ -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.
  *
index eb8ab618f14f72a768b5851d4e804f1b5f0c2974..f4a0a92bdb8148a180fe169cfc2d2316d2cf1fd3 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace Shaarli\Plugin\Wallabag;
 
 /**
  * Class WallabagInstance.
index a6476c71c893b0b9f7b2fadef9e8610a86b807be..bc35df08dcde122f0ca11e8fad30dc17e6f16baf 100644 (file)
@@ -1,11 +1,11 @@
 <?php
-
 /**
- * Plugin Wallabag.
+ * Wallabag plugin
  */
 
-require_once 'WallabagInstance.php';
 use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Plugin\Wallabag\WallabagInstance;
 
 /**
  * Init function, return an error if the server is not set.
index fe5f84ce674f8dadcf195793b0ec61c0d807891b..82f8804d525867af42fa2345e2bdfd234adb5aae 100644 (file)
@@ -1,33 +1,14 @@
 <?php
-use Shaarli\Config\ConfigManager;
-
-/**
- * ApplicationUtils' tests
- */
+namespace Shaarli;
 
-require_once 'application/ApplicationUtils.php';
-
-/**
- * Fake ApplicationUtils class to avoid HTTP requests
- */
-class FakeApplicationUtils extends ApplicationUtils
-{
-    public static $VERSION_CODE = '';
-
-    /**
-     * Toggle HTTP requests, allow overriding the version code
-     */
-    public static function getVersion($url, $timeout = 0)
-    {
-        return self::$VERSION_CODE;
-    }
-}
+use Shaarli\Config\ConfigManager;
 
+require_once 'tests/utils/FakeApplicationUtils.php';
 
 /**
  * Unitary tests for Shaarli utilities
  */
-class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
+class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
 {
     protected static $testUpdateFile = 'sandbox/update.txt';
     protected static $testVersion = '0.5.0';
index d764e4953a1bff4870eaca13683e09864c736e42..57719175542c3562af141c0658a9b28e1ba96dcb 100644 (file)
@@ -1,13 +1,15 @@
 <?php
 
-require_once 'application/FileUtils.php';
+namespace Shaarli;
+
+use Exception;
 
 /**
  * Class FileUtilsTest
  *
  * Test file utility class.
  */
-class FileUtilsTest extends PHPUnit_Framework_TestCase
+class FileUtilsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Test file path.
@@ -48,7 +50,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
     /**
      * File not writable: raise an exception.
      *
-     * @expectedException IOException
+     * @expectedException Shaarli\Exceptions\IOException
      * @expectedExceptionMessage Error accessing "sandbox/flat.db"
      */
     public function testWriteWithoutPermission()
@@ -61,7 +63,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
     /**
      * Folder non existent: raise an exception.
      *
-     * @expectedException IOException
+     * @expectedException Shaarli\Exceptions\IOException
      * @expectedExceptionMessage Error accessing "nopefolder"
      */
     public function testWriteFolderDoesNotExist()
@@ -72,7 +74,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
     /**
      * Folder non writable: raise an exception.
      *
-     * @expectedException IOException
+     * @expectedException Shaarli\Exceptions\IOException
      * @expectedExceptionMessage Error accessing "sandbox"
      */
     public function testWriteFolderPermission()
index d3bef5a332cec8336455d00fc80c51d43b6bae23..8303e53a40b512386559aa2e665aeb88c28cbfa2 100644 (file)
@@ -1,9 +1,11 @@
 <?php
 
-require_once 'application/History.php';
+namespace Shaarli;
 
+use DateTime;
+use Exception;
 
-class HistoryTest extends PHPUnit_Framework_TestCase
+class HistoryTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string History file path
index 4951e09a3e2f31261ca9b119d700fb817a3e860f..de83f2913707aef08f52ff08474186e38210c9a8 100644 (file)
@@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager;
 /**
  * Class LanguagesTest.
  */
-class LanguagesTest extends \PHPUnit_Framework_TestCase
+class LanguagesTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Config file path (without extension).
index 01de959c5266bb9e877f7e425e5a5af9e2cc673d..71761ac17db62f18eb199f4f85e32774b4ae2cf4 100644 (file)
@@ -1,16 +1,12 @@
 <?php
-use Shaarli\Config\ConfigManager;
+namespace Shaarli\Plugin;
 
-/**
- * Plugin Manager tests
- */
-
-require_once 'application/PluginManager.php';
+use Shaarli\Config\ConfigManager;
 
 /**
  * Unit tests for Plugins
  */
-class PluginManagerTest extends PHPUnit_Framework_TestCase
+class PluginManagerTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Path to tests plugin.
index abf1bd5f5067caf74451439273c2e5a494fe4963..0cd49bb8fb2ea6951018e818bc3b8a9907c242d7 100644 (file)
@@ -1,15 +1,10 @@
 <?php
-
-/**
- * Router tests
- */
-
-require_once 'application/Router.php';
+namespace Shaarli;
 
 /**
  * Unit tests for Router
  */
-class RouterTest extends PHPUnit_Framework_TestCase
+class RouterTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Test findPage: login page output.
index 127fdc192ccab36ec57427ba270f444f9108b29f..02bf060f34a0a7a1be177b2ab96d10316c73b869 100644 (file)
@@ -8,7 +8,7 @@ require_once 'application/TimeZone.php';
 /**
  * Unitary tests for timezone utilities
  */
-class TimeZoneTest extends PHPUnit_Framework_TestCase
+class TimeZoneTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var array of timezones
index d0abd9968cfdc4afa152db87682b00ae4d5d73e5..8225d95ae067d3c5db9fb4a352860bb341c8b961 100644 (file)
@@ -10,7 +10,7 @@ require_once 'application/Languages.php';
 /**
  * Unitary tests for Shaarli utilities
  */
-class UtilsTest extends PHPUnit_Framework_TestCase
+class UtilsTest extends PHPUnit\Framework\TestCase
 {
     // Log file
     protected static $testLogFile = 'tests.log';
index 23a56b1cee4e78e90aec15941fb4b3927242b32e..0b9b03f28ec7c0d824e23484395d60dd867f06a4 100644 (file)
@@ -2,7 +2,6 @@
 namespace Shaarli\Api;
 
 use Shaarli\Config\ConfigManager;
-
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
  *
  * @package Api
  */
-class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase
+class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
index df4e189a9f786b91718cde89b6152c90bac395c0..ea0ae50087d04ee5ac89c9a681f97f6676c88979 100644 (file)
@@ -2,12 +2,12 @@
 
 namespace Shaarli\Api;
 
-use Shaarli\Base64Url;
+use Shaarli\Http\Base64Url;
 
 /**
  * Class ApiUtilsTest
  */
-class ApiUtilsTest extends \PHPUnit_Framework_TestCase
+class ApiUtilsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Force the timezone for ISO datetimes.
index ff34e16dce598be8e849fba6fac30887908cc875..e287f239eea24fe746ccf894f1b464c3769206de 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
-
 namespace Shaarli\Api\Controllers;
 
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -11,7 +11,7 @@ use Slim\Http\Response;
 
 require_once 'tests/utils/ReferenceHistory.php';
 
-class HistoryTest extends \PHPUnit_Framework_TestCase
+class HistoryTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -34,7 +34,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
     protected $container;
 
     /**
-     * @var History controller instance.
+     * @var HistoryController controller instance.
      */
     protected $controller;
 
@@ -49,9 +49,9 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
         $this->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']
index e437082a1af9517b9b658498a07bed89ff9459c8..e70d371bf7ae650364444c0318b0ca7ddeb75d6d 100644 (file)
@@ -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);
index 7d79713779cc70bf1c18c3ae3803196be6af3990..90193e289ab95bf453c35de9af63250d3ea7800f 100644 (file)
@@ -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()
     {
index 57528d5aee7c7372dee4dff3fd6f15abe0a6d8af..cb9b7f6a84afbc8cb87b0cc8cf3592474084fcc8 100644 (file)
@@ -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']);
index 64f027743787d22fd7ad9a700145c4e6563ba6e7..711a315221b84d85d5829413866caa2411d5de1b 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace Shaarli\Api\Controllers;
 
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
-
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -17,7 +17,7 @@ use Slim\Http\Response;
  *
  * @package Shaarli\Api\Controllers
  */
-class GetLinksTest extends \PHPUnit_Framework_TestCase
+class GetLinksTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -60,7 +60,7 @@ class GetLinksTest 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 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']
         );
     }
index 5c2b56232c4691529c0aa8ac96904a1c4ec9ec54..d683a98429c05a882d42998a287f9e98cf4c4ff7 100644 (file)
@@ -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'])
         );
     }
index f276b4c179df6edcec3c7896c4621bc7bdc93bf1..cd815b667be954b99719e7a2c0e9b7fab1661a9c 100644 (file)
@@ -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'])
         );
     }
index e0787ce2cfa213f356e6a770f1875fc24364e73f..84e1d56ecd279d4e45eb137f57e4777108480df8 100644 (file)
@@ -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']
         );
index afac228e26b23e0ad74037c105e69a5a4b49a67c..a2525c177b63967aadb8c1b7b6255b4fcf585814 100644 (file)
@@ -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);
index 3fab31b0f462a3ee335b9429240e65919a745e68..98628c984f0fa9e12f2da7f7865bb6eb70155d3f 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace Shaarli\Api\Controllers;
 
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
-
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -15,7 +15,7 @@ use Slim\Http\Response;
  *
  * @package Shaarli\Api\Controllers
  */
-class GetTagsTest extends \PHPUnit_Framework_TestCase
+class GetTagsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -38,7 +38,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
     protected $container;
 
     /**
-     * @var \LinkDB instance.
+     * @var LinkDB instance.
      */
     protected $linkDB;
 
@@ -63,7 +63,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
 
         $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'] = null;
 
index 3801724304d9b011c88325ff60d77fc8e0cf826f..86106fc7eaec629b8739a14d87ee42dea8ca90ed 100644 (file)
@@ -1,16 +1,17 @@
 <?php
 
-
 namespace Shaarli\Api\Controllers;
 
 use Shaarli\Api\Exceptions\ApiBadParametersException;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class PutTagTest extends \PHPUnit_Framework_TestCase
+class PutTagTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -33,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
     protected $refDB = null;
 
     /**
-     * @var \History instance.
+     * @var HistoryController instance.
      */
     protected $history;
 
@@ -43,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
     protected $container;
 
     /**
-     * @var \LinkDB instance.
+     * @var LinkDB instance.
      */
     protected $linkDB;
 
@@ -68,11 +69,11 @@ class PutTagTest 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->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']
         );
similarity index 95%
rename from tests/LinkDBTest.php
rename to tests/bookmark/LinkDBTest.php
index c763c0cbd5f34ce7797658b7bcae2e72829f3290..ff5c0b970af1e8283d71e68606c3337e3d4c5936 100644 (file)
@@ -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()
     {
similarity index 96%
rename from tests/LinkFilterTest.php
rename to tests/bookmark/LinkFilterTest.php
index eb54c3591af12fb6111389d34d55b5979149bc10..808f81220b84e5d75d48ae3ca62983f262473a1f 100644 (file)
@@ -1,11 +1,14 @@
 <?php
 
-require_once 'application/LinkFilter.php';
+namespace Shaarli\Bookmark;
+
+use Exception;
+use ReferenceLinkDB;
 
 /**
  * Class LinkFilterTest.
  */
-class LinkFilterTest extends PHPUnit_Framework_TestCase
+class LinkFilterTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Test datastore path.
@@ -27,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
     protected static $linkDB;
 
     /**
-     * Instanciate linkFilter with ReferenceLinkDB data.
+     * Instantiate linkFilter with ReferenceLinkDB data.
      */
     public static function setUpBeforeClass()
     {
@@ -79,10 +82,14 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
             count(
                 self::$linkFilter->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()
     {
similarity index 76%
rename from tests/LinkUtilsTest.php
rename to tests/bookmark/LinkUtilsTest.php
index 5407159a04c37ed9908aa7fcb063c576b4fd8475..1b8688e6d398fc1381e6b2acc586ae2562c282f2 100644 (file)
@@ -1,11 +1,15 @@
 <?php
 
-require_once 'application/LinkUtils.php';
+namespace Shaarli\Bookmark;
+
+use ReferenceLinkDB;
+
+require_once 'tests/utils/CurlUtils.php';
 
 /**
-* Class LinkUtilsTest.
-*/
-class LinkUtilsTest extends PHPUnit_Framework_TestCase
+ * Class LinkUtilsTest.
+ */
+class LinkUtilsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Test html_extract_title() when the title is found.
@@ -13,9 +17,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
     public function testHtmlExtractExistentTitle()
     {
         $title = 'Read me please.';
-        $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
+        $html = '<html><meta>stuff</meta><title>' . $title . '</title></html>';
         $this->assertEquals($title, html_extract_title($html));
-        $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>';
+        $html = '<html><title>' . $title . '</title>blabla<title>another</title></html>';
         $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 = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>';
+        $html = '<html><meta>stuff2</meta><meta charset="' . $charset . '"/></html>';
         $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">'
-            .'<title>Refactoring Â· GitHub</title>'
-            .'<link rel="search" type="application/opensea',
+                . '<title>Refactoring Â· GitHub</title>'
+                . '<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -109,8 +113,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
         $data = [
             'HTTP/1.1 200 OK',
             'end' => 'th=device-width">'
-            .'<title>Refactoring Â· GitHub</title>'
-            .'<link rel="search" type="application/opensea',
+                . '<title>Refactoring Â· GitHub</title>'
+                . '<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -131,8 +135,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
             'HTTP/1.1 200 OK',
             '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
             'end' => 'th=device-width">'
-            .'<title>Refactoring Â· GitHub</title>'
-            .'<link rel="search" type="application/opensea',
+                . '<title>Refactoring Â· GitHub</title>'
+                . '<link rel="search" type="application/opensea',
             '<title>ignored</title>',
         ];
         foreach ($data as $key => $line) {
@@ -218,19 +222,19 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
     {
         $text = 'stuff http://hello.there/is=someone#here otherstuff';
         $expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
-            .'http://hello.there/is=someone#here</a> otherstuff';
+            . 'http://hello.there/is=someone#here</a> otherstuff';
         $processedText = text2clickable($text, '');
         $this->assertEquals($expectedText, $processedText);
 
         $text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
         $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
-            .'http://hello.there/is=someone#here(please)</a> otherstuff';
+            . 'http://hello.there/is=someone#here(please)</a> otherstuff';
         $processedText = text2clickable($text, '');
         $this->assertEquals($expectedText, $processedText);
 
         $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
         $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
-            .'http://hello.there/is=someone#here(please)&no</a> otherstuff';
+            . 'http://hello.there/is=someone#here(please)&no</a> 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 <a href="'.
+        $expectedText = 'stuff <a href="' .
             $redirector .
             urlencode('http://hello.there/is=someone#here') .
             '">http://hello.there/is=someone#here</a> 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 <a href="'.
+        $expectedText = 'stuff <a href="' .
             $redirector .
             'http://hello.there/?is=someone&or=something#here' .
             '">http://hello.there/?is=someone&or=something#here</a> otherstuff';
@@ -270,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
      */
     public function testSpace2nbsp()
     {
-        $text = '  Are you   thrilled  by flags   ?'. PHP_EOL .' Really?';
-        $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?'. PHP_EOL .'&nbsp;Really?';
+        $text = '  Are you   thrilled  by flags   ?' . PHP_EOL . ' Really?';
+        $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?' . PHP_EOL . '&nbsp;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 = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>';
+        $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>';
         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';
-    }
-}
index d237bc80cdacd1a7919399f68cad57ece869a470..95ad060b0537fed84ca2bd2cc43a6f92098ee1b4 100644 (file)
@@ -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()
     {
index 4a4e94ac551f135cca96d81a7f08672c43bae7ef..33830bc94bcc3584380b1a18259e4cf9ec101980 100644 (file)
@@ -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
index be23eea1563a909ecce1a981d1194040d8d9fe3a..67d878cee31cc88a61cf0cad4b92eb8d08e2b044 100644 (file)
@@ -4,7 +4,7 @@ namespace Shaarli\Config;
 /**
  * Class ConfigPhpTest
  */
-class ConfigPhpTest extends \PHPUnit_Framework_TestCase
+class ConfigPhpTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var ConfigPhp
index deb02c9e487f901519b07b66f545599aaed75692..d7a70e6886b54a889eed845560350eae05cefabe 100644 (file)
@@ -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.
similarity index 68%
rename from tests/CacheTest.php
rename to tests/feed/CacheTest.php
index f60fad91099048ba5d1c8c2d3d34289175880a4f..c0a9f26f2dc933d7adf8644a8b580d797efe01de 100644 (file)
@@ -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);
similarity index 92%
rename from tests/CachedPageTest.php
rename to tests/feed/CachedPageTest.php
index 51565cd63f591c5e69ff41a1eb29d1e616b52cba..0bcc1442c7133bbf41bba1348213a9143352d328 100644 (file)
@@ -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';
     }
 
     /**
similarity index 97%
rename from tests/FeedBuilderTest.php
rename to tests/feed/FeedBuilderTest.php
index 4ca58e5a3b514bf20f21a4597c3d49fb927c1378..b496cb4c3499612fa2ec37c2df44a679eead3da1 100644 (file)
@@ -1,14 +1,17 @@
 <?php
 
-require_once 'application/FeedBuilder.php';
-require_once 'application/LinkDB.php';
+namespace Shaarli\Feed;
+
+use DateTime;
+use ReferenceLinkDB;
+use Shaarli\Bookmark\LinkDB;
 
 /**
  * FeedBuilderTest class.
  *
  * Unit tests for FeedBuilder.
  */
-class FeedBuilderTest extends PHPUnit_Framework_TestCase
+class FeedBuilderTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string locale Basque (Spain).
@@ -90,7 +93,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
         $this->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']);
similarity index 89%
rename from tests/HttpUtils/ClientIpIdTest.php
rename to tests/http/HttpUtils/ClientIpIdTest.php
index c15ac5cc0a4814733cd7bfdd79eccaccec29e0c4..982e57e0b6ff37ae8b42b1a5a11707ddf0bb08b9 100644 (file)
@@ -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
similarity index 85%
rename from tests/HttpUtils/GetHttpUrlTest.php
rename to tests/http/HttpUtils/GetHttpUrlTest.php
index ea53de5f27feabec829489c442c728bf5b661cf4..3dc5bc9b03c38c9b0cad7763b2578b6e0ed017c5 100644 (file)
@@ -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);
     }
 
similarity index 91%
rename from tests/HttpUtils/GetIpAdressFromProxyTest.php
rename to tests/http/HttpUtils/GetIpAdressFromProxyTest.php
index 7af5bd9db058c356e9b0b13a52cc2ffc430b2337..fe3a639e296ed3fe6512c7186f43f9d49fb7694c 100644 (file)
@@ -1,11 +1,13 @@
 <?php
 
-require_once 'application/HttpUtils.php';
+namespace Shaarli\Http;
+
+require_once 'application/http/HttpUtils.php';
 
 /**
  * Unitary tests for getIpAddressFromProxy()
  */
-class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase
+class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
 {
 
     /**
similarity index 92%
rename from tests/HttpUtils/IndexUrlTest.php
rename to tests/http/HttpUtils/IndexUrlTest.php
index 337dcab0b070fa9b6439eb11d9009815c6ee2450..bcbe59cbf6abe493a392f429fb96f1c54cb2d46c 100644 (file)
@@ -3,12 +3,14 @@
  * HttpUtils' tests
  */
 
-require_once 'application/HttpUtils.php';
+namespace Shaarli\Http;
+
+require_once 'application/http/HttpUtils.php';
 
 /**
  * Unitary tests for index_url()
  */
-class IndexUrlTest extends PHPUnit_Framework_TestCase
+class IndexUrlTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * If on the main page, remove "index.php" from the URL resource
similarity index 89%
rename from tests/HttpUtils/IsHttpsTest.php
rename to tests/http/HttpUtils/IsHttpsTest.php
index 097f2bcf0c56b5e2364548ffc360402ea3e05f38..348956c645e6c40891ab42655237e75d7b810403 100644 (file)
@@ -1,12 +1,15 @@
 <?php
 
+namespace Shaarli\Http;
+
+require_once 'application/http/HttpUtils.php';
 
 /**
  * Class IsHttpsTest
  *
  * Test class for is_https() function.
  */
-class IsHttpsTest extends PHPUnit_Framework_TestCase
+class IsHttpsTest extends \PHPUnit\Framework\TestCase
 {
 
     /**
similarity index 93%
rename from tests/HttpUtils/PageUrlTest.php
rename to tests/http/HttpUtils/PageUrlTest.php
index 4dbbe9cf40bb57d40fe0f862c80367b116acb780..f199171684bad9694e6d3545b13b2a55c14d14ef 100644 (file)
@@ -3,12 +3,14 @@
  * HttpUtils' tests
  */
 
-require_once 'application/HttpUtils.php';
+namespace Shaarli\Http;
+
+require_once 'application/http/HttpUtils.php';
 
 /**
  * Unitary tests for page_url()
  */
-class PageUrlTest extends PHPUnit_Framework_TestCase
+class PageUrlTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * If on the main page, remove "index.php" from the URL resource
similarity index 97%
rename from tests/HttpUtils/ServerUrlTest.php
rename to tests/http/HttpUtils/ServerUrlTest.php
index 324b827acc11e9612c933fa89893dfd318f523a3..9caf104983ffd75427cb6a9a9c35cb1a29f042d0 100644 (file)
@@ -3,12 +3,14 @@
  * HttpUtils' tests
  */
 
-require_once 'application/HttpUtils.php';
+namespace Shaarli\Http;
+
+require_once 'application/http/HttpUtils.php';
 
 /**
  * Unitary tests for server_url()
  */
-class ServerUrlTest extends PHPUnit_Framework_TestCase
+class ServerUrlTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Detect if the server uses SSL
similarity index 87%
rename from tests/Url/UrlTest.php
rename to tests/http/UrlTest.php
index db229ce0d87c544ff912fd5240cc6a15dccaa950..ae92f73a4d4a2a62a851b9d99d5b523bc9b303e7 100644 (file)
@@ -1,14 +1,14 @@
 <?php
 /**
- * Url's tests
+ * UrlUtils's tests
  */
 
-require_once 'application/Url.php';
+namespace Shaarli\Http;
 
 /**
  * Unitary tests for URL utilities
  */
-class UrlTest extends PHPUnit_Framework_TestCase
+class UrlTest extends \PHPUnit\Framework\TestCase
 {
     // base URL for tests
     protected static $baseUrl = 'http://domain.tld:3000';
@@ -18,7 +18,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
      */
     private function assertUrlIsCleaned($query = '', $fragment = '')
     {
-        $url = new Url(self::$baseUrl.$query.$fragment);
+        $url = new Url(self::$baseUrl . $query . $fragment);
         $url->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());
     }
 
     /**
similarity index 96%
rename from tests/Url/CleanupUrlTest.php
rename to tests/http/UrlUtils/CleanupUrlTest.php
index 24791948337a94be0692a6e97b4c20faa94d2de2..6c4d124bed845f4d5205dda31df2f61b0a0d99d0 100644 (file)
@@ -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
similarity index 76%
rename from tests/Url/GetUrlSchemeTest.php
rename to tests/http/UrlUtils/GetUrlSchemeTest.php
index 18b932d6f3a350c9f7191a5faf7517ffbdd02b76..2b97f7be649a4c120fb31c24f13ab19f70b7c3a1 100644 (file)
@@ -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()
     {
similarity index 76%
rename from tests/Url/UnparseUrlTest.php
rename to tests/http/UrlUtils/UnparseUrlTest.php
index e314b48468b789688fec09dda194074c670de0e3..040d8c54ed5a1fca14490ec36ebdb2994005252f 100644 (file)
@@ -1,14 +1,16 @@
 <?php
 /**
- * Unpares Url's tests
+ * Unpares UrlUtils's tests
  */
 
-require_once 'application/Url.php';
+namespace Shaarli\Http;
+
+require_once 'application/http/UrlUtils.php';
 
 /**
  * Unitary tests for unparse_url()
  */
-class UnparseUrlTest extends PHPUnit_Framework_TestCase
+class UnparseUrlTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Thanks for building nothing
similarity index 91%
rename from tests/Url/WhitelistProtocolsTest.php
rename to tests/http/UrlUtils/WhitelistProtocolsTest.php
index a315680483259e4e340a6323f4c12069d00075c5..69512dbd18787a2129b83c97662cf31fbba91f9a 100644 (file)
@@ -1,15 +1,15 @@
 <?php
 
-require_once 'application/Url.php';
+namespace Shaarli\Http;
 
-use Shaarli\Config\ConfigManager;
+require_once 'application/http/UrlUtils.php';
 
 /**
  * Class WhitelistProtocolsTest
  *
- * Test whitelist_protocols() function of Url.
+ * Test whitelist_protocols() function of UrlUtils.
  */
-class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase
+class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Test whitelist_protocols() on a note (relative URL).
index 38347de19cce5e543e8774d60b5991a19c6bc8ed..b8b7ca3a548358e98946e5d8833b748a40ecf27c 100644 (file)
@@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager;
  *
  * @package Shaarli
  */
-class LanguagesFrTest extends \PHPUnit_Framework_TestCase
+class LanguagesFrTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Config file path (without extension).
similarity index 93%
rename from tests/NetscapeBookmarkUtils/BookmarkExportTest.php
rename to tests/netscape/BookmarkExportTest.php
index 77fbd5f38795ee6bf8d1761e1a00da77922be9ae..6de9876d419701cd76bcf7078b3c57a718e13510 100644 (file)
@@ -1,11 +1,14 @@
 <?php
+namespace Shaarli\Netscape;
 
-require_once 'application/NetscapeBookmarkUtils.php';
+use Shaarli\Bookmark\LinkDB;
+
+require_once 'tests/utils/ReferenceLinkDB.php';
 
 /**
  * Netscape bookmark export
  */
-class BookmarkExportTest extends PHPUnit_Framework_TestCase
+class BookmarkExportTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -13,7 +16,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
     protected static $testDatastore = 'sandbox/datastore.php';
 
     /**
-     * @var ReferenceLinkDB instance.
+     * @var \ReferenceLinkDB instance.
      */
     protected static $refDb = null;
 
@@ -27,7 +30,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
      */
     public static function setUpBeforeClass()
     {
-        self::$refDb = new ReferenceLinkDB();
+        self::$refDb = new \ReferenceLinkDB();
         self::$refDb->write(self::$testDatastore);
         self::$linkDb = new LinkDB(self::$testDatastore, true, false);
     }
similarity index 99%
rename from tests/NetscapeBookmarkUtils/BookmarkImportTest.php
rename to tests/netscape/BookmarkImportTest.php
index f0a958cb2e71fed3cd747ef10f906b38b82efc1b..ccafc1619cf48d988fef4e4a62d44f5f81789a88 100644 (file)
@@ -1,8 +1,10 @@
 <?php
+namespace Shaarli\Netscape;
 
-require_once 'application/NetscapeBookmarkUtils.php';
-
+use DateTime;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 
 /**
  * Utility function to load a file's metadata in a $_FILES-like array
@@ -26,7 +28,7 @@ function file2array($filename)
 /**
  * Netscape bookmark import
  */
-class BookmarkImportTest extends PHPUnit_Framework_TestCase
+class BookmarkImportTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
index b6239e7f2f09851e94caf0b3933e4c511c0157ca..d052f8b9f24766911d4c295a4015b24456959f07 100644 (file)
@@ -1,17 +1,15 @@
 <?php
+namespace Shaarli\Plugin\Addlink;
 
-/**
- * PluginPlayvideosTest.php
- */
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Router;
 
 require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
-require_once 'application/Router.php';
 
 /**
- * Class PluginAddlinkTest
  * Unit test for the Addlink toolbar plugin
  */
-class PluginAddlinkTest extends PHPUnit_Framework_TestCase
+class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path.
index fecd5f2c21488b3cf35390b663879766c0a1a0e8..510288bbadc2e31557142896d89034bf10a40148 100644 (file)
@@ -1,16 +1,19 @@
 <?php
+namespace Shaarli\Plugin\Archiveorg;
 
 /**
  * PluginArchiveorgTest.php
  */
 
+use Shaarli\Plugin\PluginManager;
+
 require_once 'plugins/archiveorg/archiveorg.php';
 
 /**
  * Class PluginArchiveorgTest
  * Unit test for the archiveorg plugin
  */
-class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
+class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path
index 2c9efbcde4292a221392a725d73d488dd26c2c9e..bdfab439cd60d0a42b22193dd1f4b7ddd60d0076 100644 (file)
@@ -1,5 +1,10 @@
 <?php
+namespace Shaarli\Plugin\Isso;
+
+use DateTime;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
 
 require_once 'plugins/isso/isso.php';
 
@@ -8,7 +13,7 @@ require_once 'plugins/isso/isso.php';
  *
  * Test the Isso plugin (comment system).
  */
-class PluginIssoTest extends PHPUnit_Framework_TestCase
+class PluginIssoTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path
index 44364b05b5f4a14036e432a51fdc539668ac39dd..5e7c02b0c8f5b95407733d73cf01f95b26ccf3e8 100644 (file)
@@ -1,10 +1,14 @@
 <?php
+namespace Shaarli\Plugin\Markdown;
+
 use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
 
 /**
  * PluginMarkdownTest.php
  */
 
+require_once 'application/bookmark/LinkUtils.php';
 require_once 'application/Utils.php';
 require_once 'plugins/markdown/markdown.php';
 
@@ -12,7 +16,7 @@ require_once 'plugins/markdown/markdown.php';
  * Class PluginMarkdownTest
  * Unit test for the Markdown plugin
  */
-class PluginMarkdownTest extends PHPUnit_Framework_TestCase
+class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var ConfigManager instance.
index 29ad047f4a10ae608dd1d1b59bd057f40429ff9a..51472617ad47cf21cd5fbc418ca2fd5d0982652c 100644 (file)
@@ -1,17 +1,20 @@
 <?php
+namespace Shaarli\Plugin\Playvideos;
 
 /**
  * PluginPlayvideosTest.php
  */
 
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Router;
+
 require_once 'plugins/playvideos/playvideos.php';
-require_once 'application/Router.php';
 
 /**
  * Class PluginPlayvideosTest
  * Unit test for the PlayVideos plugin
  */
-class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
+class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path
index 69d00936f13db7a9f8d38e20753a8973dbad77c6..a7bd8fc93d79980633fd7edc71a66eb248df0b3e 100644 (file)
@@ -1,14 +1,17 @@
 <?php
+namespace Shaarli\Plugin\Pubsubhubbub;
+
 use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Router;
 
 require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
-require_once 'application/Router.php';
 
 /**
  * Class PluginPubsubhubbubTest
  * Unit test for the pubsubhubbub plugin
  */
-class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase
+class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Config file path (without extension).
index dd632eee4594592a5ebcadf47b6c386caffe7a49..0c61e14a75bc841f1be4d5362bcb4b55c8b4662d 100644 (file)
@@ -1,16 +1,20 @@
 <?php
+namespace Shaarli\Plugin\Qrcode;
+
 /**
  * PluginQrcodeTest.php
  */
 
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Router;
+
 require_once 'plugins/qrcode/qrcode.php';
-require_once 'application/Router.php';
 
 /**
  * Class PluginQrcodeTest
  * Unit test for the QR-Code plugin
  */
-class PluginQrcodeTest extends PHPUnit_Framework_TestCase
+class PluginQrcodeTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path
index 76b7887e53e1443272527518d50a72f5eb4b420e..797519210c63c5827da633d870e90de1b152d6c3 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-use Shaarli\Config\ConfigManager;
+namespace Shaarli\Plugin\Wallabag;
 
-/**
- * PluginWallabagTest.php.php
- */
+use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
 
 require_once 'plugins/wallabag/wallabag.php';
 
@@ -11,7 +10,7 @@ require_once 'plugins/wallabag/wallabag.php';
  * Class PluginWallabagTest
  * Unit test for the Wallabag plugin
  */
-class PluginWallabagTest extends PHPUnit_Framework_TestCase
+class PluginWallabagTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Reset plugin path
index 2c46687100c13495408e80ac68dc31523283fd78..a3cd90765676c36920a9a58d2b0140133950a54d 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-require_once 'plugins/wallabag/WallabagInstance.php';
+namespace Shaarli\Plugin\Wallabag;
 
 /**
  * Class WallabagInstanceTest
  */
-class WallabagInstanceTest extends PHPUnit_Framework_TestCase
+class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string wallabag url.
similarity index 93%
rename from tests/ThemeUtilsTest.php
rename to tests/render/ThemeUtilsTest.php
index e44564be3e398bc2e265a5f8cf7cbc089e31652e..58e3426b2de3670ab40a2c12bc385c2b308652d8 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 
-namespace Shaarli;
+namespace Shaarli\Render;
 
 /**
  * Class ThemeUtilsTest
  *
  * @package Shaarli
  */
-class ThemeUtilsTest extends \PHPUnit_Framework_TestCase
+class ThemeUtilsTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * Test getThemes() with existing theme directories.
index f26cd1eb8635c0bd21f8f4ab68043b7569562ddf..de8055edaede452cdeeb1c21ed42ae3b13447a8e 100644 (file)
@@ -2,7 +2,8 @@
 namespace Shaarli\Security;
 
 require_once 'tests/utils/FakeConfigManager.php';
-use \PHPUnit\Framework\TestCase;
+
+use PHPUnit\Framework\TestCase;
 
 /**
  * Test coverage for LoginManager
index 7961e7710dc3581a2d7f63659fc6f2aa500c25b2..f264505eaefa81159e7cf1af14fb01b22b60f027 100644 (file)
@@ -5,8 +5,8 @@ require_once 'tests/utils/FakeConfigManager.php';
 require_once 'tests/utils/ReferenceSessionIdHashes.php';
 ReferenceSessionIdHashes::genAllHashes();
 
-use \Shaarli\Security\SessionManager;
-use \PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\TestCase;
+use Shaarli\Security\SessionManager;
 
 /**
  * Test coverage for SessionManager
similarity index 87%
rename from tests/Updater/DummyUpdater.php
rename to tests/updater/DummyUpdater.php
index a805ab5e900181755191e46b2dbe82b2f3c9e2dd..9e866f1f1c60fab1f7551885378d91ffadcdc4a4 100644 (file)
@@ -1,10 +1,15 @@
 <?php
+namespace Shaarli\Updater;
 
-require_once 'application/Updater.php';
+use Exception;
+use ReflectionClass;
+use ReflectionMethod;
+use Shaarli\Bookmark\LinkDB;
+use Shaarli\Config\ConfigManager;
 
 /**
  * Class DummyUpdater.
- * Extends Updater to add update method designed for unit tests.
+ * Extends updater to add update method designed for unit tests.
  */
 class DummyUpdater extends Updater
 {
similarity index 97%
rename from tests/Updater/UpdaterTest.php
rename to tests/updater/UpdaterTest.php
index c4a6e7ef4fee86c9634e9aaff4cfdc7f6f8d03d7..d7df59637395ddf9a7d4760eecefa5db4a32a97e 100644 (file)
@@ -1,17 +1,24 @@
 <?php
+namespace Shaarli\Updater;
+
+use DateTime;
+use Exception;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigJson;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Config\ConfigPhp;
 use Shaarli\Thumbnailer;
 
-require_once 'tests/Updater/DummyUpdater.php';
+require_once 'application/updater/UpdaterUtils.php';
+require_once 'tests/updater/DummyUpdater.php';
+require_once 'tests/utils/ReferenceLinkDB.php';
 require_once 'inc/rain.tpl.class.php';
 
 /**
  * Class UpdaterTest.
- * Runs unit tests against the Updater class.
+ * Runs unit tests against the updater class.
  */
-class UpdaterTest extends PHPUnit_Framework_TestCase
+class UpdaterTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Path to test datastore.
@@ -153,7 +160,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
     /**
      * Test Update failed.
      *
-     * @expectedException UpdaterException
+     * @expectedException \Exception
      */
     public function testUpdateFailed()
     {
@@ -179,17 +186,17 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
         $this->conf->setConfigFile('tests/utils/config/configPhp');
         $this->conf->reset();
 
-        $optionsFile = 'tests/Updater/options.php';
+        $optionsFile = 'tests/updater/options.php';
         $options = '<?php
 $GLOBALS[\'privateLinkByDefault\'] = true;';
         file_put_contents($optionsFile, $options);
 
         // tmp config file.
-        $this->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 (file)
index 0000000..1cc4907
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions
+ */
+
+/**
+ * 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/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php
new file mode 100644 (file)
index 0000000..de83d59
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+namespace Shaarli;
+
+/**
+ * Fake ApplicationUtils class to avoid HTTP requests
+ */
+class FakeApplicationUtils extends ApplicationUtils
+{
+    public static $VERSION_CODE = '';
+
+    /**
+     * Toggle HTTP requests, allow overriding the version code
+     */
+    public static function getVersion($url, $timeout = 0)
+    {
+        return self::$VERSION_CODE;
+    }
+}
index 75cbb32629a3668fcde141619afde6514a360210..e411c417e7e6ed96ccaf24becd51541dab347f52 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+use Shaarli\FileUtils;
+use Shaarli\History;
+
 /**
  * Populates a reference history
  */
index 59679e380f8d59b8e959d5773b941ec9b68b3a65..c12bcb678e42bf8de317e5308bd5a9251613ec59 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use Shaarli\Bookmark\LinkDB;
+
 /**
  * Populates a reference datastore to test LinkDB
  */
index 34b11fcddf1a76ed9a1ef3f926e999ce9ab70cd8..7dc81e2289504286fa69abeeea9d20d5c538a448 100644 (file)
@@ -8,7 +8,7 @@ $GLOBALS['titleLink'] = 'titleLink';
 $GLOBALS['redirector'] = 'lala';
 $GLOBALS['disablesessionprotection'] = false;
 $GLOBALS['privateLinkByDefault'] = false;
-$GLOBALS['config']['DATADIR'] = 'tests/Updater';
+$GLOBALS['config']['DATADIR'] = 'tests/updater';
 $GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
 $GLOBALS['config']['DATASTORE'] = 'data/datastore.php';
 $GLOBALS['plugins']['WALLABAG_VERSION'] = '1';