aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
-rw-r--r--application/ApplicationUtils.php75
-rw-r--r--application/FileUtils.php8
-rw-r--r--application/History.php12
-rw-r--r--application/Languages.php1
-rw-r--r--application/Router.php43
-rw-r--r--application/Thumbnailer.php2
-rw-r--r--application/api/ApiMiddleware.php5
-rw-r--r--application/api/ApiUtils.php6
-rw-r--r--application/api/controllers/ApiController.php7
-rw-r--r--application/api/controllers/HistoryController.php (renamed from application/api/controllers/History.php)2
-rw-r--r--application/api/controllers/Tags.php1
-rw-r--r--application/api/exceptions/ApiLinkNotFoundException.php2
-rw-r--r--application/api/exceptions/ApiTagNotFoundException.php2
-rw-r--r--application/bookmark/LinkDB.php (renamed from application/LinkDB.php)61
-rw-r--r--application/bookmark/LinkFilter.php (renamed from application/LinkFilter.php)42
-rw-r--r--application/bookmark/LinkUtils.php (renamed from application/LinkUtils.php)6
-rw-r--r--application/bookmark/exception/LinkNotFoundException.php15
-rw-r--r--application/config/ConfigJson.php2
-rw-r--r--application/config/ConfigManager.php2
-rw-r--r--application/config/ConfigPhp.php4
-rw-r--r--application/exceptions/IOException.php5
-rw-r--r--application/feed/Cache.php (renamed from application/Cache.php)0
-rw-r--r--application/feed/CachedPage.php (renamed from application/CachedPage.php)5
-rw-r--r--application/feed/FeedBuilder.php (renamed from application/FeedBuilder.php)41
-rw-r--r--application/http/Base64Url.php (renamed from application/Base64Url.php)2
-rw-r--r--application/http/HttpUtils.php (renamed from application/HttpUtils.php)5
-rw-r--r--application/http/Url.php (renamed from application/Url.php)97
-rw-r--r--application/http/UrlUtils.php88
-rw-r--r--application/netscape/NetscapeBookmarkUtils.php (renamed from application/NetscapeBookmarkUtils.php)31
-rw-r--r--application/plugin/PluginManager.php (renamed from application/PluginManager.php)39
-rw-r--r--application/plugin/exception/PluginFileNotFoundException.php23
-rw-r--r--application/render/PageBuilder.php (renamed from application/PageBuilder.php)20
-rw-r--r--application/render/ThemeUtils.php (renamed from application/ThemeUtils.php)2
-rw-r--r--application/updater/Updater.php (renamed from application/Updater.php)138
-rw-r--r--application/updater/UpdaterUtils.php39
-rw-r--r--application/updater/exception/UpdaterException.php60
-rw-r--r--composer.json23
-rw-r--r--composer.lock111
-rw-r--r--index.php34
-rw-r--r--plugins/addlink_toolbar/addlink_toolbar.php2
-rw-r--r--plugins/archiveorg/archiveorg.php2
-rw-r--r--plugins/demo_plugin/demo_plugin.php2
-rw-r--r--plugins/isso/isso.php2
-rw-r--r--plugins/markdown/markdown.php2
-rw-r--r--plugins/piwik/piwik.php2
-rw-r--r--plugins/playvideos/playvideos.php3
-rw-r--r--plugins/pubsubhubbub/pubsubhubbub.php3
-rw-r--r--plugins/qrcode/qrcode.php3
-rw-r--r--plugins/wallabag/WallabagInstance.php1
-rw-r--r--plugins/wallabag/wallabag.php6
-rw-r--r--tests/ApplicationUtilsTest.php27
-rw-r--r--tests/FileUtilsTest.php12
-rw-r--r--tests/HistoryTest.php6
-rw-r--r--tests/LanguagesTest.php2
-rw-r--r--tests/PluginManagerTest.php10
-rw-r--r--tests/RouterTest.php9
-rw-r--r--tests/TimeZoneTest.php2
-rw-r--r--tests/UtilsTest.php2
-rw-r--r--tests/api/ApiMiddlewareTest.php3
-rw-r--r--tests/api/ApiUtilsTest.php4
-rw-r--r--tests/api/controllers/history/HistoryTest.php28
-rw-r--r--tests/api/controllers/info/InfoTest.php5
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php18
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php7
-rw-r--r--tests/api/controllers/links/GetLinksTest.php10
-rw-r--r--tests/api/controllers/links/PostLinkTest.php19
-rw-r--r--tests/api/controllers/links/PutLinkTest.php17
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php22
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php6
-rw-r--r--tests/api/controllers/tags/GetTagsTest.php8
-rw-r--r--tests/api/controllers/tags/PutTagTest.php17
-rw-r--r--tests/bookmark/LinkDBTest.php (renamed from tests/LinkDBTest.php)33
-rw-r--r--tests/bookmark/LinkFilterTest.php (renamed from tests/LinkFilterTest.php)23
-rw-r--r--tests/bookmark/LinkUtilsTest.php (renamed from tests/LinkUtilsTest.php)142
-rw-r--r--tests/config/ConfigJsonTest.php6
-rw-r--r--tests/config/ConfigManagerTest.php2
-rw-r--r--tests/config/ConfigPhpTest.php2
-rw-r--r--tests/config/ConfigPluginTest.php2
-rw-r--r--tests/feed/CacheTest.php (renamed from tests/CacheTest.php)23
-rw-r--r--tests/feed/CachedPageTest.php (renamed from tests/CachedPageTest.php)9
-rw-r--r--tests/feed/FeedBuilderTest.php (renamed from tests/FeedBuilderTest.php)11
-rw-r--r--tests/http/HttpUtils/ClientIpIdTest.php (renamed from tests/HttpUtils/ClientIpIdTest.php)6
-rw-r--r--tests/http/HttpUtils/GetHttpUrlTest.php (renamed from tests/HttpUtils/GetHttpUrlTest.php)10
-rw-r--r--tests/http/HttpUtils/GetIpAdressFromProxyTest.php (renamed from tests/HttpUtils/GetIpAdressFromProxyTest.php)6
-rw-r--r--tests/http/HttpUtils/IndexUrlTest.php (renamed from tests/HttpUtils/IndexUrlTest.php)6
-rw-r--r--tests/http/HttpUtils/IsHttpsTest.php (renamed from tests/HttpUtils/IsHttpsTest.php)5
-rw-r--r--tests/http/HttpUtils/PageUrlTest.php (renamed from tests/HttpUtils/PageUrlTest.php)6
-rw-r--r--tests/http/HttpUtils/ServerUrlTest.php (renamed from tests/HttpUtils/ServerUrlTest.php)6
-rw-r--r--tests/http/UrlTest.php (renamed from tests/Url/UrlTest.php)24
-rw-r--r--tests/http/UrlUtils/CleanupUrlTest.php (renamed from tests/Url/CleanupUrlTest.php)6
-rw-r--r--tests/http/UrlUtils/GetUrlSchemeTest.php (renamed from tests/Url/GetUrlSchemeTest.php)10
-rw-r--r--tests/http/UrlUtils/UnparseUrlTest.php (renamed from tests/Url/UnparseUrlTest.php)8
-rw-r--r--tests/http/UrlUtils/WhitelistProtocolsTest.php (renamed from tests/Url/WhitelistProtocolsTest.php)8
-rw-r--r--tests/languages/fr/LanguagesFrTest.php2
-rw-r--r--tests/netscape/BookmarkExportTest.php (renamed from tests/NetscapeBookmarkUtils/BookmarkExportTest.php)11
-rw-r--r--tests/netscape/BookmarkImportTest.php (renamed from tests/NetscapeBookmarkUtils/BookmarkImportTest.php)8
-rw-r--r--tests/netscape/input/empty.htm (renamed from tests/NetscapeBookmarkUtils/input/empty.htm)0
-rw-r--r--tests/netscape/input/internet_explorer_encoding.htm (renamed from tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm)0
-rw-r--r--tests/netscape/input/lowercase_doctype.htm (renamed from tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm)0
-rw-r--r--tests/netscape/input/netscape_basic.htm (renamed from tests/NetscapeBookmarkUtils/input/netscape_basic.htm)0
-rw-r--r--tests/netscape/input/netscape_nested.htm (renamed from tests/NetscapeBookmarkUtils/input/netscape_nested.htm)0
-rw-r--r--tests/netscape/input/no_doctype.htm (renamed from tests/NetscapeBookmarkUtils/input/no_doctype.htm)0
-rw-r--r--tests/netscape/input/same_date.htm (renamed from tests/NetscapeBookmarkUtils/input/same_date.htm)0
-rw-r--r--tests/plugins/PluginAddlinkTest.php10
-rw-r--r--tests/plugins/PluginArchiveorgTest.php5
-rw-r--r--tests/plugins/PluginIssoTest.php7
-rw-r--r--tests/plugins/PluginMarkdownTest.php6
-rw-r--r--tests/plugins/PluginPlayvideosTest.php7
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php7
-rw-r--r--tests/plugins/PluginQrcodeTest.php8
-rw-r--r--tests/plugins/PluginWallabagTest.php9
-rw-r--r--tests/plugins/WallabagInstanceTest.php5
-rw-r--r--tests/render/ThemeUtilsTest.php (renamed from tests/ThemeUtilsTest.php)4
-rw-r--r--tests/security/LoginManagerTest.php3
-rw-r--r--tests/security/SessionManagerTest.php4
-rw-r--r--tests/updater/DummyUpdater.php (renamed from tests/Updater/DummyUpdater.php)9
-rw-r--r--tests/updater/UpdaterTest.php (renamed from tests/Updater/UpdaterTest.php)31
-rw-r--r--tests/utils/CurlUtils.php94
-rw-r--r--tests/utils/FakeApplicationUtils.php19
-rw-r--r--tests/utils/ReferenceHistory.php3
-rw-r--r--tests/utils/ReferenceLinkDB.php3
-rw-r--r--tests/utils/config/configPhp.php2
122 files changed, 1079 insertions, 855 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index a3b2dcb1..7fe3cb32 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -1,4 +1,9 @@
1<?php 1<?php
2namespace Shaarli;
3
4use Exception;
5use Shaarli\Config\ConfigManager;
6
2/** 7/**
3 * Shaarli (application) utilities 8 * Shaarli (application) utilities
4 */ 9 */
@@ -51,7 +56,7 @@ class ApplicationUtils
51 return false; 56 return false;
52 } 57 }
53 } else { 58 } else {
54 if (! is_file($remote)) { 59 if (!is_file($remote)) {
55 return false; 60 return false;
56 } 61 }
57 $data = file_get_contents($remote); 62 $data = file_get_contents($remote);
@@ -97,7 +102,7 @@ class ApplicationUtils
97 // Do not check versions for visitors 102 // Do not check versions for visitors
98 // Do not check if the user doesn't want to 103 // Do not check if the user doesn't want to
99 // Do not check with dev version 104 // Do not check with dev version
100 if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { 105 if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') {
101 return false; 106 return false;
102 } 107 }
103 108
@@ -111,7 +116,7 @@ class ApplicationUtils
111 return false; 116 return false;
112 } 117 }
113 118
114 if (! in_array($branch, self::$GIT_BRANCHES)) { 119 if (!in_array($branch, self::$GIT_BRANCHES)) {
115 throw new Exception( 120 throw new Exception(
116 'Invalid branch selected for updates: "' . $branch . '"' 121 'Invalid branch selected for updates: "' . $branch . '"'
117 ); 122 );
@@ -123,7 +128,7 @@ class ApplicationUtils
123 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE 128 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE
124 ); 129 );
125 130
126 if (! $latestVersion) { 131 if (!$latestVersion) {
127 // Only update the file's modification date 132 // Only update the file's modification date
128 file_put_contents($updateFile, $currentVersion); 133 file_put_contents($updateFile, $currentVersion);
129 return false; 134 return false;
@@ -152,9 +157,9 @@ class ApplicationUtils
152 if (version_compare($curVersion, $minVersion) < 0) { 157 if (version_compare($curVersion, $minVersion) < 0) {
153 $msg = t( 158 $msg = t(
154 'Your PHP version is obsolete!' 159 'Your PHP version is obsolete!'
155 . ' Shaarli requires at least PHP %s, and thus cannot run.' 160 . ' Shaarli requires at least PHP %s, and thus cannot run.'
156 . ' Your PHP version has known security vulnerabilities and should be' 161 . ' Your PHP version has known security vulnerabilities and should be'
157 . ' updated as soon as possible.' 162 . ' updated as soon as possible.'
158 ); 163 );
159 throw new Exception(sprintf($msg, $minVersion)); 164 throw new Exception(sprintf($msg, $minVersion));
160 } 165 }
@@ -174,50 +179,50 @@ class ApplicationUtils
174 179
175 // Check script and template directories are readable 180 // Check script and template directories are readable
176 foreach (array( 181 foreach (array(
177 'application', 182 'application',
178 'inc', 183 'inc',
179 'plugins', 184 'plugins',
180 $rainTplDir, 185 $rainTplDir,
181 $rainTplDir.'/'.$conf->get('resource.theme'), 186 $rainTplDir . '/' . $conf->get('resource.theme'),
182 ) as $path) { 187 ) as $path) {
183 if (! is_readable(realpath($path))) { 188 if (!is_readable(realpath($path))) {
184 $errors[] = '"'.$path.'" '. t('directory is not readable'); 189 $errors[] = '"' . $path . '" ' . t('directory is not readable');
185 } 190 }
186 } 191 }
187 192
188 // Check cache and data directories are readable and writable 193 // Check cache and data directories are readable and writable
189 foreach (array( 194 foreach (array(
190 $conf->get('resource.thumbnails_cache'), 195 $conf->get('resource.thumbnails_cache'),
191 $conf->get('resource.data_dir'), 196 $conf->get('resource.data_dir'),
192 $conf->get('resource.page_cache'), 197 $conf->get('resource.page_cache'),
193 $conf->get('resource.raintpl_tmp'), 198 $conf->get('resource.raintpl_tmp'),
194 ) as $path) { 199 ) as $path) {
195 if (! is_readable(realpath($path))) { 200 if (!is_readable(realpath($path))) {
196 $errors[] = '"'.$path.'" '. t('directory is not readable'); 201 $errors[] = '"' . $path . '" ' . t('directory is not readable');
197 } 202 }
198 if (! is_writable(realpath($path))) { 203 if (!is_writable(realpath($path))) {
199 $errors[] = '"'.$path.'" '. t('directory is not writable'); 204 $errors[] = '"' . $path . '" ' . t('directory is not writable');
200 } 205 }
201 } 206 }
202 207
203 // Check configuration files are readable and writable 208 // Check configuration files are readable and writable
204 foreach (array( 209 foreach (array(
205 $conf->getConfigFileExt(), 210 $conf->getConfigFileExt(),
206 $conf->get('resource.datastore'), 211 $conf->get('resource.datastore'),
207 $conf->get('resource.ban_file'), 212 $conf->get('resource.ban_file'),
208 $conf->get('resource.log'), 213 $conf->get('resource.log'),
209 $conf->get('resource.update_check'), 214 $conf->get('resource.update_check'),
210 ) as $path) { 215 ) as $path) {
211 if (! is_file(realpath($path))) { 216 if (!is_file(realpath($path))) {
212 # the file may not exist yet 217 # the file may not exist yet
213 continue; 218 continue;
214 } 219 }
215 220
216 if (! is_readable(realpath($path))) { 221 if (!is_readable(realpath($path))) {
217 $errors[] = '"'.$path.'" '. t('file is not readable'); 222 $errors[] = '"' . $path . '" ' . t('file is not readable');
218 } 223 }
219 if (! is_writable(realpath($path))) { 224 if (!is_writable(realpath($path))) {
220 $errors[] = '"'.$path.'" '. t('file is not writable'); 225 $errors[] = '"' . $path . '" ' . t('file is not writable');
221 } 226 }
222 } 227 }
223 228
diff --git a/application/FileUtils.php b/application/FileUtils.php
index b89ea12b..30560bfc 100644
--- a/application/FileUtils.php
+++ b/application/FileUtils.php
@@ -1,6 +1,8 @@
1<?php 1<?php
2 2
3require_once 'exceptions/IOException.php'; 3namespace Shaarli;
4
5use Shaarli\Exceptions\IOException;
4 6
5/** 7/**
6 * Class FileUtils 8 * Class FileUtils
@@ -44,7 +46,7 @@ class FileUtils
44 46
45 return file_put_contents( 47 return file_put_contents(
46 $file, 48 $file,
47 self::$phpPrefix.base64_encode(gzdeflate(serialize($content))).self::$phpSuffix 49 self::$phpPrefix . base64_encode(gzdeflate(serialize($content))) . self::$phpSuffix
48 ); 50 );
49 } 51 }
50 52
@@ -62,7 +64,7 @@ class FileUtils
62 { 64 {
63 // Note that gzinflate is faster than gzuncompress. 65 // Note that gzinflate is faster than gzuncompress.
64 // See: http://www.php.net/manual/en/function.gzdeflate.php#96439 66 // See: http://www.php.net/manual/en/function.gzdeflate.php#96439
65 if (! is_readable($file)) { 67 if (!is_readable($file)) {
66 return $default; 68 return $default;
67 } 69 }
68 70
diff --git a/application/History.php b/application/History.php
index 35ec016a..a5846652 100644
--- a/application/History.php
+++ b/application/History.php
@@ -1,4 +1,8 @@
1<?php 1<?php
2namespace Shaarli;
3
4use DateTime;
5use Exception;
2 6
3/** 7/**
4 * Class History 8 * Class History
@@ -66,7 +70,7 @@ class History
66 * History constructor. 70 * History constructor.
67 * 71 *
68 * @param string $historyFilePath History file path. 72 * @param string $historyFilePath History file path.
69 * @param int $retentionTime History content rentention time in seconds. 73 * @param int $retentionTime History content retention time in seconds.
70 * 74 *
71 * @throws Exception if something goes wrong. 75 * @throws Exception if something goes wrong.
72 */ 76 */
@@ -166,11 +170,11 @@ class History
166 */ 170 */
167 protected function check() 171 protected function check()
168 { 172 {
169 if (! is_file($this->historyFilePath)) { 173 if (!is_file($this->historyFilePath)) {
170 FileUtils::writeFlatDB($this->historyFilePath, []); 174 FileUtils::writeFlatDB($this->historyFilePath, []);
171 } 175 }
172 176
173 if (! is_writable($this->historyFilePath)) { 177 if (!is_writable($this->historyFilePath)) {
174 throw new Exception(t('History file isn\'t readable or writable')); 178 throw new Exception(t('History file isn\'t readable or writable'));
175 } 179 }
176 } 180 }
@@ -191,7 +195,7 @@ class History
191 */ 195 */
192 protected function write() 196 protected function write()
193 { 197 {
194 $comparaison = new DateTime('-'. $this->retentionTime . ' seconds'); 198 $comparaison = new DateTime('-' . $this->retentionTime . ' seconds');
195 foreach ($this->history as $key => $value) { 199 foreach ($this->history as $key => $value) {
196 if ($value['datetime'] < $comparaison) { 200 if ($value['datetime'] < $comparaison) {
197 unset($this->history[$key]); 201 unset($this->history[$key]);
diff --git a/application/Languages.php b/application/Languages.php
index b9c5d0e8..5cda802e 100644
--- a/application/Languages.php
+++ b/application/Languages.php
@@ -3,7 +3,6 @@
3namespace Shaarli; 3namespace Shaarli;
4 4
5use Gettext\GettextTranslator; 5use Gettext\GettextTranslator;
6use Gettext\Merge;
7use Gettext\Translations; 6use Gettext\Translations;
8use Gettext\Translator; 7use Gettext\Translator;
9use Gettext\TranslatorInterface; 8use Gettext\TranslatorInterface;
diff --git a/application/Router.php b/application/Router.php
index beb3165b..05877acd 100644
--- a/application/Router.php
+++ b/application/Router.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2namespace Shaarli;
2 3
3/** 4/**
4 * Class Router 5 * Class Router
@@ -75,43 +76,43 @@ class Router
75 return self::$PAGE_LINKLIST; 76 return self::$PAGE_LINKLIST;
76 } 77 }
77 78
78 if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) { 79 if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
79 return self::$PAGE_LOGIN; 80 return self::$PAGE_LOGIN;
80 } 81 }
81 82
82 if (startsWith($query, 'do='. self::$PAGE_PICWALL)) { 83 if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) {
83 return self::$PAGE_PICWALL; 84 return self::$PAGE_PICWALL;
84 } 85 }
85 86
86 if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) { 87 if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
87 return self::$PAGE_TAGCLOUD; 88 return self::$PAGE_TAGCLOUD;
88 } 89 }
89 90
90 if (startsWith($query, 'do='. self::$PAGE_TAGLIST)) { 91 if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) {
91 return self::$PAGE_TAGLIST; 92 return self::$PAGE_TAGLIST;
92 } 93 }
93 94
94 if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) { 95 if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
95 return self::$PAGE_OPENSEARCH; 96 return self::$PAGE_OPENSEARCH;
96 } 97 }
97 98
98 if (startsWith($query, 'do='. self::$PAGE_DAILY)) { 99 if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
99 return self::$PAGE_DAILY; 100 return self::$PAGE_DAILY;
100 } 101 }
101 102
102 if (startsWith($query, 'do='. self::$PAGE_FEED_ATOM)) { 103 if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) {
103 return self::$PAGE_FEED_ATOM; 104 return self::$PAGE_FEED_ATOM;
104 } 105 }
105 106
106 if (startsWith($query, 'do='. self::$PAGE_FEED_RSS)) { 107 if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) {
107 return self::$PAGE_FEED_RSS; 108 return self::$PAGE_FEED_RSS;
108 } 109 }
109 110
110 if (startsWith($query, 'do='. self::$PAGE_THUMBS_UPDATE)) { 111 if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) {
111 return self::$PAGE_THUMBS_UPDATE; 112 return self::$PAGE_THUMBS_UPDATE;
112 } 113 }
113 114
114 if (startsWith($query, 'do='. self::$AJAX_THUMB_UPDATE)) { 115 if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) {
115 return self::$AJAX_THUMB_UPDATE; 116 return self::$AJAX_THUMB_UPDATE;
116 } 117 }
117 118
@@ -120,23 +121,23 @@ class Router
120 return self::$PAGE_LINKLIST; 121 return self::$PAGE_LINKLIST;
121 } 122 }
122 123
123 if (startsWith($query, 'do='. self::$PAGE_TOOLS)) { 124 if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) {
124 return self::$PAGE_TOOLS; 125 return self::$PAGE_TOOLS;
125 } 126 }
126 127
127 if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) { 128 if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
128 return self::$PAGE_CHANGEPASSWORD; 129 return self::$PAGE_CHANGEPASSWORD;
129 } 130 }
130 131
131 if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) { 132 if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) {
132 return self::$PAGE_CONFIGURE; 133 return self::$PAGE_CONFIGURE;
133 } 134 }
134 135
135 if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) { 136 if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) {
136 return self::$PAGE_CHANGETAG; 137 return self::$PAGE_CHANGETAG;
137 } 138 }
138 139
139 if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) { 140 if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) {
140 return self::$PAGE_ADDLINK; 141 return self::$PAGE_ADDLINK;
141 } 142 }
142 143
@@ -148,27 +149,27 @@ class Router
148 return self::$PAGE_DELETELINK; 149 return self::$PAGE_DELETELINK;
149 } 150 }
150 151
151 if (startsWith($query, 'do='. self::$PAGE_PINLINK)) { 152 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
152 return self::$PAGE_PINLINK; 153 return self::$PAGE_PINLINK;
153 } 154 }
154 155
155 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) { 156 if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) {
156 return self::$PAGE_EXPORT; 157 return self::$PAGE_EXPORT;
157 } 158 }
158 159
159 if (startsWith($query, 'do='. self::$PAGE_IMPORT)) { 160 if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) {
160 return self::$PAGE_IMPORT; 161 return self::$PAGE_IMPORT;
161 } 162 }
162 163
163 if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) { 164 if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) {
164 return self::$PAGE_PLUGINSADMIN; 165 return self::$PAGE_PLUGINSADMIN;
165 } 166 }
166 167
167 if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) { 168 if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) {
168 return self::$PAGE_SAVE_PLUGINSADMIN; 169 return self::$PAGE_SAVE_PLUGINSADMIN;
169 } 170 }
170 171
171 if (startsWith($query, 'do='. self::$GET_TOKEN)) { 172 if (startsWith($query, 'do=' . self::$GET_TOKEN)) {
172 return self::$GET_TOKEN; 173 return self::$GET_TOKEN;
173 } 174 }
174 175
diff --git a/application/Thumbnailer.php b/application/Thumbnailer.php
index 37ed97a1..a23f98e9 100644
--- a/application/Thumbnailer.php
+++ b/application/Thumbnailer.php
@@ -3,9 +3,9 @@
3namespace Shaarli; 3namespace Shaarli;
4 4
5use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use WebThumbnailer\Application\ConfigManager as WTConfigManager;
6use WebThumbnailer\Exception\WebThumbnailerException; 7use WebThumbnailer\Exception\WebThumbnailerException;
7use WebThumbnailer\WebThumbnailer; 8use WebThumbnailer\WebThumbnailer;
8use WebThumbnailer\Application\ConfigManager as WTConfigManager;
9 9
10/** 10/**
11 * Class Thumbnailer 11 * Class Thumbnailer
diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php
index 66eac133..5ffb8c6d 100644
--- a/application/api/ApiMiddleware.php
+++ b/application/api/ApiMiddleware.php
@@ -1,9 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api; 2namespace Shaarli\Api;
3 3
4use Shaarli\Api\Exceptions\ApiException;
5use Shaarli\Api\Exceptions\ApiAuthorizationException; 4use Shaarli\Api\Exceptions\ApiAuthorizationException;
6 5use Shaarli\Api\Exceptions\ApiException;
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
8use Slim\Container; 7use Slim\Container;
9use Slim\Http\Request; 8use Slim\Http\Request;
@@ -127,7 +126,7 @@ class ApiMiddleware
127 */ 126 */
128 protected function setLinkDb($conf) 127 protected function setLinkDb($conf)
129 { 128 {
130 $linkDb = new \LinkDB( 129 $linkDb = new \Shaarli\Bookmark\LinkDB(
131 $conf->get('resource.datastore'), 130 $conf->get('resource.datastore'),
132 true, 131 true,
133 $conf->get('privacy.hide_public_links'), 132 $conf->get('privacy.hide_public_links'),
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index fc5ecaf1..1824b5d0 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api; 2namespace Shaarli\Api;
3 3
4use Shaarli\Base64Url;
5use Shaarli\Api\Exceptions\ApiAuthorizationException; 4use Shaarli\Api\Exceptions\ApiAuthorizationException;
5use Shaarli\Http\Base64Url;
6 6
7/** 7/**
8 * REST API utilities 8 * REST API utilities
@@ -12,7 +12,7 @@ class ApiUtils
12 /** 12 /**
13 * Validates a JWT token authenticity. 13 * Validates a JWT token authenticity.
14 * 14 *
15 * @param string $token JWT token extracted from the headers. 15 * @param string $token JWT token extracted from the headers.
16 * @param string $secret API secret set in the settings. 16 * @param string $secret API secret set in the settings.
17 * 17 *
18 * @throws ApiAuthorizationException the token is not valid. 18 * @throws ApiAuthorizationException the token is not valid.
@@ -50,7 +50,7 @@ class ApiUtils
50 /** 50 /**
51 * Format a Link for the REST API. 51 * Format a Link for the REST API.
52 * 52 *
53 * @param array $link Link data read from the datastore. 53 * @param array $link Link data read from the datastore.
54 * @param string $indexUrl Shaarli's index URL (used for relative URL). 54 * @param string $indexUrl Shaarli's index URL (used for relative URL).
55 * 55 *
56 * @return array Link data formatted for the REST API. 56 * @return array Link data formatted for the REST API.
diff --git a/application/api/controllers/ApiController.php b/application/api/controllers/ApiController.php
index 9edefcf6..a6e7cbab 100644
--- a/application/api/controllers/ApiController.php
+++ b/application/api/controllers/ApiController.php
@@ -2,8 +2,9 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
6use \Slim\Container; 7use Slim\Container;
7 8
8/** 9/**
9 * Abstract Class ApiController 10 * Abstract Class ApiController
@@ -25,12 +26,12 @@ abstract class ApiController
25 protected $conf; 26 protected $conf;
26 27
27 /** 28 /**
28 * @var \LinkDB 29 * @var LinkDB
29 */ 30 */
30 protected $linkDb; 31 protected $linkDb;
31 32
32 /** 33 /**
33 * @var \History 34 * @var HistoryController
34 */ 35 */
35 protected $history; 36 protected $history;
36 37
diff --git a/application/api/controllers/History.php b/application/api/controllers/HistoryController.php
index 4582e8b2..9afcfa26 100644
--- a/application/api/controllers/History.php
+++ b/application/api/controllers/HistoryController.php
@@ -14,7 +14,7 @@ use Slim\Http\Response;
14 * 14 *
15 * @package Shaarli\Api\Controllers 15 * @package Shaarli\Api\Controllers
16 */ 16 */
17class History extends ApiController 17class HistoryController extends ApiController
18{ 18{
19 /** 19 /**
20 * Service providing operation regarding Shaarli datastore and settings. 20 * Service providing operation regarding Shaarli datastore and settings.
diff --git a/application/api/controllers/Tags.php b/application/api/controllers/Tags.php
index 6dd78750..82f3ef74 100644
--- a/application/api/controllers/Tags.php
+++ b/application/api/controllers/Tags.php
@@ -4,7 +4,6 @@ namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Api\ApiUtils; 5use Shaarli\Api\ApiUtils;
6use Shaarli\Api\Exceptions\ApiBadParametersException; 6use Shaarli\Api\Exceptions\ApiBadParametersException;
7use Shaarli\Api\Exceptions\ApiLinkNotFoundException;
8use Shaarli\Api\Exceptions\ApiTagNotFoundException; 7use Shaarli\Api\Exceptions\ApiTagNotFoundException;
9use Slim\Http\Request; 8use Slim\Http\Request;
10use Slim\Http\Response; 9use Slim\Http\Response;
diff --git a/application/api/exceptions/ApiLinkNotFoundException.php b/application/api/exceptions/ApiLinkNotFoundException.php
index c727f4f0..7c2bb56e 100644
--- a/application/api/exceptions/ApiLinkNotFoundException.php
+++ b/application/api/exceptions/ApiLinkNotFoundException.php
@@ -2,8 +2,6 @@
2 2
3namespace Shaarli\Api\Exceptions; 3namespace Shaarli\Api\Exceptions;
4 4
5use Slim\Http\Response;
6
7/** 5/**
8 * Class ApiLinkNotFoundException 6 * Class ApiLinkNotFoundException
9 * 7 *
diff --git a/application/api/exceptions/ApiTagNotFoundException.php b/application/api/exceptions/ApiTagNotFoundException.php
index eee152fe..66ace8bf 100644
--- a/application/api/exceptions/ApiTagNotFoundException.php
+++ b/application/api/exceptions/ApiTagNotFoundException.php
@@ -2,8 +2,6 @@
2 2
3namespace Shaarli\Api\Exceptions; 3namespace Shaarli\Api\Exceptions;
4 4
5use Slim\Http\Response;
6
7/** 5/**
8 * Class ApiTagNotFoundException 6 * Class ApiTagNotFoundException
9 * 7 *
diff --git a/application/LinkDB.php b/application/bookmark/LinkDB.php
index 4bbc2950..c13a1141 100644
--- a/application/LinkDB.php
+++ b/application/bookmark/LinkDB.php
@@ -1,4 +1,15 @@
1<?php 1<?php
2
3namespace Shaarli\Bookmark;
4
5use ArrayAccess;
6use Countable;
7use DateTime;
8use Iterator;
9use Shaarli\Bookmark\Exception\LinkNotFoundException;
10use Shaarli\Exceptions\IOException;
11use Shaarli\FileUtils;
12
2/** 13/**
3 * Data storage for links. 14 * Data storage for links.
4 * 15 *
@@ -108,6 +119,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess
108 $redirector = '', 119 $redirector = '',
109 $redirectorEncode = true 120 $redirectorEncode = true
110 ) { 121 ) {
122
111 $this->datastore = $datastore; 123 $this->datastore = $datastore;
112 $this->loggedIn = $isLoggedIn; 124 $this->loggedIn = $isLoggedIn;
113 $this->hidePublicLinks = $hidePublicLinks; 125 $this->hidePublicLinks = $hidePublicLinks;
@@ -137,7 +149,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess
137 if (!isset($value['id']) || empty($value['url'])) { 149 if (!isset($value['id']) || empty($value['url'])) {
138 die(t('Internal Error: A link should always have an id and URL.')); 150 die(t('Internal Error: A link should always have an id and URL.'));
139 } 151 }
140 if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) { 152 if (($offset !== null && !is_int($offset)) || !is_int($value['id'])) {
141 die(t('You must specify an integer as a key.')); 153 die(t('You must specify an integer as a key.'));
142 } 154 }
143 if ($offset !== null && $offset !== $value['id']) { 155 if ($offset !== null && $offset !== $value['id']) {
@@ -247,31 +259,31 @@ class LinkDB implements Iterator, Countable, ArrayAccess
247 $this->links = array(); 259 $this->links = array();
248 $link = array( 260 $link = array(
249 'id' => 1, 261 'id' => 1,
250 'title'=> t('The personal, minimalist, super-fast, database free, bookmarking service'), 262 'title' => t('The personal, minimalist, super-fast, database free, bookmarking service'),
251 'url'=>'https://shaarli.readthedocs.io', 263 'url' => 'https://shaarli.readthedocs.io',
252 'description'=>t( 264 'description' => t(
253 'Welcome to Shaarli! This is your first public bookmark. ' 265 'Welcome to Shaarli! This is your first public bookmark. '
254 .'To edit or delete me, you must first login. 266 . 'To edit or delete me, you must first login.
255 267
256To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page. 268To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page.
257 269
258You use the community supported version of the original Shaarli project, by Sebastien Sauvage.' 270You use the community supported version of the original Shaarli project, by Sebastien Sauvage.'
259 ), 271 ),
260 'private'=>0, 272 'private' => 0,
261 'created'=> new DateTime(), 273 'created' => new DateTime(),
262 'tags'=>'opensource software' 274 'tags' => 'opensource software'
263 ); 275 );
264 $link['shorturl'] = link_small_hash($link['created'], $link['id']); 276 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
265 $this->links[1] = $link; 277 $this->links[1] = $link;
266 278
267 $link = array( 279 $link = array(
268 'id' => 0, 280 'id' => 0,
269 'title'=> t('My secret stuff... - Pastebin.com'), 281 'title' => t('My secret stuff... - Pastebin.com'),
270 'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', 282 'url' => 'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=',
271 'description'=> t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'), 283 'description' => t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'),
272 'private'=>1, 284 'private' => 1,
273 'created'=> new DateTime('1 minute ago'), 285 'created' => new DateTime('1 minute ago'),
274 'tags'=>'secretstuff', 286 'tags' => 'secretstuff',
275 ); 287 );
276 $link['shorturl'] = link_small_hash($link['created'], $link['id']); 288 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
277 $this->links[0] = $link; 289 $this->links[0] = $link;
@@ -297,7 +309,7 @@ You use the community supported version of the original Shaarli project, by Seba
297 309
298 $toremove = array(); 310 $toremove = array();
299 foreach ($this->links as $key => &$link) { 311 foreach ($this->links as $key => &$link) {
300 if (! $this->loggedIn && $link['private'] != 0) { 312 if (!$this->loggedIn && $link['private'] != 0) {
301 // Transition for not upgraded databases. 313 // Transition for not upgraded databases.
302 unset($this->links[$key]); 314 unset($this->links[$key]);
303 continue; 315 continue;
@@ -307,7 +319,7 @@ You use the community supported version of the original Shaarli project, by Seba
307 sanitizeLink($link); 319 sanitizeLink($link);
308 320
309 // Remove private tags if the user is not logged in. 321 // Remove private tags if the user is not logged in.
310 if (! $this->loggedIn) { 322 if (!$this->loggedIn) {
311 $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']); 323 $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']);
312 } 324 }
313 325
@@ -324,10 +336,10 @@ You use the community supported version of the original Shaarli project, by Seba
324 } 336 }
325 337
326 // To be able to load links before running the update, and prepare the update 338 // To be able to load links before running the update, and prepare the update
327 if (! isset($link['created'])) { 339 if (!isset($link['created'])) {
328 $link['id'] = $link['linkdate']; 340 $link['id'] = $link['linkdate'];
329 $link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']); 341 $link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']);
330 if (! empty($link['updated'])) { 342 if (!empty($link['updated'])) {
331 $link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']); 343 $link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']);
332 } 344 }
333 $link['shorturl'] = smallHash($link['linkdate']); 345 $link['shorturl'] = smallHash($link['linkdate']);
@@ -413,12 +425,12 @@ You use the community supported version of the original Shaarli project, by Seba
413 /** 425 /**
414 * Filter links according to search parameters. 426 * Filter links according to search parameters.
415 * 427 *
416 * @param array $filterRequest Search request content. Supported keys: 428 * @param array $filterRequest Search request content. Supported keys:
417 * - searchtags: list of tags 429 * - searchtags: list of tags
418 * - searchterm: term search 430 * - searchterm: term search
419 * @param bool $casesensitive Optional: Perform case sensitive filter 431 * @param bool $casesensitive Optional: Perform case sensitive filter
420 * @param string $visibility return only all/private/public links 432 * @param string $visibility return only all/private/public links
421 * @param string $untaggedonly return only untagged links 433 * @param bool $untaggedonly return only untagged links
422 * 434 *
423 * @return array filtered links, all links if no suitable filter was provided. 435 * @return array filtered links, all links if no suitable filter was provided.
424 */ 436 */
@@ -428,6 +440,7 @@ You use the community supported version of the original Shaarli project, by Seba
428 $visibility = 'all', 440 $visibility = 'all',
429 $untaggedonly = false 441 $untaggedonly = false
430 ) { 442 ) {
443
431 // Filter link database according to parameters. 444 // Filter link database according to parameters.
432 $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; 445 $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : '';
433 $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; 446 $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : '';
@@ -443,8 +456,8 @@ You use the community supported version of the original Shaarli project, by Seba
443 /** 456 /**
444 * Returns the list tags appearing in the links with the given tags 457 * Returns the list tags appearing in the links with the given tags
445 * 458 *
446 * @param array $filteringTags tags selecting the links to consider 459 * @param array $filteringTags tags selecting the links to consider
447 * @param string $visibility process only all/private/public links 460 * @param string $visibility process only all/private/public links
448 * 461 *
449 * @return array tag => linksCount 462 * @return array tag => linksCount
450 */ 463 */
diff --git a/application/LinkFilter.php b/application/bookmark/LinkFilter.php
index 8f147974..9b966307 100644
--- a/application/LinkFilter.php
+++ b/application/bookmark/LinkFilter.php
@@ -1,5 +1,10 @@
1<?php 1<?php
2 2
3namespace Shaarli\Bookmark;
4
5use Exception;
6use Shaarli\Bookmark\Exception\LinkNotFoundException;
7
3/** 8/**
4 * Class LinkFilter. 9 * Class LinkFilter.
5 * 10 *
@@ -10,22 +15,22 @@ class LinkFilter
10 /** 15 /**
11 * @var string permalinks. 16 * @var string permalinks.
12 */ 17 */
13 public static $FILTER_HASH = 'permalink'; 18 public static $FILTER_HASH = 'permalink';
14 19
15 /** 20 /**
16 * @var string text search. 21 * @var string text search.
17 */ 22 */
18 public static $FILTER_TEXT = 'fulltext'; 23 public static $FILTER_TEXT = 'fulltext';
19 24
20 /** 25 /**
21 * @var string tag filter. 26 * @var string tag filter.
22 */ 27 */
23 public static $FILTER_TAG = 'tags'; 28 public static $FILTER_TAG = 'tags';
24 29
25 /** 30 /**
26 * @var string filter by day. 31 * @var string filter by day.
27 */ 32 */
28 public static $FILTER_DAY = 'FILTER_DAY'; 33 public static $FILTER_DAY = 'FILTER_DAY';
29 34
30 /** 35 /**
31 * @var string Allowed characters for hashtags (regex syntax). 36 * @var string Allowed characters for hashtags (regex syntax).
@@ -58,7 +63,7 @@ class LinkFilter
58 */ 63 */
59 public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false) 64 public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
60 { 65 {
61 if (! in_array($visibility, ['all', 'public', 'private'])) { 66 if (!in_array($visibility, ['all', 'public', 'private'])) {
62 $visibility = 'all'; 67 $visibility = 'all';
63 } 68 }
64 69
@@ -117,7 +122,7 @@ class LinkFilter
117 foreach ($this->links as $key => $value) { 122 foreach ($this->links as $key => $value) {
118 if ($value['private'] && $visibility === 'private') { 123 if ($value['private'] && $visibility === 'private') {
119 $out[$key] = $value; 124 $out[$key] = $value;
120 } elseif (! $value['private'] && $visibility === 'public') { 125 } elseif (!$value['private'] && $visibility === 'public') {
121 $out[$key] = $value; 126 $out[$key] = $value;
122 } 127 }
123 } 128 }
@@ -132,7 +137,7 @@ class LinkFilter
132 * 137 *
133 * @return array $filtered array containing permalink data. 138 * @return array $filtered array containing permalink data.
134 * 139 *
135 * @throws LinkNotFoundException if the smallhash doesn't match any link. 140 * @throws \Shaarli\Bookmark\Exception\LinkNotFoundException if the smallhash doesn't match any link.
136 */ 141 */
137 private function filterSmallHash($smallHash) 142 private function filterSmallHash($smallHash)
138 { 143 {
@@ -169,7 +174,7 @@ class LinkFilter
169 * - see https://github.com/shaarli/Shaarli/issues/75 for examples 174 * - see https://github.com/shaarli/Shaarli/issues/75 for examples
170 * 175 *
171 * @param string $searchterms search query. 176 * @param string $searchterms search query.
172 * @param string $visibility Optional: return only all/private/public links. 177 * @param string $visibility Optional: return only all/private/public links.
173 * 178 *
174 * @return array search results. 179 * @return array search results.
175 */ 180 */
@@ -207,7 +212,7 @@ class LinkFilter
207 foreach ($this->links as $id => $link) { 212 foreach ($this->links as $id => $link) {
208 // ignore non private links when 'privatonly' is on. 213 // ignore non private links when 'privatonly' is on.
209 if ($visibility !== 'all') { 214 if ($visibility !== 'all') {
210 if (! $link['private'] && $visibility === 'private') { 215 if (!$link['private'] && $visibility === 'private') {
211 continue; 216 continue;
212 } elseif ($link['private'] && $visibility === 'public') { 217 } elseif ($link['private'] && $visibility === 'public') {
213 continue; 218 continue;
@@ -250,7 +255,9 @@ class LinkFilter
250 255
251 /** 256 /**
252 * generate a regex fragment out of a tag 257 * generate a regex fragment out of a tag
258 *
253 * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard 259 * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
260 *
254 * @return string generated regex fragment 261 * @return string generated regex fragment
255 */ 262 */
256 private static function tag2regex($tag) 263 private static function tag2regex($tag)
@@ -334,7 +341,7 @@ class LinkFilter
334 // check level of visibility 341 // check level of visibility
335 // ignore non private links when 'privateonly' is on. 342 // ignore non private links when 'privateonly' is on.
336 if ($visibility !== 'all') { 343 if ($visibility !== 'all') {
337 if (! $link['private'] && $visibility === 'private') { 344 if (!$link['private'] && $visibility === 'private') {
338 continue; 345 continue;
339 } elseif ($link['private'] && $visibility === 'public') { 346 } elseif ($link['private'] && $visibility === 'public') {
340 continue; 347 continue;
@@ -377,7 +384,7 @@ class LinkFilter
377 $filtered = []; 384 $filtered = [];
378 foreach ($this->links as $key => $link) { 385 foreach ($this->links as $key => $link) {
379 if ($visibility !== 'all') { 386 if ($visibility !== 'all') {
380 if (! $link['private'] && $visibility === 'private') { 387 if (!$link['private'] && $visibility === 'private') {
381 continue; 388 continue;
382 } elseif ($link['private'] && $visibility === 'public') { 389 } elseif ($link['private'] && $visibility === 'public') {
383 continue; 390 continue;
@@ -406,7 +413,7 @@ class LinkFilter
406 */ 413 */
407 public function filterDay($day) 414 public function filterDay($day)
408 { 415 {
409 if (! checkDateFormat('Ymd', $day)) { 416 if (!checkDateFormat('Ymd', $day)) {
410 throw new Exception('Invalid date format'); 417 throw new Exception('Invalid date format');
411 } 418 }
412 419
@@ -440,14 +447,3 @@ class LinkFilter
440 return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY); 447 return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
441 } 448 }
442} 449}
443
444class LinkNotFoundException extends Exception
445{
446 /**
447 * LinkNotFoundException constructor.
448 */
449 public function __construct()
450 {
451 $this->message = t('The link you are trying to reach does not exist or has been deleted.');
452 }
453}
diff --git a/application/LinkUtils.php b/application/bookmark/LinkUtils.php
index d56e019f..de5b61cb 100644
--- a/application/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -1,11 +1,13 @@
1<?php 1<?php
2 2
3use Shaarli\Bookmark\LinkDB;
4
3/** 5/**
4 * Get cURL callback function for CURLOPT_WRITEFUNCTION 6 * Get cURL callback function for CURLOPT_WRITEFUNCTION
5 * 7 *
6 * @param string $charset to extract from the downloaded page (reference) 8 * @param string $charset to extract from the downloaded page (reference)
7 * @param string $title to extract from the downloaded page (reference) 9 * @param string $title to extract from the downloaded page (reference)
8 * @param string $curlGetInfo Optionnaly overrides curl_getinfo function 10 * @param string $curlGetInfo Optionally overrides curl_getinfo function
9 * 11 *
10 * @return Closure 12 * @return Closure
11 */ 13 */
@@ -196,7 +198,7 @@ function space2nbsp($text)
196 * 198 *
197 * @param string $description shaare's description. 199 * @param string $description shaare's description.
198 * @param string $redirector if a redirector is set, use it to gerenate links. 200 * @param string $redirector if a redirector is set, use it to gerenate links.
199 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. 201 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
200 * @param string $indexUrl URL to Shaarli's index. 202 * @param string $indexUrl URL to Shaarli's index.
201 203
202 * @return string formatted description. 204 * @return string formatted description.
diff --git a/application/bookmark/exception/LinkNotFoundException.php b/application/bookmark/exception/LinkNotFoundException.php
new file mode 100644
index 00000000..f9414428
--- /dev/null
+++ b/application/bookmark/exception/LinkNotFoundException.php
@@ -0,0 +1,15 @@
1<?php
2namespace Shaarli\Bookmark\Exception;
3
4use Exception;
5
6class LinkNotFoundException extends Exception
7{
8 /**
9 * LinkNotFoundException constructor.
10 */
11 public function __construct()
12 {
13 $this->message = t('The link you are trying to reach does not exist or has been deleted.');
14 }
15}
diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php
index 8c8d5610..4509357c 100644
--- a/application/config/ConfigJson.php
+++ b/application/config/ConfigJson.php
@@ -47,7 +47,7 @@ class ConfigJson implements ConfigIO
47 $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; 47 $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
48 $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); 48 $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
49 if (!file_put_contents($filepath, $data)) { 49 if (!file_put_contents($filepath, $data)) {
50 throw new \IOException( 50 throw new \Shaarli\Exceptions\IOException(
51 $filepath, 51 $filepath,
52 t('Shaarli could not create the config file. '. 52 t('Shaarli could not create the config file. '.
53 'Please make sure Shaarli has the right to write in the folder is it installed in.') 53 'Please make sure Shaarli has the right to write in the folder is it installed in.')
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index 32aaea48..e6c35073 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -207,7 +207,7 @@ class ConfigManager
207 * 207 *
208 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. 208 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
209 * @throws UnauthorizedConfigException: user is not authorize to change configuration. 209 * @throws UnauthorizedConfigException: user is not authorize to change configuration.
210 * @throws \IOException: an error occurred while writing the new config file. 210 * @throws \Shaarli\Exceptions\IOException: an error occurred while writing the new config file.
211 */ 211 */
212 public function write($isLoggedIn) 212 public function write($isLoggedIn)
213 { 213 {
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php
index 9625fe1a..cad34594 100644
--- a/application/config/ConfigPhp.php
+++ b/application/config/ConfigPhp.php
@@ -27,7 +27,7 @@ class ConfigPhp implements ConfigIO
27 /** 27 /**
28 * Map legacy config keys with the new ones. 28 * Map legacy config keys with the new ones.
29 * If ConfigPhp is used, getting <newkey> will actually look for <legacykey>. 29 * If ConfigPhp is used, getting <newkey> will actually look for <legacykey>.
30 * The Updater will use this array to transform keys when switching to JSON. 30 * The updater will use this array to transform keys when switching to JSON.
31 * 31 *
32 * @var array current key => legacy key. 32 * @var array current key => legacy key.
33 */ 33 */
@@ -124,7 +124,7 @@ class ConfigPhp implements ConfigIO
124 if (!file_put_contents($filepath, $configStr) 124 if (!file_put_contents($filepath, $configStr)
125 || strcmp(file_get_contents($filepath), $configStr) != 0 125 || strcmp(file_get_contents($filepath), $configStr) != 0
126 ) { 126 ) {
127 throw new \IOException( 127 throw new \Shaarli\Exceptions\IOException(
128 $filepath, 128 $filepath,
129 t('Shaarli could not create the config file. '. 129 t('Shaarli could not create the config file. '.
130 'Please make sure Shaarli has the right to write in the folder is it installed in.') 130 'Please make sure Shaarli has the right to write in the folder is it installed in.')
diff --git a/application/exceptions/IOException.php b/application/exceptions/IOException.php
index 18e46b77..2aa25e5c 100644
--- a/application/exceptions/IOException.php
+++ b/application/exceptions/IOException.php
@@ -1,4 +1,7 @@
1<?php 1<?php
2namespace Shaarli\Exceptions;
3
4use Exception;
2 5
3/** 6/**
4 * Exception class thrown when a filesystem access failure happens 7 * Exception class thrown when a filesystem access failure happens
@@ -17,6 +20,6 @@ class IOException extends Exception
17 { 20 {
18 $this->path = $path; 21 $this->path = $path;
19 $this->message = empty($message) ? t('Error accessing') : $message; 22 $this->message = empty($message) ? t('Error accessing') : $message;
20 $this->message .= ' "' . $this->path .'"'; 23 $this->message .= ' "' . $this->path . '"';
21 } 24 }
22} 25}
diff --git a/application/Cache.php b/application/feed/Cache.php
index e5d43e61..e5d43e61 100644
--- a/application/Cache.php
+++ b/application/feed/Cache.php
diff --git a/application/CachedPage.php b/application/feed/CachedPage.php
index e11cc52d..d809bdd9 100644
--- a/application/CachedPage.php
+++ b/application/feed/CachedPage.php
@@ -1,4 +1,7 @@
1<?php 1<?php
2
3namespace Shaarli\Feed;
4
2/** 5/**
3 * Simple cache system, mainly for the RSS/ATOM feeds 6 * Simple cache system, mainly for the RSS/ATOM feeds
4 */ 7 */
@@ -24,7 +27,7 @@ class CachedPage
24 { 27 {
25 // TODO: check write access to the cache directory 28 // TODO: check write access to the cache directory
26 $this->cacheDir = $cacheDir; 29 $this->cacheDir = $cacheDir;
27 $this->filename = $this->cacheDir.'/'.sha1($url).'.cache'; 30 $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache';
28 $this->shouldBeCached = $shouldBeCached; 31 $this->shouldBeCached = $shouldBeCached;
29 } 32 }
30 33
diff --git a/application/FeedBuilder.php b/application/feed/FeedBuilder.php
index 73fafcbe..b66f2f91 100644
--- a/application/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -1,4 +1,7 @@
1<?php 1<?php
2namespace Shaarli\Feed;
3
4use DateTime;
2 5
3/** 6/**
4 * FeedBuilder class. 7 * FeedBuilder class.
@@ -28,7 +31,7 @@ class FeedBuilder
28 public static $DEFAULT_NB_LINKS = 50; 31 public static $DEFAULT_NB_LINKS = 50;
29 32
30 /** 33 /**
31 * @var LinkDB instance. 34 * @var \Shaarli\Bookmark\LinkDB instance.
32 */ 35 */
33 protected $linkDB; 36 protected $linkDB;
34 37
@@ -38,12 +41,12 @@ class FeedBuilder
38 protected $feedType; 41 protected $feedType;
39 42
40 /** 43 /**
41 * @var array $_SERVER. 44 * @var array $_SERVER
42 */ 45 */
43 protected $serverInfo; 46 protected $serverInfo;
44 47
45 /** 48 /**
46 * @var array $_GET. 49 * @var array $_GET
47 */ 50 */
48 protected $userInput; 51 protected $userInput;
49 52
@@ -75,11 +78,12 @@ class FeedBuilder
75 /** 78 /**
76 * Feed constructor. 79 * Feed constructor.
77 * 80 *
78 * @param LinkDB $linkDB LinkDB instance. 81 * @param \Shaarli\Bookmark\LinkDB $linkDB LinkDB instance.
79 * @param string $feedType Type of feed. 82 * @param string $feedType Type of feed.
80 * @param array $serverInfo $_SERVER. 83 * @param array $serverInfo $_SERVER.
81 * @param array $userInput $_GET. 84 * @param array $userInput $_GET.
82 * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise. 85 * @param boolean $isLoggedIn True if the user is currently logged in,
86 * false otherwise.
83 */ 87 */
84 public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn) 88 public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn)
85 { 89 {
@@ -124,7 +128,7 @@ class FeedBuilder
124 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; 128 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
125 // Remove leading slash from REQUEST_URI. 129 // Remove leading slash from REQUEST_URI.
126 $data['self_link'] = escape(server_url($this->serverInfo)) 130 $data['self_link'] = escape(server_url($this->serverInfo))
127 . escape($this->serverInfo['REQUEST_URI']); 131 . escape($this->serverInfo['REQUEST_URI']);
128 $data['index_url'] = $pageaddr; 132 $data['index_url'] = $pageaddr;
129 $data['usepermalinks'] = $this->usePermalinks === true; 133 $data['usepermalinks'] = $this->usePermalinks === true;
130 $data['links'] = $linkDisplayed; 134 $data['links'] = $linkDisplayed;
@@ -142,18 +146,18 @@ class FeedBuilder
142 */ 146 */
143 protected function buildItem($link, $pageaddr) 147 protected function buildItem($link, $pageaddr)
144 { 148 {
145 $link['guid'] = $pageaddr .'?'. $link['shorturl']; 149 $link['guid'] = $pageaddr . '?' . $link['shorturl'];
146 // Check for both signs of a note: starting with ? and 7 chars long. 150 // Check for both signs of a note: starting with ? and 7 chars long.
147 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 151 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
148 $link['url'] = $pageaddr . $link['url']; 152 $link['url'] = $pageaddr . $link['url'];
149 } 153 }
150 if ($this->usePermalinks === true) { 154 if ($this->usePermalinks === true) {
151 $permalink = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>'; 155 $permalink = '<a href="' . $link['url'] . '" title="' . t('Direct link') . '">' . t('Direct link') . '</a>';
152 } else { 156 } else {
153 $permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>'; 157 $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
154 } 158 }
155 $link['description'] = format_description($link['description'], '', false, $pageaddr); 159 $link['description'] = format_description($link['description'], '', false, $pageaddr);
156 $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink; 160 $link['description'] .= PHP_EOL . '<br>&#8212; ' . $permalink;
157 161
158 $pubDate = $link['created']; 162 $pubDate = $link['created'];
159 $link['pub_iso_date'] = $this->getIsoDate($pubDate); 163 $link['pub_iso_date'] = $this->getIsoDate($pubDate);
@@ -164,7 +168,6 @@ class FeedBuilder
164 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); 168 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
165 } else { 169 } else {
166 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM); 170 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
167 ;
168 } 171 }
169 172
170 // Save the more recent item. 173 // Save the more recent item.
@@ -223,11 +226,11 @@ class FeedBuilder
223 public function getTypeLanguage() 226 public function getTypeLanguage()
224 { 227 {
225 // Use the locale do define the language, if available. 228 // Use the locale do define the language, if available.
226 if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { 229 if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) {
227 $length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; 230 $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2;
228 return str_replace('_', '-', substr($this->locale, 0, $length)); 231 return str_replace('_', '-', substr($this->locale, 0, $length));
229 } 232 }
230 return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en'; 233 return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en';
231 } 234 }
232 235
233 /** 236 /**
@@ -287,7 +290,7 @@ class FeedBuilder
287 } 290 }
288 291
289 $intNb = intval($this->userInput['nb']); 292 $intNb = intval($this->userInput['nb']);
290 if (! is_int($intNb) || $intNb == 0) { 293 if (!is_int($intNb) || $intNb == 0) {
291 return self::$DEFAULT_NB_LINKS; 294 return self::$DEFAULT_NB_LINKS;
292 } 295 }
293 296
diff --git a/application/Base64Url.php b/application/http/Base64Url.php
index 54d0fcd5..33fa7c1f 100644
--- a/application/Base64Url.php
+++ b/application/http/Base64Url.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Shaarli; 3namespace Shaarli\Http;
4 4
5/** 5/**
6 * URL-safe Base64 operations 6 * URL-safe Base64 operations
diff --git a/application/HttpUtils.php b/application/http/HttpUtils.php
index 9c438160..2ea9195d 100644
--- a/application/HttpUtils.php
+++ b/application/http/HttpUtils.php
@@ -1,4 +1,7 @@
1<?php 1<?php
2
3use Shaarli\Http\Url;
4
2/** 5/**
3 * GET an HTTP URL to retrieve its content 6 * GET an HTTP URL to retrieve its content
4 * Uses the cURL library or a fallback method 7 * Uses the cURL library or a fallback method
@@ -38,7 +41,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF
38 $cleanUrl = $urlObj->idnToAscii(); 41 $cleanUrl = $urlObj->idnToAscii();
39 42
40 if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) { 43 if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
41 return array(array(0 => 'Invalid HTTP Url'), false); 44 return array(array(0 => 'Invalid HTTP UrlUtils'), false);
42 } 45 }
43 46
44 $userAgent = 47 $userAgent =
diff --git a/application/Url.php b/application/http/Url.php
index 3b7f19c2..90444a2f 100644
--- a/application/Url.php
+++ b/application/http/Url.php
@@ -1,91 +1,6 @@
1<?php 1<?php
2/**
3 * Converts an array-represented URL to a string
4 *
5 * Source: http://php.net/manual/en/function.parse-url.php#106731
6 *
7 * @see http://php.net/manual/en/function.parse-url.php
8 *
9 * @param array $parsedUrl an array-represented URL
10 *
11 * @return string the string representation of the URL
12 */
13function unparse_url($parsedUrl)
14{
15 $scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
16 $host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
17 $port = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
18 $user = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
19 $pass = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass'] : '';
20 $pass = ($user || $pass) ? "$pass@" : '';
21 $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
22 $query = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
23 $fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
24 2
25 return "$scheme$user$pass$host$port$path$query$fragment"; 3namespace Shaarli\Http;
26}
27
28/**
29 * Removes undesired query parameters and fragments
30 *
31 * @param string url Url to be cleaned
32 *
33 * @return string the string representation of this URL after cleanup
34 */
35function cleanup_url($url)
36{
37 $obj_url = new Url($url);
38 return $obj_url->cleanup();
39}
40
41/**
42 * Get URL scheme.
43 *
44 * @param string url Url for which the scheme is requested
45 *
46 * @return mixed the URL scheme or false if none is provided.
47 */
48function get_url_scheme($url)
49{
50 $obj_url = new Url($url);
51 return $obj_url->getScheme();
52}
53
54/**
55 * Adds a trailing slash at the end of URL if necessary.
56 *
57 * @param string $url URL to check/edit.
58 *
59 * @return string $url URL with a end trailing slash.
60 */
61function add_trailing_slash($url)
62{
63 return $url . (!endsWith($url, '/') ? '/' : '');
64}
65
66/**
67 * Replace not whitelisted protocols by 'http://' from given URL.
68 *
69 * @param string $url URL to clean
70 * @param array $protocols List of allowed protocols (aside from http(s)).
71 *
72 * @return string URL with allowed protocol
73 */
74function whitelist_protocols($url, $protocols)
75{
76 if (startsWith($url, '?') || startsWith($url, '/')) {
77 return $url;
78 }
79 $protocols = array_merge(['http', 'https'], $protocols);
80 $protocol = preg_match('#^(\w+):/?/?#', $url, $match);
81 // Protocol not allowed: we remove it and replace it with http
82 if ($protocol === 1 && ! in_array($match[1], $protocols)) {
83 $url = str_replace($match[0], 'http://', $url);
84 } elseif ($protocol !== 1) {
85 $url = 'http://' . $url;
86 }
87 return $url;
88}
89 4
90/** 5/**
91 * URL representation and cleanup utilities 6 * URL representation and cleanup utilities
@@ -182,7 +97,7 @@ class Url
182 } 97 }
183 return $input; 98 return $input;
184 } 99 }
185 100
186 /** 101 /**
187 * Returns a string representation of this URL 102 * Returns a string representation of this URL
188 */ 103 */
@@ -196,7 +111,7 @@ class Url
196 */ 111 */
197 protected function cleanupQuery() 112 protected function cleanupQuery()
198 { 113 {
199 if (! isset($this->parts['query'])) { 114 if (!isset($this->parts['query'])) {
200 return; 115 return;
201 } 116 }
202 117
@@ -224,7 +139,7 @@ class Url
224 */ 139 */
225 protected function cleanupFragment() 140 protected function cleanupFragment()
226 { 141 {
227 if (! isset($this->parts['fragment'])) { 142 if (!isset($this->parts['fragment'])) {
228 return; 143 return;
229 } 144 }
230 145
@@ -257,7 +172,7 @@ class Url
257 public function idnToAscii() 172 public function idnToAscii()
258 { 173 {
259 $out = $this->cleanup(); 174 $out = $this->cleanup();
260 if (! function_exists('idn_to_ascii') || ! isset($this->parts['host'])) { 175 if (!function_exists('idn_to_ascii') || !isset($this->parts['host'])) {
261 return $out; 176 return $out;
262 } 177 }
263 $asciiHost = idn_to_ascii($this->parts['host'], 0, INTL_IDNA_VARIANT_UTS46); 178 $asciiHost = idn_to_ascii($this->parts['host'], 0, INTL_IDNA_VARIANT_UTS46);
@@ -291,7 +206,7 @@ class Url
291 } 206 }
292 207
293 /** 208 /**
294 * Test if the Url is an HTTP one. 209 * Test if the UrlUtils is an HTTP one.
295 * 210 *
296 * @return true is HTTP, false otherwise. 211 * @return true is HTTP, false otherwise.
297 */ 212 */
diff --git a/application/http/UrlUtils.php b/application/http/UrlUtils.php
new file mode 100644
index 00000000..4bc84b82
--- /dev/null
+++ b/application/http/UrlUtils.php
@@ -0,0 +1,88 @@
1<?php
2/**
3 * Converts an array-represented URL to a string
4 *
5 * Source: http://php.net/manual/en/function.parse-url.php#106731
6 *
7 * @see http://php.net/manual/en/function.parse-url.php
8 *
9 * @param array $parsedUrl an array-represented URL
10 *
11 * @return string the string representation of the URL
12 */
13function unparse_url($parsedUrl)
14{
15 $scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'].'://' : '';
16 $host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
17 $port = isset($parsedUrl['port']) ? ':'.$parsedUrl['port'] : '';
18 $user = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
19 $pass = isset($parsedUrl['pass']) ? ':'.$parsedUrl['pass'] : '';
20 $pass = ($user || $pass) ? "$pass@" : '';
21 $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
22 $query = isset($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '';
23 $fragment = isset($parsedUrl['fragment']) ? '#'.$parsedUrl['fragment'] : '';
24
25 return "$scheme$user$pass$host$port$path$query$fragment";
26}
27
28/**
29 * Removes undesired query parameters and fragments
30 *
31 * @param string url UrlUtils to be cleaned
32 *
33 * @return string the string representation of this URL after cleanup
34 */
35function cleanup_url($url)
36{
37 $obj_url = new \Shaarli\Http\Url($url);
38 return $obj_url->cleanup();
39}
40
41/**
42 * Get URL scheme.
43 *
44 * @param string url UrlUtils for which the scheme is requested
45 *
46 * @return mixed the URL scheme or false if none is provided.
47 */
48function get_url_scheme($url)
49{
50 $obj_url = new \Shaarli\Http\Url($url);
51 return $obj_url->getScheme();
52}
53
54/**
55 * Adds a trailing slash at the end of URL if necessary.
56 *
57 * @param string $url URL to check/edit.
58 *
59 * @return string $url URL with a end trailing slash.
60 */
61function add_trailing_slash($url)
62{
63 return $url . (!endsWith($url, '/') ? '/' : '');
64}
65
66/**
67 * Replace not whitelisted protocols by 'http://' from given URL.
68 *
69 * @param string $url URL to clean
70 * @param array $protocols List of allowed protocols (aside from http(s)).
71 *
72 * @return string URL with allowed protocol
73 */
74function whitelist_protocols($url, $protocols)
75{
76 if (startsWith($url, '?') || startsWith($url, '/')) {
77 return $url;
78 }
79 $protocols = array_merge(['http', 'https'], $protocols);
80 $protocol = preg_match('#^(\w+):/?/?#', $url, $match);
81 // Protocol not allowed: we remove it and replace it with http
82 if ($protocol === 1 && ! in_array($match[1], $protocols)) {
83 $url = str_replace($match[0], 'http://', $url);
84 } elseif ($protocol !== 1) {
85 $url = 'http://' . $url;
86 }
87 return $url;
88}
diff --git a/application/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php
index 84dd2b20..2fb1a4a6 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/netscape/NetscapeBookmarkUtils.php
@@ -1,9 +1,16 @@
1<?php 1<?php
2 2
3namespace Shaarli\Netscape;
4
5use DateTime;
6use DateTimeZone;
7use Exception;
8use Katzgrau\KLogger\Logger;
3use Psr\Log\LogLevel; 9use Psr\Log\LogLevel;
10use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 11use Shaarli\Config\ConfigManager;
12use Shaarli\History;
5use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser; 13use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
6use Katzgrau\KLogger\Logger;
7 14
8/** 15/**
9 * Utilities to import and export bookmarks using the Netscape format 16 * Utilities to import and export bookmarks using the Netscape format
@@ -31,8 +38,8 @@ class NetscapeBookmarkUtils
31 public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl) 38 public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl)
32 { 39 {
33 // see tpl/export.html for possible values 40 // see tpl/export.html for possible values
34 if (! in_array($selection, array('all', 'public', 'private'))) { 41 if (!in_array($selection, array('all', 'public', 'private'))) {
35 throw new Exception(t('Invalid export selection:') .' "'.$selection.'"'); 42 throw new Exception(t('Invalid export selection:') . ' "' . $selection . '"');
36 } 43 }
37 44
38 $bookmarkLinks = array(); 45 $bookmarkLinks = array();
@@ -84,7 +91,7 @@ class NetscapeBookmarkUtils
84 $status .= vsprintf( 91 $status .= vsprintf(
85 t( 92 t(
86 'was successfully processed in %d seconds: ' 93 'was successfully processed in %d seconds: '
87 .'%d links imported, %d links overwritten, %d links skipped.' 94 . '%d links imported, %d links overwritten, %d links skipped.'
88 ), 95 ),
89 [$duration, $importCount, $overwriteCount, $skipCount] 96 [$duration, $importCount, $overwriteCount, $skipCount]
90 ); 97 );
@@ -95,11 +102,11 @@ class NetscapeBookmarkUtils
95 /** 102 /**
96 * Imports Web bookmarks from an uploaded Netscape bookmark dump 103 * Imports Web bookmarks from an uploaded Netscape bookmark dump
97 * 104 *
98 * @param array $post Server $_POST parameters 105 * @param array $post Server $_POST parameters
99 * @param array $files Server $_FILES parameters 106 * @param array $files Server $_FILES parameters
100 * @param LinkDB $linkDb Loaded LinkDB instance 107 * @param LinkDB $linkDb Loaded LinkDB instance
101 * @param ConfigManager $conf instance 108 * @param ConfigManager $conf instance
102 * @param History $history History instance 109 * @param History $history History instance
103 * 110 *
104 * @return string Summary of the bookmark import status 111 * @return string Summary of the bookmark import status
105 */ 112 */
@@ -115,7 +122,7 @@ class NetscapeBookmarkUtils
115 } 122 }
116 123
117 // Overwrite existing links? 124 // Overwrite existing links?
118 $overwrite = ! empty($post['overwrite']); 125 $overwrite = !empty($post['overwrite']);
119 126
120 // Add tags to all imported links? 127 // Add tags to all imported links?
121 if (empty($post['default_tags'])) { 128 if (empty($post['default_tags'])) {
@@ -138,7 +145,7 @@ class NetscapeBookmarkUtils
138 ); 145 );
139 $logger = new Logger( 146 $logger = new Logger(
140 $conf->get('resource.data_dir'), 147 $conf->get('resource.data_dir'),
141 ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, 148 !$conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
142 [ 149 [
143 'prefix' => 'import.', 150 'prefix' => 'import.',
144 'extension' => 'log', 151 'extension' => 'log',
@@ -193,7 +200,7 @@ class NetscapeBookmarkUtils
193 } 200 }
194 201
195 // Add a new link - @ used for UNIX timestamps 202 // Add a new link - @ used for UNIX timestamps
196 $newLinkDate = new DateTime('@'.strval($bkm['time'])); 203 $newLinkDate = new DateTime('@' . strval($bkm['time']));
197 $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get())); 204 $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
198 $newLink['created'] = $newLinkDate; 205 $newLink['created'] = $newLinkDate;
199 $newLink['id'] = $linkDb->getNextId(); 206 $newLink['id'] = $linkDb->getNextId();
diff --git a/application/PluginManager.php b/application/plugin/PluginManager.php
index 1ed4db4b..f7b24a8e 100644
--- a/application/PluginManager.php
+++ b/application/plugin/PluginManager.php
@@ -1,4 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Plugin;
3
4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\Exception\PluginFileNotFoundException;
2 6
3/** 7/**
4 * Class PluginManager 8 * Class PluginManager
@@ -9,12 +13,14 @@ class PluginManager
9{ 13{
10 /** 14 /**
11 * List of authorized plugins from configuration file. 15 * List of authorized plugins from configuration file.
16 *
12 * @var array $authorizedPlugins 17 * @var array $authorizedPlugins
13 */ 18 */
14 private $authorizedPlugins; 19 private $authorizedPlugins;
15 20
16 /** 21 /**
17 * List of loaded plugins. 22 * List of loaded plugins.
23 *
18 * @var array $loadedPlugins 24 * @var array $loadedPlugins
19 */ 25 */
20 private $loadedPlugins = array(); 26 private $loadedPlugins = array();
@@ -31,12 +37,14 @@ class PluginManager
31 37
32 /** 38 /**
33 * Plugins subdirectory. 39 * Plugins subdirectory.
40 *
34 * @var string $PLUGINS_PATH 41 * @var string $PLUGINS_PATH
35 */ 42 */
36 public static $PLUGINS_PATH = 'plugins'; 43 public static $PLUGINS_PATH = 'plugins';
37 44
38 /** 45 /**
39 * Plugins meta files extension. 46 * Plugins meta files extension.
47 *
40 * @var string $META_EXT 48 * @var string $META_EXT
41 */ 49 */
42 public static $META_EXT = 'meta'; 50 public static $META_EXT = 'meta';
@@ -84,9 +92,9 @@ class PluginManager
84 /** 92 /**
85 * Execute all plugins registered hook. 93 * Execute all plugins registered hook.
86 * 94 *
87 * @param string $hook name of the hook to trigger. 95 * @param string $hook name of the hook to trigger.
88 * @param array $data list of data to manipulate passed by reference. 96 * @param array $data list of data to manipulate passed by reference.
89 * @param array $params additional parameters such as page target. 97 * @param array $params additional parameters such as page target.
90 * 98 *
91 * @return void 99 * @return void
92 */ 100 */
@@ -118,7 +126,7 @@ class PluginManager
118 * @param string $pluginName plugin's name. 126 * @param string $pluginName plugin's name.
119 * 127 *
120 * @return void 128 * @return void
121 * @throws PluginFileNotFoundException - plugin files not found. 129 * @throws \Shaarli\Plugin\Exception\PluginFileNotFoundException - plugin files not found.
122 */ 130 */
123 private function loadPlugin($dir, $pluginName) 131 private function loadPlugin($dir, $pluginName)
124 { 132 {
@@ -204,8 +212,8 @@ class PluginManager
204 212
205 $metaData[$plugin]['parameters'][$param]['value'] = ''; 213 $metaData[$plugin]['parameters'][$param]['value'] = '';
206 // Optional parameter description in parameter.PARAM_NAME= 214 // Optional parameter description in parameter.PARAM_NAME=
207 if (isset($metaData[$plugin]['parameter.'. $param])) { 215 if (isset($metaData[$plugin]['parameter.' . $param])) {
208 $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.'. $param]); 216 $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.' . $param]);
209 } 217 }
210 } 218 }
211 } 219 }
@@ -223,22 +231,3 @@ class PluginManager
223 return $this->errors; 231 return $this->errors;
224 } 232 }
225} 233}
226
227/**
228 * Class PluginFileNotFoundException
229 *
230 * Raise when plugin files can't be found.
231 */
232class PluginFileNotFoundException extends Exception
233{
234 /**
235 * Construct exception with plugin name.
236 * Generate message.
237 *
238 * @param string $pluginName name of the plugin not found
239 */
240 public function __construct($pluginName)
241 {
242 $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
243 }
244}
diff --git a/application/plugin/exception/PluginFileNotFoundException.php b/application/plugin/exception/PluginFileNotFoundException.php
new file mode 100644
index 00000000..e5386f02
--- /dev/null
+++ b/application/plugin/exception/PluginFileNotFoundException.php
@@ -0,0 +1,23 @@
1<?php
2namespace Shaarli\Plugin\Exception;
3
4use Exception;
5
6/**
7 * Class PluginFileNotFoundException
8 *
9 * Raise when plugin files can't be found.
10 */
11class PluginFileNotFoundException extends Exception
12{
13 /**
14 * Construct exception with plugin name.
15 * Generate message.
16 *
17 * @param string $pluginName name of the plugin not found
18 */
19 public function __construct($pluginName)
20 {
21 $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
22 }
23}
diff --git a/application/PageBuilder.php b/application/render/PageBuilder.php
index 2ca95832..0569b67f 100644
--- a/application/PageBuilder.php
+++ b/application/render/PageBuilder.php
@@ -1,5 +1,11 @@
1<?php 1<?php
2 2
3namespace Shaarli\Render;
4
5use Exception;
6use RainTPL;
7use Shaarli\ApplicationUtils;
8use Shaarli\Bookmark\LinkDB;
3use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
4use Shaarli\Thumbnailer; 10use Shaarli\Thumbnailer;
5 11
@@ -37,7 +43,9 @@ class PageBuilder
37 */ 43 */
38 protected $token; 44 protected $token;
39 45
40 /** @var bool $isLoggedIn Whether the user is logged in **/ 46 /**
47 * @var bool $isLoggedIn Whether the user is logged in
48 */
41 protected $isLoggedIn = false; 49 protected $isLoggedIn = false;
42 50
43 /** 51 /**
@@ -101,7 +109,7 @@ class PageBuilder
101 ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt')) 109 ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt'))
102 ); 110 );
103 $this->tpl->assign('index_url', index_url($_SERVER)); 111 $this->tpl->assign('index_url', index_url($_SERVER));
104 $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; 112 $visibility = !empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '';
105 $this->tpl->assign('visibility', $visibility); 113 $this->tpl->assign('visibility', $visibility);
106 $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); 114 $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly']));
107 $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); 115 $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli'));
@@ -126,7 +134,7 @@ class PageBuilder
126 $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width')); 134 $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width'));
127 $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height')); 135 $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height'));
128 136
129 if (! empty($_SESSION['warnings'])) { 137 if (!empty($_SESSION['warnings'])) {
130 $this->tpl->assign('global_warnings', $_SESSION['warnings']); 138 $this->tpl->assign('global_warnings', $_SESSION['warnings']);
131 unset($_SESSION['warnings']); 139 unset($_SESSION['warnings']);
132 } 140 }
@@ -189,16 +197,16 @@ class PageBuilder
189 197
190 /** 198 /**
191 * Render a 404 page (uses the template : tpl/404.tpl) 199 * Render a 404 page (uses the template : tpl/404.tpl)
192 * usage : $PAGE->render404('The link was deleted') 200 * usage: $PAGE->render404('The link was deleted')
193 * 201 *
194 * @param string $message A messate to display what is not found 202 * @param string $message A message to display what is not found
195 */ 203 */
196 public function render404($message = '') 204 public function render404($message = '')
197 { 205 {
198 if (empty($message)) { 206 if (empty($message)) {
199 $message = t('The page you are trying to reach does not exist or has been deleted.'); 207 $message = t('The page you are trying to reach does not exist or has been deleted.');
200 } 208 }
201 header($_SERVER['SERVER_PROTOCOL'] .' '. t('404 Not Found')); 209 header($_SERVER['SERVER_PROTOCOL'] . ' ' . t('404 Not Found'));
202 $this->tpl->assign('error_message', $message); 210 $this->tpl->assign('error_message', $message);
203 $this->renderPage('404'); 211 $this->renderPage('404');
204 } 212 }
diff --git a/application/ThemeUtils.php b/application/render/ThemeUtils.php
index 16f2f6a2..86096c64 100644
--- a/application/ThemeUtils.php
+++ b/application/render/ThemeUtils.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Shaarli; 3namespace Shaarli\Render;
4 4
5/** 5/**
6 * Class ThemeUtils 6 * Class ThemeUtils
diff --git a/application/Updater.php b/application/updater/Updater.php
index 6b94c5e3..f12e3516 100644
--- a/application/Updater.php
+++ b/application/updater/Updater.php
@@ -1,11 +1,24 @@
1<?php 1<?php
2
3namespace Shaarli\Updater;
4
5use Exception;
6use RainTPL;
7use ReflectionClass;
8use ReflectionException;
9use ReflectionMethod;
10use Shaarli\ApplicationUtils;
11use Shaarli\Bookmark\LinkDB;
12use Shaarli\Bookmark\LinkFilter;
2use Shaarli\Config\ConfigJson; 13use Shaarli\Config\ConfigJson;
3use Shaarli\Config\ConfigPhp;
4use Shaarli\Config\ConfigManager; 14use Shaarli\Config\ConfigManager;
15use Shaarli\Config\ConfigPhp;
16use Shaarli\Exceptions\IOException;
5use Shaarli\Thumbnailer; 17use Shaarli\Thumbnailer;
18use Shaarli\Updater\Exception\UpdaterException;
6 19
7/** 20/**
8 * Class Updater. 21 * Class updater.
9 * Used to update stuff when a new Shaarli's version is reached. 22 * Used to update stuff when a new Shaarli's version is reached.
10 * Update methods are ran only once, and the stored in a JSON file. 23 * Update methods are ran only once, and the stored in a JSON file.
11 */ 24 */
@@ -83,12 +96,12 @@ class Updater
83 } 96 }
84 97
85 if ($this->methods === null) { 98 if ($this->methods === null) {
86 throw new UpdaterException(t('Couldn\'t retrieve Updater class methods.')); 99 throw new UpdaterException(t('Couldn\'t retrieve updater class methods.'));
87 } 100 }
88 101
89 foreach ($this->methods as $method) { 102 foreach ($this->methods as $method) {
90 // Not an update method or already done, pass. 103 // Not an update method or already done, pass.
91 if (! startsWith($method->getName(), 'updateMethod') 104 if (!startsWith($method->getName(), 'updateMethod')
92 || in_array($method->getName(), $this->doneUpdates) 105 || in_array($method->getName(), $this->doneUpdates)
93 ) { 106 ) {
94 continue; 107 continue;
@@ -139,7 +152,7 @@ class Updater
139 } 152 }
140 } 153 }
141 $this->conf->write($this->isLoggedIn); 154 $this->conf->write($this->isLoggedIn);
142 unlink($this->conf->get('resource.data_dir').'/options.php'); 155 unlink($this->conf->get('resource.data_dir') . '/options.php');
143 } 156 }
144 157
145 return true; 158 return true;
@@ -174,10 +187,10 @@ class Updater
174 $subConfig = array('config', 'plugins'); 187 $subConfig = array('config', 'plugins');
175 foreach ($subConfig as $sub) { 188 foreach ($subConfig as $sub) {
176 foreach ($oldConfig[$sub] as $key => $value) { 189 foreach ($oldConfig[$sub] as $key => $value) {
177 if (isset($legacyMap[$sub .'.'. $key])) { 190 if (isset($legacyMap[$sub . '.' . $key])) {
178 $configKey = $legacyMap[$sub .'.'. $key]; 191 $configKey = $legacyMap[$sub . '.' . $key];
179 } else { 192 } else {
180 $configKey = $sub .'.'. $key; 193 $configKey = $sub . '.' . $key;
181 } 194 }
182 $this->conf->set($configKey, $value); 195 $this->conf->set($configKey, $value);
183 } 196 }
@@ -233,7 +246,7 @@ class Updater
233 return true; 246 return true;
234 } 247 }
235 248
236 $save = $this->conf->get('resource.data_dir') .'/datastore.'. date('YmdHis') .'.php'; 249 $save = $this->conf->get('resource.data_dir') . '/datastore.' . date('YmdHis') . '.php';
237 copy($this->conf->get('resource.datastore'), $save); 250 copy($this->conf->get('resource.datastore'), $save);
238 251
239 $links = array(); 252 $links = array();
@@ -307,7 +320,7 @@ class Updater
307 // We run the update only if this folder still contains the template files. 320 // We run the update only if this folder still contains the template files.
308 $tplDir = $this->conf->get('resource.raintpl_tpl'); 321 $tplDir = $this->conf->get('resource.raintpl_tpl');
309 $tplFile = $tplDir . '/linklist.html'; 322 $tplFile = $tplDir . '/linklist.html';
310 if (! file_exists($tplFile)) { 323 if (!file_exists($tplFile)) {
311 return true; 324 return true;
312 } 325 }
313 326
@@ -331,7 +344,7 @@ class Updater
331 */ 344 */
332 public function updateMethodMoveUserCss() 345 public function updateMethodMoveUserCss()
333 { 346 {
334 if (! is_file('inc/user.css')) { 347 if (!is_file('inc/user.css')) {
335 return true; 348 return true;
336 } 349 }
337 350
@@ -367,11 +380,11 @@ class Updater
367 */ 380 */
368 public function updateMethodPiwikUrl() 381 public function updateMethodPiwikUrl()
369 { 382 {
370 if (! $this->conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) { 383 if (!$this->conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) {
371 return true; 384 return true;
372 } 385 }
373 386
374 $this->conf->set('plugins.PIWIK_URL', 'http://'. $this->conf->get('plugins.PIWIK_URL')); 387 $this->conf->set('plugins.PIWIK_URL', 'http://' . $this->conf->get('plugins.PIWIK_URL'));
375 $this->conf->write($this->isLoggedIn); 388 $this->conf->write($this->isLoggedIn);
376 389
377 return true; 390 return true;
@@ -481,11 +494,11 @@ class Updater
481 return true; 494 return true;
482 } 495 }
483 496
484 if (! $this->conf->exists('general.download_max_size')) { 497 if (!$this->conf->exists('general.download_max_size')) {
485 $this->conf->set('general.download_max_size', 1024*1024*4); 498 $this->conf->set('general.download_max_size', 1024 * 1024 * 4);
486 } 499 }
487 500
488 if (! $this->conf->exists('general.download_timeout')) { 501 if (!$this->conf->exists('general.download_timeout')) {
489 $this->conf->set('general.download_timeout', 30); 502 $this->conf->set('general.download_timeout', 30);
490 } 503 }
491 504
@@ -538,96 +551,3 @@ class Updater
538 return true; 551 return true;
539 } 552 }
540} 553}
541
542/**
543 * Class UpdaterException.
544 */
545class UpdaterException extends Exception
546{
547 /**
548 * @var string Method where the error occurred.
549 */
550 protected $method;
551
552 /**
553 * @var Exception The parent exception.
554 */
555 protected $previous;
556
557 /**
558 * Constructor.
559 *
560 * @param string $message Force the error message if set.
561 * @param string $method Method where the error occurred.
562 * @param Exception|bool $previous Parent exception.
563 */
564 public function __construct($message = '', $method = '', $previous = false)
565 {
566 $this->method = $method;
567 $this->previous = $previous;
568 $this->message = $this->buildMessage($message);
569 }
570
571 /**
572 * Build the exception error message.
573 *
574 * @param string $message Optional given error message.
575 *
576 * @return string The built error message.
577 */
578 private function buildMessage($message)
579 {
580 $out = '';
581 if (! empty($message)) {
582 $out .= $message . PHP_EOL;
583 }
584
585 if (! empty($this->method)) {
586 $out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
587 }
588
589 if (! empty($this->previous)) {
590 $out .= ' '. $this->previous->getMessage();
591 }
592
593 return $out;
594 }
595}
596
597/**
598 * Read the updates file, and return already done updates.
599 *
600 * @param string $updatesFilepath Updates file path.
601 *
602 * @return array Already done update methods.
603 */
604function read_updates_file($updatesFilepath)
605{
606 if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
607 $content = file_get_contents($updatesFilepath);
608 if (! empty($content)) {
609 return explode(';', $content);
610 }
611 }
612 return array();
613}
614
615/**
616 * Write updates file.
617 *
618 * @param string $updatesFilepath Updates file path.
619 * @param array $updates Updates array to write.
620 *
621 * @throws Exception Couldn't write version number.
622 */
623function write_updates_file($updatesFilepath, $updates)
624{
625 if (empty($updatesFilepath)) {
626 throw new Exception(t('Updates file path is not set, can\'t write updates.'));
627 }
628
629 $res = file_put_contents($updatesFilepath, implode(';', $updates));
630 if ($res === false) {
631 throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
632 }
633}
diff --git a/application/updater/UpdaterUtils.php b/application/updater/UpdaterUtils.php
new file mode 100644
index 00000000..34d4f422
--- /dev/null
+++ b/application/updater/UpdaterUtils.php
@@ -0,0 +1,39 @@
1<?php
2
3/**
4 * Read the updates file, and return already done updates.
5 *
6 * @param string $updatesFilepath Updates file path.
7 *
8 * @return array Already done update methods.
9 */
10function read_updates_file($updatesFilepath)
11{
12 if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
13 $content = file_get_contents($updatesFilepath);
14 if (! empty($content)) {
15 return explode(';', $content);
16 }
17 }
18 return array();
19}
20
21/**
22 * Write updates file.
23 *
24 * @param string $updatesFilepath Updates file path.
25 * @param array $updates Updates array to write.
26 *
27 * @throws Exception Couldn't write version number.
28 */
29function write_updates_file($updatesFilepath, $updates)
30{
31 if (empty($updatesFilepath)) {
32 throw new Exception(t('Updates file path is not set, can\'t write updates.'));
33 }
34
35 $res = file_put_contents($updatesFilepath, implode(';', $updates));
36 if ($res === false) {
37 throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
38 }
39}
diff --git a/application/updater/exception/UpdaterException.php b/application/updater/exception/UpdaterException.php
new file mode 100644
index 00000000..20aceccf
--- /dev/null
+++ b/application/updater/exception/UpdaterException.php
@@ -0,0 +1,60 @@
1<?php
2
3namespace Shaarli\Updater\Exception;
4
5use Exception;
6
7/**
8 * Class UpdaterException.
9 */
10class UpdaterException extends Exception
11{
12 /**
13 * @var string Method where the error occurred.
14 */
15 protected $method;
16
17 /**
18 * @var Exception The parent exception.
19 */
20 protected $previous;
21
22 /**
23 * Constructor.
24 *
25 * @param string $message Force the error message if set.
26 * @param string $method Method where the error occurred.
27 * @param Exception|bool $previous Parent exception.
28 */
29 public function __construct($message = '', $method = '', $previous = false)
30 {
31 $this->method = $method;
32 $this->previous = $previous;
33 $this->message = $this->buildMessage($message);
34 }
35
36 /**
37 * Build the exception error message.
38 *
39 * @param string $message Optional given error message.
40 *
41 * @return string The built error message.
42 */
43 private function buildMessage($message)
44 {
45 $out = '';
46 if (!empty($message)) {
47 $out .= $message . PHP_EOL;
48 }
49
50 if (!empty($this->method)) {
51 $out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
52 }
53
54 if (!empty($this->previous)) {
55 $out .= ' ' . $this->previous->getMessage();
56 }
57
58 return $out;
59 }
60}
diff --git a/composer.json b/composer.json
index dccf83b6..a52b5f78 100644
--- a/composer.json
+++ b/composer.json
@@ -16,6 +16,8 @@
16 }, 16 },
17 "require": { 17 "require": {
18 "php": ">=5.6", 18 "php": ">=5.6",
19 "ext-json": "*",
20 "ext-zlib": "*",
19 "shaarli/netscape-bookmark-parser": "^2.1", 21 "shaarli/netscape-bookmark-parser": "^2.1",
20 "erusev/parsedown": "^1.6", 22 "erusev/parsedown": "^1.6",
21 "slim/slim": "^3.0", 23 "slim/slim": "^3.0",
@@ -28,15 +30,34 @@
28 "phpunit/phpunit": "^5.0", 30 "phpunit/phpunit": "^5.0",
29 "squizlabs/php_codesniffer": "2.*" 31 "squizlabs/php_codesniffer": "2.*"
30 }, 32 },
33 "suggest": {
34 "ext-curl": "Allows fetching web pages and thumbnails in a more robust way",
35 "ext-gd": "Required for thumbnail generation",
36 "ext-gettext": "Enables faster translation system in gettext mode",
37 "ext-intl": "Provides localized text sorting",
38 "ext-mbstring": "Provides multibyte (Unicode) string support"
39 },
31 "autoload": { 40 "autoload": {
32 "psr-4": { 41 "psr-4": {
33 "Shaarli\\": "application", 42 "Shaarli\\": "application",
34 "Shaarli\\Api\\": "application/api/", 43 "Shaarli\\Api\\": "application/api/",
35 "Shaarli\\Api\\Controllers\\": "application/api/controllers", 44 "Shaarli\\Api\\Controllers\\": "application/api/controllers",
36 "Shaarli\\Api\\Exceptions\\": "application/api/exceptions", 45 "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
46 "Shaarli\\Bookmark\\": "application/bookmark",
47 "Shaarli\\Bookmark\\Exception\\": "application/bookmark/exception",
37 "Shaarli\\Config\\": "application/config/", 48 "Shaarli\\Config\\": "application/config/",
38 "Shaarli\\Config\\Exception\\": "application/config/exception", 49 "Shaarli\\Config\\Exception\\": "application/config/exception",
39 "Shaarli\\Security\\": "application/security" 50 "Shaarli\\Exceptions\\": "application/exceptions",
51 "Shaarli\\Feed\\": "application/feed",
52 "Shaarli\\Http\\": "application/http",
53 "Shaarli\\Netscape\\": "application/netscape",
54 "Shaarli\\Plugin\\": "application/plugin",
55 "Shaarli\\Plugin\\Exception\\": "application/plugin/exception",
56 "Shaarli\\Plugin\\Wallabag\\": "plugins/wallabag",
57 "Shaarli\\Render\\": "application/render",
58 "Shaarli\\Security\\": "application/security",
59 "Shaarli\\Updater\\": "application/updater",
60 "Shaarli\\Updater\\Exception\\": "application/updater/exception"
40 } 61 }
41 } 62 }
42} 63}
diff --git a/composer.lock b/composer.lock
index c43dad6f..53fb2175 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 "This file is @generated automatically" 5 "This file is @generated automatically"
6 ], 6 ],
7 "content-hash": "3876b34296fedb365517b785af8384de", 7 "content-hash": "f8965821c946c2a1271c3f8c7e8c6eea",
8 "packages": [ 8 "packages": [
9 { 9 {
10 "name": "arthurhoaro/web-thumbnailer", 10 "name": "arthurhoaro/web-thumbnailer",
@@ -133,16 +133,16 @@
133 }, 133 },
134 { 134 {
135 "name": "gettext/gettext", 135 "name": "gettext/gettext",
136 "version": "v4.6.1", 136 "version": "v4.6.2",
137 "source": { 137 "source": {
138 "type": "git", 138 "type": "git",
139 "url": "https://github.com/oscarotero/Gettext.git", 139 "url": "https://github.com/oscarotero/Gettext.git",
140 "reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a" 140 "reference": "93176b272d61fb58a9767be71c50d19149cb1e48"
141 }, 141 },
142 "dist": { 142 "dist": {
143 "type": "zip", 143 "type": "zip",
144 "url": "https://api.github.com/repos/oscarotero/Gettext/zipball/854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", 144 "url": "https://api.github.com/repos/oscarotero/Gettext/zipball/93176b272d61fb58a9767be71c50d19149cb1e48",
145 "reference": "854ff5f5aaf92d2af7080ba8fc15718b27b5c89a", 145 "reference": "93176b272d61fb58a9767be71c50d19149cb1e48",
146 "shasum": "" 146 "shasum": ""
147 }, 147 },
148 "require": { 148 "require": {
@@ -191,20 +191,20 @@
191 "po", 191 "po",
192 "translation" 192 "translation"
193 ], 193 ],
194 "time": "2018-08-27T15:40:19+00:00" 194 "time": "2019-01-12T18:40:56+00:00"
195 }, 195 },
196 { 196 {
197 "name": "gettext/languages", 197 "name": "gettext/languages",
198 "version": "2.4.0", 198 "version": "2.5.0",
199 "source": { 199 "source": {
200 "type": "git", 200 "type": "git",
201 "url": "https://github.com/mlocati/cldr-to-gettext-plural-rules.git", 201 "url": "https://github.com/mlocati/cldr-to-gettext-plural-rules.git",
202 "reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5" 202 "reference": "78db2d17933f0765a102f368a6663f057162ddbd"
203 }, 203 },
204 "dist": { 204 "dist": {
205 "type": "zip", 205 "type": "zip",
206 "url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/1b74377bd0c4cd87e8d72b948f5d8867e23505a5", 206 "url": "https://api.github.com/repos/mlocati/cldr-to-gettext-plural-rules/zipball/78db2d17933f0765a102f368a6663f057162ddbd",
207 "reference": "1b74377bd0c4cd87e8d72b948f5d8867e23505a5", 207 "reference": "78db2d17933f0765a102f368a6663f057162ddbd",
208 "shasum": "" 208 "shasum": ""
209 }, 209 },
210 "require": { 210 "require": {
@@ -252,7 +252,7 @@
252 "translations", 252 "translations",
253 "unicode" 253 "unicode"
254 ], 254 ],
255 "time": "2018-06-21T15:58:36+00:00" 255 "time": "2018-11-13T22:06:07+00:00"
256 }, 256 },
257 { 257 {
258 "name": "katzgrau/klogger", 258 "name": "katzgrau/klogger",
@@ -542,16 +542,16 @@
542 }, 542 },
543 { 543 {
544 "name": "psr/log", 544 "name": "psr/log",
545 "version": "1.0.2", 545 "version": "1.1.0",
546 "source": { 546 "source": {
547 "type": "git", 547 "type": "git",
548 "url": "https://github.com/php-fig/log.git", 548 "url": "https://github.com/php-fig/log.git",
549 "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" 549 "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
550 }, 550 },
551 "dist": { 551 "dist": {
552 "type": "zip", 552 "type": "zip",
553 "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", 553 "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
554 "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", 554 "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
555 "shasum": "" 555 "shasum": ""
556 }, 556 },
557 "require": { 557 "require": {
@@ -585,7 +585,7 @@
585 "psr", 585 "psr",
586 "psr-3" 586 "psr-3"
587 ], 587 ],
588 "time": "2016-10-10T12:19:37+00:00" 588 "time": "2018-11-20T15:27:04+00:00"
589 }, 589 },
590 { 590 {
591 "name": "pubsubhubbub/publisher", 591 "name": "pubsubhubbub/publisher",
@@ -2023,16 +2023,16 @@
2023 }, 2023 },
2024 { 2024 {
2025 "name": "squizlabs/php_codesniffer", 2025 "name": "squizlabs/php_codesniffer",
2026 "version": "2.9.1", 2026 "version": "2.9.2",
2027 "source": { 2027 "source": {
2028 "type": "git", 2028 "type": "git",
2029 "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", 2029 "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
2030 "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" 2030 "reference": "2acf168de78487db620ab4bc524135a13cfe6745"
2031 }, 2031 },
2032 "dist": { 2032 "dist": {
2033 "type": "zip", 2033 "type": "zip",
2034 "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", 2034 "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745",
2035 "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", 2035 "reference": "2acf168de78487db620ab4bc524135a13cfe6745",
2036 "shasum": "" 2036 "shasum": ""
2037 }, 2037 },
2038 "require": { 2038 "require": {
@@ -2097,20 +2097,20 @@
2097 "phpcs", 2097 "phpcs",
2098 "standards" 2098 "standards"
2099 ], 2099 ],
2100 "time": "2017-05-22T02:43:20+00:00" 2100 "time": "2018-11-07T22:31:41+00:00"
2101 }, 2101 },
2102 { 2102 {
2103 "name": "symfony/console", 2103 "name": "symfony/console",
2104 "version": "v3.4.17", 2104 "version": "v3.4.21",
2105 "source": { 2105 "source": {
2106 "type": "git", 2106 "type": "git",
2107 "url": "https://github.com/symfony/console.git", 2107 "url": "https://github.com/symfony/console.git",
2108 "reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b" 2108 "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a"
2109 }, 2109 },
2110 "dist": { 2110 "dist": {
2111 "type": "zip", 2111 "type": "zip",
2112 "url": "https://api.github.com/repos/symfony/console/zipball/3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", 2112 "url": "https://api.github.com/repos/symfony/console/zipball/a700b874d3692bc8342199adfb6d3b99f62cc61a",
2113 "reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b", 2113 "reference": "a700b874d3692bc8342199adfb6d3b99f62cc61a",
2114 "shasum": "" 2114 "shasum": ""
2115 }, 2115 },
2116 "require": { 2116 "require": {
@@ -2166,20 +2166,20 @@
2166 ], 2166 ],
2167 "description": "Symfony Console Component", 2167 "description": "Symfony Console Component",
2168 "homepage": "https://symfony.com", 2168 "homepage": "https://symfony.com",
2169 "time": "2018-10-02T16:33:53+00:00" 2169 "time": "2019-01-04T04:42:43+00:00"
2170 }, 2170 },
2171 { 2171 {
2172 "name": "symfony/debug", 2172 "name": "symfony/debug",
2173 "version": "v3.4.17", 2173 "version": "v3.4.21",
2174 "source": { 2174 "source": {
2175 "type": "git", 2175 "type": "git",
2176 "url": "https://github.com/symfony/debug.git", 2176 "url": "https://github.com/symfony/debug.git",
2177 "reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6" 2177 "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186"
2178 }, 2178 },
2179 "dist": { 2179 "dist": {
2180 "type": "zip", 2180 "type": "zip",
2181 "url": "https://api.github.com/repos/symfony/debug/zipball/0a612e9dfbd2ccce03eb174365f31ecdca930ff6", 2181 "url": "https://api.github.com/repos/symfony/debug/zipball/26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186",
2182 "reference": "0a612e9dfbd2ccce03eb174365f31ecdca930ff6", 2182 "reference": "26d7f23b9bd0b93bee5583e4d6ca5cb1ab31b186",
2183 "shasum": "" 2183 "shasum": ""
2184 }, 2184 },
2185 "require": { 2185 "require": {
@@ -2222,20 +2222,20 @@
2222 ], 2222 ],
2223 "description": "Symfony Debug Component", 2223 "description": "Symfony Debug Component",
2224 "homepage": "https://symfony.com", 2224 "homepage": "https://symfony.com",
2225 "time": "2018-10-02T16:33:53+00:00" 2225 "time": "2019-01-01T13:45:19+00:00"
2226 }, 2226 },
2227 { 2227 {
2228 "name": "symfony/finder", 2228 "name": "symfony/finder",
2229 "version": "v3.4.17", 2229 "version": "v3.4.21",
2230 "source": { 2230 "source": {
2231 "type": "git", 2231 "type": "git",
2232 "url": "https://github.com/symfony/finder.git", 2232 "url": "https://github.com/symfony/finder.git",
2233 "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d" 2233 "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e"
2234 }, 2234 },
2235 "dist": { 2235 "dist": {
2236 "type": "zip", 2236 "type": "zip",
2237 "url": "https://api.github.com/repos/symfony/finder/zipball/54ba444dddc5bd5708a34bd095ea67c6eb54644d", 2237 "url": "https://api.github.com/repos/symfony/finder/zipball/3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e",
2238 "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d", 2238 "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e",
2239 "shasum": "" 2239 "shasum": ""
2240 }, 2240 },
2241 "require": { 2241 "require": {
@@ -2271,11 +2271,11 @@
2271 ], 2271 ],
2272 "description": "Symfony Finder Component", 2272 "description": "Symfony Finder Component",
2273 "homepage": "https://symfony.com", 2273 "homepage": "https://symfony.com",
2274 "time": "2018-10-03T08:46:40+00:00" 2274 "time": "2019-01-01T13:45:19+00:00"
2275 }, 2275 },
2276 { 2276 {
2277 "name": "symfony/polyfill-ctype", 2277 "name": "symfony/polyfill-ctype",
2278 "version": "v1.9.0", 2278 "version": "v1.10.0",
2279 "source": { 2279 "source": {
2280 "type": "git", 2280 "type": "git",
2281 "url": "https://github.com/symfony/polyfill-ctype.git", 2281 "url": "https://github.com/symfony/polyfill-ctype.git",
@@ -2333,16 +2333,16 @@
2333 }, 2333 },
2334 { 2334 {
2335 "name": "symfony/polyfill-mbstring", 2335 "name": "symfony/polyfill-mbstring",
2336 "version": "v1.9.0", 2336 "version": "v1.10.0",
2337 "source": { 2337 "source": {
2338 "type": "git", 2338 "type": "git",
2339 "url": "https://github.com/symfony/polyfill-mbstring.git", 2339 "url": "https://github.com/symfony/polyfill-mbstring.git",
2340 "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" 2340 "reference": "c79c051f5b3a46be09205c73b80b346e4153e494"
2341 }, 2341 },
2342 "dist": { 2342 "dist": {
2343 "type": "zip", 2343 "type": "zip",
2344 "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", 2344 "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494",
2345 "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", 2345 "reference": "c79c051f5b3a46be09205c73b80b346e4153e494",
2346 "shasum": "" 2346 "shasum": ""
2347 }, 2347 },
2348 "require": { 2348 "require": {
@@ -2388,20 +2388,20 @@
2388 "portable", 2388 "portable",
2389 "shim" 2389 "shim"
2390 ], 2390 ],
2391 "time": "2018-08-06T14:22:27+00:00" 2391 "time": "2018-09-21T13:07:52+00:00"
2392 }, 2392 },
2393 { 2393 {
2394 "name": "symfony/yaml", 2394 "name": "symfony/yaml",
2395 "version": "v3.4.17", 2395 "version": "v3.4.21",
2396 "source": { 2396 "source": {
2397 "type": "git", 2397 "type": "git",
2398 "url": "https://github.com/symfony/yaml.git", 2398 "url": "https://github.com/symfony/yaml.git",
2399 "reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f" 2399 "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea"
2400 }, 2400 },
2401 "dist": { 2401 "dist": {
2402 "type": "zip", 2402 "type": "zip",
2403 "url": "https://api.github.com/repos/symfony/yaml/zipball/640b6c27fed4066d64b64d5903a86043f4a4de7f", 2403 "url": "https://api.github.com/repos/symfony/yaml/zipball/554a59a1ccbaac238a89b19c8e551a556fd0e2ea",
2404 "reference": "640b6c27fed4066d64b64d5903a86043f4a4de7f", 2404 "reference": "554a59a1ccbaac238a89b19c8e551a556fd0e2ea",
2405 "shasum": "" 2405 "shasum": ""
2406 }, 2406 },
2407 "require": { 2407 "require": {
@@ -2447,7 +2447,7 @@
2447 ], 2447 ],
2448 "description": "Symfony Yaml Component", 2448 "description": "Symfony Yaml Component",
2449 "homepage": "https://symfony.com", 2449 "homepage": "https://symfony.com",
2450 "time": "2018-10-02T16:33:53+00:00" 2450 "time": "2019-01-01T13:45:19+00:00"
2451 }, 2451 },
2452 { 2452 {
2453 "name": "theseer/fdomdocument", 2453 "name": "theseer/fdomdocument",
@@ -2491,20 +2491,21 @@
2491 }, 2491 },
2492 { 2492 {
2493 "name": "webmozart/assert", 2493 "name": "webmozart/assert",
2494 "version": "1.3.0", 2494 "version": "1.4.0",
2495 "source": { 2495 "source": {
2496 "type": "git", 2496 "type": "git",
2497 "url": "https://github.com/webmozart/assert.git", 2497 "url": "https://github.com/webmozart/assert.git",
2498 "reference": "0df1908962e7a3071564e857d86874dad1ef204a" 2498 "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9"
2499 }, 2499 },
2500 "dist": { 2500 "dist": {
2501 "type": "zip", 2501 "type": "zip",
2502 "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", 2502 "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9",
2503 "reference": "0df1908962e7a3071564e857d86874dad1ef204a", 2503 "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9",
2504 "shasum": "" 2504 "shasum": ""
2505 }, 2505 },
2506 "require": { 2506 "require": {
2507 "php": "^5.3.3 || ^7.0" 2507 "php": "^5.3.3 || ^7.0",
2508 "symfony/polyfill-ctype": "^1.8"
2508 }, 2509 },
2509 "require-dev": { 2510 "require-dev": {
2510 "phpunit/phpunit": "^4.6", 2511 "phpunit/phpunit": "^4.6",
@@ -2537,7 +2538,7 @@
2537 "check", 2538 "check",
2538 "validate" 2539 "validate"
2539 ], 2540 ],
2540 "time": "2018-01-29T19:49:41+00:00" 2541 "time": "2018-12-25T11:19:39+00:00"
2541 } 2542 }
2542 ], 2543 ],
2543 "aliases": [], 2544 "aliases": [],
@@ -2548,7 +2549,9 @@
2548 "prefer-stable": false, 2549 "prefer-stable": false,
2549 "prefer-lowest": false, 2550 "prefer-lowest": false,
2550 "platform": { 2551 "platform": {
2551 "php": ">=5.6" 2552 "php": ">=5.6",
2553 "ext-json": "*",
2554 "ext-zlib": "*"
2552 }, 2555 },
2553 "platform-dev": [], 2556 "platform-dev": [],
2554 "platform-overrides": { 2557 "platform-overrides": {
diff --git a/index.php b/index.php
index acfcc660..633ab89e 100644
--- a/index.php
+++ b/index.php
@@ -56,31 +56,33 @@ require_once 'inc/rain.tpl.class.php';
56require_once __DIR__ . '/vendor/autoload.php'; 56require_once __DIR__ . '/vendor/autoload.php';
57 57
58// Shaarli library 58// Shaarli library
59require_once 'application/ApplicationUtils.php'; 59require_once 'application/bookmark/LinkUtils.php';
60require_once 'application/Cache.php';
61require_once 'application/CachedPage.php';
62require_once 'application/config/ConfigPlugin.php'; 60require_once 'application/config/ConfigPlugin.php';
63require_once 'application/FeedBuilder.php'; 61require_once 'application/feed/Cache.php';
62require_once 'application/http/HttpUtils.php';
63require_once 'application/http/UrlUtils.php';
64require_once 'application/updater/UpdaterUtils.php';
64require_once 'application/FileUtils.php'; 65require_once 'application/FileUtils.php';
65require_once 'application/History.php';
66require_once 'application/HttpUtils.php';
67require_once 'application/LinkDB.php';
68require_once 'application/LinkFilter.php';
69require_once 'application/LinkUtils.php';
70require_once 'application/NetscapeBookmarkUtils.php';
71require_once 'application/PageBuilder.php';
72require_once 'application/TimeZone.php'; 66require_once 'application/TimeZone.php';
73require_once 'application/Url.php';
74require_once 'application/Utils.php'; 67require_once 'application/Utils.php';
75require_once 'application/PluginManager.php'; 68
76require_once 'application/Router.php'; 69use \Shaarli\ApplicationUtils;
77require_once 'application/Updater.php'; 70use \Shaarli\Bookmark\Exception\LinkNotFoundException;
71use \Shaarli\Bookmark\LinkDB;
78use \Shaarli\Config\ConfigManager; 72use \Shaarli\Config\ConfigManager;
73use \Shaarli\Feed\CachedPage;
74use \Shaarli\Feed\FeedBuilder;
75use \Shaarli\History;
79use \Shaarli\Languages; 76use \Shaarli\Languages;
77use \Shaarli\Netscape\NetscapeBookmarkUtils;
78use \Shaarli\Plugin\PluginManager;
79use \Shaarli\Render\PageBuilder;
80use \Shaarli\Render\ThemeUtils;
81use \Shaarli\Router;
80use \Shaarli\Security\LoginManager; 82use \Shaarli\Security\LoginManager;
81use \Shaarli\Security\SessionManager; 83use \Shaarli\Security\SessionManager;
82use \Shaarli\ThemeUtils;
83use \Shaarli\Thumbnailer; 84use \Shaarli\Thumbnailer;
85use \Shaarli\Updater\Updater;
84 86
85// Ensure the PHP version is supported 87// Ensure the PHP version is supported
86try { 88try {
diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php
index 8c05a231..8bf4ed46 100644
--- a/plugins/addlink_toolbar/addlink_toolbar.php
+++ b/plugins/addlink_toolbar/addlink_toolbar.php
@@ -5,6 +5,8 @@
5 * Adds the addlink input on the linklist page. 5 * Adds the addlink input on the linklist page.
6 */ 6 */
7 7
8use Shaarli\Router;
9
8/** 10/**
9 * When linklist is displayed, add play videos to header's toolbar. 11 * When linklist is displayed, add play videos to header's toolbar.
10 * 12 *
diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php
index 5dcea5a6..0ee1c73c 100644
--- a/plugins/archiveorg/archiveorg.php
+++ b/plugins/archiveorg/archiveorg.php
@@ -5,6 +5,8 @@
5 * Add an icon in the link list for archive.org. 5 * Add an icon in the link list for archive.org.
6 */ 6 */
7 7
8use Shaarli\Plugin\PluginManager;
9
8/** 10/**
9 * Add archive.org icon to link_plugin when rendering linklist. 11 * Add archive.org icon to link_plugin when rendering linklist.
10 * 12 *
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index ca520d15..95ea7fe2 100644
--- a/plugins/demo_plugin/demo_plugin.php
+++ b/plugins/demo_plugin/demo_plugin.php
@@ -15,6 +15,8 @@
15 */ 15 */
16 16
17use Shaarli\Config\ConfigManager; 17use Shaarli\Config\ConfigManager;
18use Shaarli\Plugin\PluginManager;
19use Shaarli\Router;
18 20
19/** 21/**
20 * In the footer hook, there is a working example of a translation extension for Shaarli. 22 * In the footer hook, there is a working example of a translation extension for Shaarli.
diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php
index 378c11af..dab75dd5 100644
--- a/plugins/isso/isso.php
+++ b/plugins/isso/isso.php
@@ -5,6 +5,8 @@
5 */ 5 */
6 6
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
8 10
9/** 11/**
10 * Display an error everywhere if the plugin is enabled without configuration. 12 * Display an error everywhere if the plugin is enabled without configuration.
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 8823af91..628970d6 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -7,6 +7,8 @@
7 */ 7 */
8 8
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\Plugin\PluginManager;
11use Shaarli\Router;
10 12
11/* 13/*
12 * If this tag is used on a shaare, the description won't be processed by Parsedown. 14 * If this tag is used on a shaare, the description won't be processed by Parsedown.
diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php
index ca00c2be..17b1aecc 100644
--- a/plugins/piwik/piwik.php
+++ b/plugins/piwik/piwik.php
@@ -4,6 +4,8 @@
4 * Adds tracking code on each page. 4 * Adds tracking code on each page.
5 */ 5 */
6 6
7use Shaarli\Plugin\PluginManager;
8
7/** 9/**
8 * Initialization function. 10 * Initialization function.
9 * It will be called when the plugin is loaded. 11 * It will be called when the plugin is loaded.
diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php
index c6d6b0cc..0341ed59 100644
--- a/plugins/playvideos/playvideos.php
+++ b/plugins/playvideos/playvideos.php
@@ -6,6 +6,9 @@
6 * Note: this plugin adds jQuery. 6 * Note: this plugin adds jQuery.
7 */ 7 */
8 8
9use Shaarli\Plugin\PluginManager;
10use Shaarli\Router;
11
9/** 12/**
10 * When linklist is displayed, add play videos to header's toolbar. 13 * When linklist is displayed, add play videos to header's toolbar.
11 * 14 *
diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php
index 9f0342a3..2878c050 100644
--- a/plugins/pubsubhubbub/pubsubhubbub.php
+++ b/plugins/pubsubhubbub/pubsubhubbub.php
@@ -11,6 +11,9 @@
11 11
12use pubsubhubbub\publisher\Publisher; 12use pubsubhubbub\publisher\Publisher;
13use Shaarli\Config\ConfigManager; 13use Shaarli\Config\ConfigManager;
14use Shaarli\Feed\FeedBuilder;
15use Shaarli\Plugin\PluginManager;
16use Shaarli\Router;
14 17
15/** 18/**
16 * Plugin init function - set the hub to the default appspot one. 19 * Plugin init function - set the hub to the default appspot one.
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php
index 4b59caa0..34eef8be 100644
--- a/plugins/qrcode/qrcode.php
+++ b/plugins/qrcode/qrcode.php
@@ -5,6 +5,9 @@
5 * Display a QRCode icon in link list. 5 * Display a QRCode icon in link list.
6 */ 6 */
7 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
8/** 11/**
9 * Add qrcode icon to link_plugin when rendering linklist. 12 * Add qrcode icon to link_plugin when rendering linklist.
10 * 13 *
diff --git a/plugins/wallabag/WallabagInstance.php b/plugins/wallabag/WallabagInstance.php
index eb8ab618..f4a0a92b 100644
--- a/plugins/wallabag/WallabagInstance.php
+++ b/plugins/wallabag/WallabagInstance.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Wallabag;
2 3
3/** 4/**
4 * Class WallabagInstance. 5 * Class WallabagInstance.
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php
index a6476c71..bc35df08 100644
--- a/plugins/wallabag/wallabag.php
+++ b/plugins/wallabag/wallabag.php
@@ -1,11 +1,11 @@
1<?php 1<?php
2
3/** 2/**
4 * Plugin Wallabag. 3 * Wallabag plugin
5 */ 4 */
6 5
7require_once 'WallabagInstance.php';
8use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\Plugin\PluginManager;
8use Shaarli\Plugin\Wallabag\WallabagInstance;
9 9
10/** 10/**
11 * Init function, return an error if the server is not set. 11 * Init function, return an error if the server is not set.
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index fe5f84ce..82f8804d 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -1,33 +1,14 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli;
3
4/**
5 * ApplicationUtils' tests
6 */
7 3
8require_once 'application/ApplicationUtils.php'; 4use Shaarli\Config\ConfigManager;
9
10/**
11 * Fake ApplicationUtils class to avoid HTTP requests
12 */
13class FakeApplicationUtils extends ApplicationUtils
14{
15 public static $VERSION_CODE = '';
16
17 /**
18 * Toggle HTTP requests, allow overriding the version code
19 */
20 public static function getVersion($url, $timeout = 0)
21 {
22 return self::$VERSION_CODE;
23 }
24}
25 5
6require_once 'tests/utils/FakeApplicationUtils.php';
26 7
27/** 8/**
28 * Unitary tests for Shaarli utilities 9 * Unitary tests for Shaarli utilities
29 */ 10 */
30class ApplicationUtilsTest extends PHPUnit_Framework_TestCase 11class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
31{ 12{
32 protected static $testUpdateFile = 'sandbox/update.txt'; 13 protected static $testUpdateFile = 'sandbox/update.txt';
33 protected static $testVersion = '0.5.0'; 14 protected static $testVersion = '0.5.0';
diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php
index d764e495..57719175 100644
--- a/tests/FileUtilsTest.php
+++ b/tests/FileUtilsTest.php
@@ -1,13 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/FileUtils.php'; 3namespace Shaarli;
4
5use Exception;
4 6
5/** 7/**
6 * Class FileUtilsTest 8 * Class FileUtilsTest
7 * 9 *
8 * Test file utility class. 10 * Test file utility class.
9 */ 11 */
10class FileUtilsTest extends PHPUnit_Framework_TestCase 12class FileUtilsTest extends \PHPUnit\Framework\TestCase
11{ 13{
12 /** 14 /**
13 * @var string Test file path. 15 * @var string Test file path.
@@ -48,7 +50,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
48 /** 50 /**
49 * File not writable: raise an exception. 51 * File not writable: raise an exception.
50 * 52 *
51 * @expectedException IOException 53 * @expectedException Shaarli\Exceptions\IOException
52 * @expectedExceptionMessage Error accessing "sandbox/flat.db" 54 * @expectedExceptionMessage Error accessing "sandbox/flat.db"
53 */ 55 */
54 public function testWriteWithoutPermission() 56 public function testWriteWithoutPermission()
@@ -61,7 +63,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
61 /** 63 /**
62 * Folder non existent: raise an exception. 64 * Folder non existent: raise an exception.
63 * 65 *
64 * @expectedException IOException 66 * @expectedException Shaarli\Exceptions\IOException
65 * @expectedExceptionMessage Error accessing "nopefolder" 67 * @expectedExceptionMessage Error accessing "nopefolder"
66 */ 68 */
67 public function testWriteFolderDoesNotExist() 69 public function testWriteFolderDoesNotExist()
@@ -72,7 +74,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
72 /** 74 /**
73 * Folder non writable: raise an exception. 75 * Folder non writable: raise an exception.
74 * 76 *
75 * @expectedException IOException 77 * @expectedException Shaarli\Exceptions\IOException
76 * @expectedExceptionMessage Error accessing "sandbox" 78 * @expectedExceptionMessage Error accessing "sandbox"
77 */ 79 */
78 public function testWriteFolderPermission() 80 public function testWriteFolderPermission()
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index d3bef5a3..8303e53a 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -1,9 +1,11 @@
1<?php 1<?php
2 2
3require_once 'application/History.php'; 3namespace Shaarli;
4 4
5use DateTime;
6use Exception;
5 7
6class HistoryTest extends PHPUnit_Framework_TestCase 8class HistoryTest extends \PHPUnit\Framework\TestCase
7{ 9{
8 /** 10 /**
9 * @var string History file path 11 * @var string History file path
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php
index 4951e09a..de83f291 100644
--- a/tests/LanguagesTest.php
+++ b/tests/LanguagesTest.php
@@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager;
7/** 7/**
8 * Class LanguagesTest. 8 * Class LanguagesTest.
9 */ 9 */
10class LanguagesTest extends \PHPUnit_Framework_TestCase 10class LanguagesTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * @var string Config file path (without extension). 13 * @var string Config file path (without extension).
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index 01de959c..71761ac1 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -1,16 +1,12 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli\Plugin;
3 3
4/** 4use Shaarli\Config\ConfigManager;
5 * Plugin Manager tests
6 */
7
8require_once 'application/PluginManager.php';
9 5
10/** 6/**
11 * Unit tests for Plugins 7 * Unit tests for Plugins
12 */ 8 */
13class PluginManagerTest extends PHPUnit_Framework_TestCase 9class PluginManagerTest extends \PHPUnit\Framework\TestCase
14{ 10{
15 /** 11 /**
16 * Path to tests plugin. 12 * Path to tests plugin.
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
index abf1bd5f..0cd49bb8 100644
--- a/tests/RouterTest.php
+++ b/tests/RouterTest.php
@@ -1,15 +1,10 @@
1<?php 1<?php
2 2namespace Shaarli;
3/**
4 * Router tests
5 */
6
7require_once 'application/Router.php';
8 3
9/** 4/**
10 * Unit tests for Router 5 * Unit tests for Router
11 */ 6 */
12class RouterTest extends PHPUnit_Framework_TestCase 7class RouterTest extends \PHPUnit\Framework\TestCase
13{ 8{
14 /** 9 /**
15 * Test findPage: login page output. 10 * Test findPage: login page output.
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php
index 127fdc19..02bf060f 100644
--- a/tests/TimeZoneTest.php
+++ b/tests/TimeZoneTest.php
@@ -8,7 +8,7 @@ require_once 'application/TimeZone.php';
8/** 8/**
9 * Unitary tests for timezone utilities 9 * Unitary tests for timezone utilities
10 */ 10 */
11class TimeZoneTest extends PHPUnit_Framework_TestCase 11class TimeZoneTest extends PHPUnit\Framework\TestCase
12{ 12{
13 /** 13 /**
14 * @var array of timezones 14 * @var array of timezones
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index d0abd996..8225d95a 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -10,7 +10,7 @@ require_once 'application/Languages.php';
10/** 10/**
11 * Unitary tests for Shaarli utilities 11 * Unitary tests for Shaarli utilities
12 */ 12 */
13class UtilsTest extends PHPUnit_Framework_TestCase 13class UtilsTest extends PHPUnit\Framework\TestCase
14{ 14{
15 // Log file 15 // Log file
16 protected static $testLogFile = 'tests.log'; 16 protected static $testLogFile = 'tests.log';
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php
index 23a56b1c..0b9b03f2 100644
--- a/tests/api/ApiMiddlewareTest.php
+++ b/tests/api/ApiMiddlewareTest.php
@@ -2,7 +2,6 @@
2namespace Shaarli\Api; 2namespace Shaarli\Api;
3 3
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 5use Slim\Container;
7use Slim\Http\Environment; 6use Slim\Http\Environment;
8use Slim\Http\Request; 7use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
18 * 17 *
19 * @package Api 18 * @package Api
20 */ 19 */
21class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase 20class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
22{ 21{
23 /** 22 /**
24 * @var string datastore to test write operations 23 * @var string datastore to test write operations
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index df4e189a..ea0ae500 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -2,12 +2,12 @@
2 2
3namespace Shaarli\Api; 3namespace Shaarli\Api;
4 4
5use Shaarli\Base64Url; 5use Shaarli\Http\Base64Url;
6 6
7/** 7/**
8 * Class ApiUtilsTest 8 * Class ApiUtilsTest
9 */ 9 */
10class ApiUtilsTest extends \PHPUnit_Framework_TestCase 10class ApiUtilsTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * Force the timezone for ISO datetimes. 13 * Force the timezone for ISO datetimes.
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php
index ff34e16d..e287f239 100644
--- a/tests/api/controllers/history/HistoryTest.php
+++ b/tests/api/controllers/history/HistoryTest.php
@@ -1,9 +1,9 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use Shaarli\History;
7use Slim\Container; 7use Slim\Container;
8use Slim\Http\Environment; 8use Slim\Http\Environment;
9use Slim\Http\Request; 9use Slim\Http\Request;
@@ -11,7 +11,7 @@ use Slim\Http\Response;
11 11
12require_once 'tests/utils/ReferenceHistory.php'; 12require_once 'tests/utils/ReferenceHistory.php';
13 13
14class HistoryTest extends \PHPUnit_Framework_TestCase 14class HistoryTest extends \PHPUnit\Framework\TestCase
15{ 15{
16 /** 16 /**
17 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -34,7 +34,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
34 protected $container; 34 protected $container;
35 35
36 /** 36 /**
37 * @var History controller instance. 37 * @var HistoryController controller instance.
38 */ 38 */
39 protected $controller; 39 protected $controller;
40 40
@@ -49,9 +49,9 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
49 $this->container = new Container(); 49 $this->container = new Container();
50 $this->container['conf'] = $this->conf; 50 $this->container['conf'] = $this->conf;
51 $this->container['db'] = true; 51 $this->container['db'] = true;
52 $this->container['history'] = new \History(self::$testHistory); 52 $this->container['history'] = new History(self::$testHistory);
53 53
54 $this->controller = new History($this->container); 54 $this->controller = new HistoryController($this->container);
55 } 55 }
56 56
57 /** 57 /**
@@ -78,35 +78,35 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
78 78
79 $this->assertEquals($this->refHistory->count(), count($data)); 79 $this->assertEquals($this->refHistory->count(), count($data));
80 80
81 $this->assertEquals(\History::DELETED, $data[0]['event']); 81 $this->assertEquals(History::DELETED, $data[0]['event']);
82 $this->assertEquals( 82 $this->assertEquals(
83 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 83 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
84 $data[0]['datetime'] 84 $data[0]['datetime']
85 ); 85 );
86 $this->assertEquals(124, $data[0]['id']); 86 $this->assertEquals(124, $data[0]['id']);
87 87
88 $this->assertEquals(\History::SETTINGS, $data[1]['event']); 88 $this->assertEquals(History::SETTINGS, $data[1]['event']);
89 $this->assertEquals( 89 $this->assertEquals(
90 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 90 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
91 $data[1]['datetime'] 91 $data[1]['datetime']
92 ); 92 );
93 $this->assertNull($data[1]['id']); 93 $this->assertNull($data[1]['id']);
94 94
95 $this->assertEquals(\History::UPDATED, $data[2]['event']); 95 $this->assertEquals(History::UPDATED, $data[2]['event']);
96 $this->assertEquals( 96 $this->assertEquals(
97 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), 97 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM),
98 $data[2]['datetime'] 98 $data[2]['datetime']
99 ); 99 );
100 $this->assertEquals(123, $data[2]['id']); 100 $this->assertEquals(123, $data[2]['id']);
101 101
102 $this->assertEquals(\History::CREATED, $data[3]['event']); 102 $this->assertEquals(History::CREATED, $data[3]['event']);
103 $this->assertEquals( 103 $this->assertEquals(
104 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), 104 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM),
105 $data[3]['datetime'] 105 $data[3]['datetime']
106 ); 106 );
107 $this->assertEquals(124, $data[3]['id']); 107 $this->assertEquals(124, $data[3]['id']);
108 108
109 $this->assertEquals(\History::CREATED, $data[4]['event']); 109 $this->assertEquals(History::CREATED, $data[4]['event']);
110 $this->assertEquals( 110 $this->assertEquals(
111 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 111 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
112 $data[4]['datetime'] 112 $data[4]['datetime']
@@ -131,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
131 131
132 $this->assertEquals(1, count($data)); 132 $this->assertEquals(1, count($data));
133 133
134 $this->assertEquals(\History::DELETED, $data[0]['event']); 134 $this->assertEquals(History::DELETED, $data[0]['event']);
135 $this->assertEquals( 135 $this->assertEquals(
136 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 136 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
137 $data[0]['datetime'] 137 $data[0]['datetime']
@@ -156,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
156 156
157 $this->assertEquals(1, count($data)); 157 $this->assertEquals(1, count($data));
158 158
159 $this->assertEquals(\History::CREATED, $data[0]['event']); 159 $this->assertEquals(History::CREATED, $data[0]['event']);
160 $this->assertEquals( 160 $this->assertEquals(
161 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 161 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
162 $data[0]['datetime'] 162 $data[0]['datetime']
@@ -181,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
181 181
182 $this->assertEquals(1, count($data)); 182 $this->assertEquals(1, count($data));
183 183
184 $this->assertEquals(\History::DELETED, $data[0]['event']); 184 $this->assertEquals(History::DELETED, $data[0]['event']);
185 $this->assertEquals( 185 $this->assertEquals(
186 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 186 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
187 $data[0]['datetime'] 187 $data[0]['datetime']
@@ -206,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
206 206
207 $this->assertEquals(1, count($data)); 207 $this->assertEquals(1, count($data));
208 208
209 $this->assertEquals(\History::SETTINGS, $data[0]['event']); 209 $this->assertEquals(History::SETTINGS, $data[0]['event']);
210 $this->assertEquals( 210 $this->assertEquals(
211 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 211 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
212 $data[0]['datetime'] 212 $data[0]['datetime']
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index e437082a..e70d371b 100644
--- a/tests/api/controllers/info/InfoTest.php
+++ b/tests/api/controllers/info/InfoTest.php
@@ -2,7 +2,6 @@
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 5use Slim\Container;
7use Slim\Http\Environment; 6use Slim\Http\Environment;
8use Slim\Http\Request; 7use Slim\Http\Request;
@@ -15,7 +14,7 @@ use Slim\Http\Response;
15 * 14 *
16 * @package Api\Controllers 15 * @package Api\Controllers
17 */ 16 */
18class InfoTest extends \PHPUnit_Framework_TestCase 17class InfoTest extends \PHPUnit\Framework\TestCase
19{ 18{
20 /** 19 /**
21 * @var string datastore to test write operations 20 * @var string datastore to test write operations
@@ -53,7 +52,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
53 52
54 $this->container = new Container(); 53 $this->container = new Container();
55 $this->container['conf'] = $this->conf; 54 $this->container['conf'] = $this->conf;
56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 55 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
57 $this->container['history'] = null; 56 $this->container['history'] = null;
58 57
59 $this->controller = new Info($this->container); 58 $this->controller = new Info($this->container);
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 7d797137..90193e28 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -3,13 +3,15 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
7use Slim\Container; 9use Slim\Container;
8use Slim\Http\Environment; 10use Slim\Http\Environment;
9use Slim\Http\Request; 11use Slim\Http\Request;
10use Slim\Http\Response; 12use Slim\Http\Response;
11 13
12class DeleteLinkTest extends \PHPUnit_Framework_TestCase 14class DeleteLinkTest extends \PHPUnit\Framework\TestCase
13{ 15{
14 /** 16 /**
15 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 34 protected $refDB = null;
33 35
34 /** 36 /**
35 * @var \LinkDB instance. 37 * @var LinkDB instance.
36 */ 38 */
37 protected $linkDB; 39 protected $linkDB;
38 40
39 /** 41 /**
40 * @var \History instance. 42 * @var HistoryController instance.
41 */ 43 */
42 protected $history; 44 protected $history;
43 45
@@ -59,10 +61,10 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
59 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
60 $this->refDB = new \ReferenceLinkDB(); 62 $this->refDB = new \ReferenceLinkDB();
61 $this->refDB->write(self::$testDatastore); 63 $this->refDB->write(self::$testDatastore);
62 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 64 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory(); 65 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 66 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 67 $this->history = new History(self::$testHistory);
66 $this->container = new Container(); 68 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
68 $this->container['db'] = $this->linkDB; 70 $this->container['db'] = $this->linkDB;
@@ -96,11 +98,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
96 $this->assertEquals(204, $response->getStatusCode()); 98 $this->assertEquals(204, $response->getStatusCode());
97 $this->assertEmpty((string) $response->getBody()); 99 $this->assertEmpty((string) $response->getBody());
98 100
99 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 101 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
100 $this->assertFalse(isset($this->linkDB[$id])); 102 $this->assertFalse(isset($this->linkDB[$id]));
101 103
102 $historyEntry = $this->history->getHistory()[0]; 104 $historyEntry = $this->history->getHistory()[0];
103 $this->assertEquals(\History::DELETED, $historyEntry['event']); 105 $this->assertEquals(History::DELETED, $historyEntry['event']);
104 $this->assertTrue( 106 $this->assertTrue(
105 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 107 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
106 ); 108 );
@@ -110,7 +112,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
110 /** 112 /**
111 * Test DELETE link endpoint: reach not existing ID. 113 * Test DELETE link endpoint: reach not existing ID.
112 * 114 *
113 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException 115 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
114 */ 116 */
115 public function testDeleteLink404() 117 public function testDeleteLink404()
116 { 118 {
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index 57528d5a..cb9b7f6a 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -3,7 +3,6 @@
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6
7use Slim\Container; 6use Slim\Container;
8use Slim\Http\Environment; 7use Slim\Http\Environment;
9use Slim\Http\Request; 8use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
18 * 17 *
19 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
20 */ 19 */
21class GetLinkIdTest extends \PHPUnit_Framework_TestCase 20class GetLinkIdTest extends \PHPUnit\Framework\TestCase
22{ 21{
23 /** 22 /**
24 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -61,7 +60,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
61 60
62 $this->container = new Container(); 61 $this->container = new Container();
63 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
64 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
65 $this->container['history'] = null; 64 $this->container['history'] = null;
66 65
67 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
@@ -108,7 +107,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
108 $this->assertEquals('sTuff', $data['tags'][0]); 107 $this->assertEquals('sTuff', $data['tags'][0]);
109 $this->assertEquals(false, $data['private']); 108 $this->assertEquals(false, $data['private']);
110 $this->assertEquals( 109 $this->assertEquals(
111 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 110 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
112 $data['created'] 111 $data['created']
113 ); 112 );
114 $this->assertEmpty($data['updated']); 113 $this->assertEmpty($data['updated']);
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index 64f02774..711a3152 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 6use Slim\Container;
7use Slim\Http\Environment; 7use Slim\Http\Environment;
8use Slim\Http\Request; 8use Slim\Http\Request;
@@ -17,7 +17,7 @@ use Slim\Http\Response;
17 * 17 *
18 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
19 */ 19 */
20class GetLinksTest extends \PHPUnit_Framework_TestCase 20class GetLinksTest extends \PHPUnit\Framework\TestCase
21{ 21{
22 /** 22 /**
23 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -60,7 +60,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
60 60
61 $this->container = new Container(); 61 $this->container = new Container();
62 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
63 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new LinkDB(self::$testDatastore, true, false);
64 $this->container['history'] = null; 64 $this->container['history'] = null;
65 65
66 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
@@ -114,7 +114,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
114 $this->assertEquals('sTuff', $first['tags'][0]); 114 $this->assertEquals('sTuff', $first['tags'][0]);
115 $this->assertEquals(false, $first['private']); 115 $this->assertEquals(false, $first['private']);
116 $this->assertEquals( 116 $this->assertEquals(
117 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 117 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
118 $first['created'] 118 $first['created']
119 ); 119 );
120 $this->assertEmpty($first['updated']); 120 $this->assertEmpty($first['updated']);
@@ -125,7 +125,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
125 125
126 // Update date 126 // Update date
127 $this->assertEquals( 127 $this->assertEquals(
128 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), 128 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
129 $link['updated'] 129 $link['updated']
130 ); 130 );
131 } 131 }
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index 5c2b5623..d683a984 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -4,6 +4,7 @@ namespace Shaarli\Api\Controllers;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
@@ -40,7 +41,7 @@ class PostLinkTest extends TestCase
40 protected $refDB = null; 41 protected $refDB = null;
41 42
42 /** 43 /**
43 * @var \History instance. 44 * @var HistoryController instance.
44 */ 45 */
45 protected $history; 46 protected $history;
46 47
@@ -70,12 +71,12 @@ class PostLinkTest extends TestCase
70 71
71 $refHistory = new \ReferenceHistory(); 72 $refHistory = new \ReferenceHistory();
72 $refHistory->write(self::$testHistory); 73 $refHistory->write(self::$testHistory);
73 $this->history = new \History(self::$testHistory); 74 $this->history = new History(self::$testHistory);
74 75
75 $this->container = new Container(); 76 $this->container = new Container();
76 $this->container['conf'] = $this->conf; 77 $this->container['conf'] = $this->conf;
77 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 78 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
78 $this->container['history'] = new \History(self::$testHistory); 79 $this->container['history'] = new History(self::$testHistory);
79 80
80 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
81 82
@@ -121,7 +122,7 @@ class PostLinkTest extends TestCase
121 $data = json_decode((string) $response->getBody(), true); 122 $data = json_decode((string) $response->getBody(), true);
122 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 123 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
123 $this->assertEquals(43, $data['id']); 124 $this->assertEquals(43, $data['id']);
124 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 125 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
125 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); 126 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']);
126 $this->assertEquals('?' . $data['shorturl'], $data['title']); 127 $this->assertEquals('?' . $data['shorturl'], $data['title']);
127 $this->assertEquals('', $data['description']); 128 $this->assertEquals('', $data['description']);
@@ -133,7 +134,7 @@ class PostLinkTest extends TestCase
133 $this->assertEquals('', $data['updated']); 134 $this->assertEquals('', $data['updated']);
134 135
135 $historyEntry = $this->history->getHistory()[0]; 136 $historyEntry = $this->history->getHistory()[0];
136 $this->assertEquals(\History::CREATED, $historyEntry['event']); 137 $this->assertEquals(History::CREATED, $historyEntry['event']);
137 $this->assertTrue( 138 $this->assertTrue(
138 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 139 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
139 ); 140 );
@@ -166,7 +167,7 @@ class PostLinkTest extends TestCase
166 $data = json_decode((string) $response->getBody(), true); 167 $data = json_decode((string) $response->getBody(), true);
167 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 168 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
168 $this->assertEquals(43, $data['id']); 169 $this->assertEquals(43, $data['id']);
169 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 170 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
170 $this->assertEquals('http://' . $link['url'], $data['url']); 171 $this->assertEquals('http://' . $link['url'], $data['url']);
171 $this->assertEquals($link['title'], $data['title']); 172 $this->assertEquals($link['title'], $data['title']);
172 $this->assertEquals($link['description'], $data['description']); 173 $this->assertEquals($link['description'], $data['description']);
@@ -210,11 +211,11 @@ class PostLinkTest extends TestCase
210 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 211 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
211 $this->assertEquals(false, $data['private']); 212 $this->assertEquals(false, $data['private']);
212 $this->assertEquals( 213 $this->assertEquals(
213 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 214 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
214 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 215 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
215 ); 216 );
216 $this->assertEquals( 217 $this->assertEquals(
217 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 218 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
218 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 219 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
219 ); 220 );
220 } 221 }
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index f276b4c1..cd815b66 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -4,12 +4,13 @@
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
10use Slim\Http\Response; 11use Slim\Http\Response;
11 12
12class PutLinkTest extends \PHPUnit_Framework_TestCase 13class PutLinkTest extends \PHPUnit\Framework\TestCase
13{ 14{
14 /** 15 /**
15 * @var string datastore to test write operations 16 * @var string datastore to test write operations
@@ -32,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 33 protected $refDB = null;
33 34
34 /** 35 /**
35 * @var \History instance. 36 * @var HistoryController instance.
36 */ 37 */
37 protected $history; 38 protected $history;
38 39
@@ -62,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
62 63
63 $refHistory = new \ReferenceHistory(); 64 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 65 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 66 $this->history = new History(self::$testHistory);
66 67
67 $this->container = new Container(); 68 $this->container = new Container();
68 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
69 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 70 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
70 $this->container['history'] = new \History(self::$testHistory); 71 $this->container['history'] = new History(self::$testHistory);
71 72
72 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
73 74
@@ -119,7 +120,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
119 ); 120 );
120 121
121 $historyEntry = $this->history->getHistory()[0]; 122 $historyEntry = $this->history->getHistory()[0];
122 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 123 $this->assertEquals(History::UPDATED, $historyEntry['event']);
123 $this->assertTrue( 124 $this->assertTrue(
124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 125 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
125 ); 126 );
@@ -198,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
198 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 199 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
199 $this->assertEquals(false, $data['private']); 200 $this->assertEquals(false, $data['private']);
200 $this->assertEquals( 201 $this->assertEquals(
201 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 202 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
202 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 203 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
203 ); 204 );
204 $this->assertEquals( 205 $this->assertEquals(
205 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 206 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
206 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 207 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
207 ); 208 );
208 } 209 }
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php
index e0787ce2..84e1d56e 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -3,13 +3,15 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
7use Slim\Container; 9use Slim\Container;
8use Slim\Http\Environment; 10use Slim\Http\Environment;
9use Slim\Http\Request; 11use Slim\Http\Request;
10use Slim\Http\Response; 12use Slim\Http\Response;
11 13
12class DeleteTagTest extends \PHPUnit_Framework_TestCase 14class DeleteTagTest extends \PHPUnit\Framework\TestCase
13{ 15{
14 /** 16 /**
15 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -32,12 +34,12 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 34 protected $refDB = null;
33 35
34 /** 36 /**
35 * @var \LinkDB instance. 37 * @var LinkDB instance.
36 */ 38 */
37 protected $linkDB; 39 protected $linkDB;
38 40
39 /** 41 /**
40 * @var \History instance. 42 * @var HistoryController instance.
41 */ 43 */
42 protected $history; 44 protected $history;
43 45
@@ -59,10 +61,10 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
59 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
60 $this->refDB = new \ReferenceLinkDB(); 62 $this->refDB = new \ReferenceLinkDB();
61 $this->refDB->write(self::$testDatastore); 63 $this->refDB->write(self::$testDatastore);
62 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 64 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory(); 65 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 66 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 67 $this->history = new History(self::$testHistory);
66 $this->container = new Container(); 68 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
68 $this->container['db'] = $this->linkDB; 70 $this->container['db'] = $this->linkDB;
@@ -97,18 +99,18 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
97 $this->assertEquals(204, $response->getStatusCode()); 99 $this->assertEquals(204, $response->getStatusCode());
98 $this->assertEmpty((string) $response->getBody()); 100 $this->assertEmpty((string) $response->getBody());
99 101
100 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 102 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
101 $tags = $this->linkDB->linksCountPerTag(); 103 $tags = $this->linkDB->linksCountPerTag();
102 $this->assertFalse(isset($tags[$tagName])); 104 $this->assertFalse(isset($tags[$tagName]));
103 105
104 // 2 links affected 106 // 2 links affected
105 $historyEntry = $this->history->getHistory()[0]; 107 $historyEntry = $this->history->getHistory()[0];
106 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 108 $this->assertEquals(History::UPDATED, $historyEntry['event']);
107 $this->assertTrue( 109 $this->assertTrue(
108 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 110 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
109 ); 111 );
110 $historyEntry = $this->history->getHistory()[1]; 112 $historyEntry = $this->history->getHistory()[1];
111 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 113 $this->assertEquals(History::UPDATED, $historyEntry['event']);
112 $this->assertTrue( 114 $this->assertTrue(
113 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 115 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
114 ); 116 );
@@ -131,13 +133,13 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
131 $this->assertEquals(204, $response->getStatusCode()); 133 $this->assertEquals(204, $response->getStatusCode());
132 $this->assertEmpty((string) $response->getBody()); 134 $this->assertEmpty((string) $response->getBody());
133 135
134 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 136 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
135 $tags = $this->linkDB->linksCountPerTag(); 137 $tags = $this->linkDB->linksCountPerTag();
136 $this->assertFalse(isset($tags[$tagName])); 138 $this->assertFalse(isset($tags[$tagName]));
137 $this->assertTrue($tags[strtolower($tagName)] > 0); 139 $this->assertTrue($tags[strtolower($tagName)] > 0);
138 140
139 $historyEntry = $this->history->getHistory()[0]; 141 $historyEntry = $this->history->getHistory()[0];
140 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 142 $this->assertEquals(History::UPDATED, $historyEntry['event']);
141 $this->assertTrue( 143 $this->assertTrue(
142 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 144 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
143 ); 145 );
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php
index afac228e..a2525c17 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -2,8 +2,8 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
6
7use Slim\Container; 7use Slim\Container;
8use Slim\Http\Environment; 8use Slim\Http\Environment;
9use Slim\Http\Request; 9use Slim\Http\Request;
@@ -16,7 +16,7 @@ use Slim\Http\Response;
16 * 16 *
17 * @package Shaarli\Api\Controllers 17 * @package Shaarli\Api\Controllers
18 */ 18 */
19class GetTagNameTest extends \PHPUnit_Framework_TestCase 19class GetTagNameTest extends \PHPUnit\Framework\TestCase
20{ 20{
21 /** 21 /**
22 * @var string datastore to test write operations 22 * @var string datastore to test write operations
@@ -59,7 +59,7 @@ class GetTagNameTest extends \PHPUnit_Framework_TestCase
59 59
60 $this->container = new Container(); 60 $this->container = new Container();
61 $this->container['conf'] = $this->conf; 61 $this->container['conf'] = $this->conf;
62 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 62 $this->container['db'] = new LinkDB(self::$testDatastore, true, false);
63 $this->container['history'] = null; 63 $this->container['history'] = null;
64 64
65 $this->controller = new Tags($this->container); 65 $this->controller = new Tags($this->container);
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php
index 3fab31b0..98628c98 100644
--- a/tests/api/controllers/tags/GetTagsTest.php
+++ b/tests/api/controllers/tags/GetTagsTest.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 6use Slim\Container;
7use Slim\Http\Environment; 7use Slim\Http\Environment;
8use Slim\Http\Request; 8use Slim\Http\Request;
@@ -15,7 +15,7 @@ use Slim\Http\Response;
15 * 15 *
16 * @package Shaarli\Api\Controllers 16 * @package Shaarli\Api\Controllers
17 */ 17 */
18class GetTagsTest extends \PHPUnit_Framework_TestCase 18class GetTagsTest extends \PHPUnit\Framework\TestCase
19{ 19{
20 /** 20 /**
21 * @var string datastore to test write operations 21 * @var string datastore to test write operations
@@ -38,7 +38,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
38 protected $container; 38 protected $container;
39 39
40 /** 40 /**
41 * @var \LinkDB instance. 41 * @var LinkDB instance.
42 */ 42 */
43 protected $linkDB; 43 protected $linkDB;
44 44
@@ -63,7 +63,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
63 63
64 $this->container = new Container(); 64 $this->container = new Container();
65 $this->container['conf'] = $this->conf; 65 $this->container['conf'] = $this->conf;
66 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 66 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
67 $this->container['db'] = $this->linkDB; 67 $this->container['db'] = $this->linkDB;
68 $this->container['history'] = null; 68 $this->container['history'] = null;
69 69
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index 38017243..86106fc7 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -1,16 +1,17 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6use Shaarli\Api\Exceptions\ApiBadParametersException; 5use Shaarli\Api\Exceptions\ApiBadParametersException;
6use Shaarli\Bookmark\LinkDB;
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
8use Slim\Container; 9use Slim\Container;
9use Slim\Http\Environment; 10use Slim\Http\Environment;
10use Slim\Http\Request; 11use Slim\Http\Request;
11use Slim\Http\Response; 12use Slim\Http\Response;
12 13
13class PutTagTest extends \PHPUnit_Framework_TestCase 14class PutTagTest extends \PHPUnit\Framework\TestCase
14{ 15{
15 /** 16 /**
16 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -33,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
33 protected $refDB = null; 34 protected $refDB = null;
34 35
35 /** 36 /**
36 * @var \History instance. 37 * @var HistoryController instance.
37 */ 38 */
38 protected $history; 39 protected $history;
39 40
@@ -43,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
43 protected $container; 44 protected $container;
44 45
45 /** 46 /**
46 * @var \LinkDB instance. 47 * @var LinkDB instance.
47 */ 48 */
48 protected $linkDB; 49 protected $linkDB;
49 50
@@ -68,11 +69,11 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
68 69
69 $refHistory = new \ReferenceHistory(); 70 $refHistory = new \ReferenceHistory();
70 $refHistory->write(self::$testHistory); 71 $refHistory->write(self::$testHistory);
71 $this->history = new \History(self::$testHistory); 72 $this->history = new History(self::$testHistory);
72 73
73 $this->container = new Container(); 74 $this->container = new Container();
74 $this->container['conf'] = $this->conf; 75 $this->container['conf'] = $this->conf;
75 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 76 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
76 $this->container['db'] = $this->linkDB; 77 $this->container['db'] = $this->linkDB;
77 $this->container['history'] = $this->history; 78 $this->container['history'] = $this->history;
78 79
@@ -113,12 +114,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
113 $this->assertEquals(2, $tags[$newName]); 114 $this->assertEquals(2, $tags[$newName]);
114 115
115 $historyEntry = $this->history->getHistory()[0]; 116 $historyEntry = $this->history->getHistory()[0];
116 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 117 $this->assertEquals(History::UPDATED, $historyEntry['event']);
117 $this->assertTrue( 118 $this->assertTrue(
118 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 119 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
119 ); 120 );
120 $historyEntry = $this->history->getHistory()[1]; 121 $historyEntry = $this->history->getHistory()[1];
121 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 122 $this->assertEquals(History::UPDATED, $historyEntry['event']);
122 $this->assertTrue( 123 $this->assertTrue(
123 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
124 ); 125 );
diff --git a/tests/LinkDBTest.php b/tests/bookmark/LinkDBTest.php
index c763c0cb..ff5c0b97 100644
--- a/tests/LinkDBTest.php
+++ b/tests/bookmark/LinkDBTest.php
@@ -3,9 +3,14 @@
3 * Link datastore tests 3 * Link datastore tests
4 */ 4 */
5 5
6require_once 'application/Cache.php'; 6namespace Shaarli\Bookmark;
7require_once 'application/FileUtils.php'; 7
8require_once 'application/LinkDB.php'; 8use DateTime;
9use ReferenceLinkDB;
10use ReflectionClass;
11use Shaarli;
12
13require_once 'application/feed/Cache.php';
9require_once 'application/Utils.php'; 14require_once 'application/Utils.php';
10require_once 'tests/utils/ReferenceLinkDB.php'; 15require_once 'tests/utils/ReferenceLinkDB.php';
11 16
@@ -13,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php';
13/** 18/**
14 * Unitary tests for LinkDB 19 * Unitary tests for LinkDB
15 */ 20 */
16class LinkDBTest extends PHPUnit_Framework_TestCase 21class LinkDBTest extends \PHPUnit\Framework\TestCase
17{ 22{
18 // datastore to test write operations 23 // datastore to test write operations
19 protected static $testDatastore = 'sandbox/datastore.php'; 24 protected static $testDatastore = 'sandbox/datastore.php';
@@ -73,7 +78,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
73 */ 78 */
74 protected static function getMethod($name) 79 protected static function getMethod($name)
75 { 80 {
76 $class = new ReflectionClass('LinkDB'); 81 $class = new ReflectionClass('Shaarli\Bookmark\LinkDB');
77 $method = $class->getMethod($name); 82 $method = $class->getMethod($name);
78 $method->setAccessible(true); 83 $method->setAccessible(true);
79 return $method; 84 return $method;
@@ -100,7 +105,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
100 /** 105 /**
101 * Attempt to instantiate a LinkDB whereas the datastore is not writable 106 * Attempt to instantiate a LinkDB whereas the datastore is not writable
102 * 107 *
103 * @expectedException IOException 108 * @expectedException Shaarli\Exceptions\IOException
104 * @expectedExceptionMessageRegExp /Error accessing "null"/ 109 * @expectedExceptionMessageRegExp /Error accessing "null"/
105 */ 110 */
106 public function testConstructDatastoreNotWriteable() 111 public function testConstructDatastoreNotWriteable()
@@ -187,12 +192,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
187 192
188 $link = array( 193 $link = array(
189 'id' => 42, 194 'id' => 42,
190 'title'=>'an additional link', 195 'title' => 'an additional link',
191 'url'=>'http://dum.my', 196 'url' => 'http://dum.my',
192 'description'=>'One more', 197 'description' => 'One more',
193 'private'=>0, 198 'private' => 0,
194 'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), 199 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'),
195 'tags'=>'unit test' 200 'tags' => 'unit test'
196 ); 201 );
197 $testDB[$link['id']] = $link; 202 $testDB[$link['id']] = $link;
198 $testDB->save('tests'); 203 $testDB->save('tests');
@@ -451,7 +456,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
451 /** 456 /**
452 * Test filterHash() with an invalid smallhash. 457 * Test filterHash() with an invalid smallhash.
453 * 458 *
454 * @expectedException LinkNotFoundException 459 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
455 */ 460 */
456 public function testFilterHashInValid1() 461 public function testFilterHashInValid1()
457 { 462 {
@@ -462,7 +467,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
462 /** 467 /**
463 * Test filterHash() with an empty smallhash. 468 * Test filterHash() with an empty smallhash.
464 * 469 *
465 * @expectedException LinkNotFoundException 470 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
466 */ 471 */
467 public function testFilterHashInValid() 472 public function testFilterHashInValid()
468 { 473 {
diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php
index eb54c359..808f8122 100644
--- a/tests/LinkFilterTest.php
+++ b/tests/bookmark/LinkFilterTest.php
@@ -1,11 +1,14 @@
1<?php 1<?php
2 2
3require_once 'application/LinkFilter.php'; 3namespace Shaarli\Bookmark;
4
5use Exception;
6use ReferenceLinkDB;
4 7
5/** 8/**
6 * Class LinkFilterTest. 9 * Class LinkFilterTest.
7 */ 10 */
8class LinkFilterTest extends PHPUnit_Framework_TestCase 11class LinkFilterTest extends \PHPUnit\Framework\TestCase
9{ 12{
10 /** 13 /**
11 * @var string Test datastore path. 14 * @var string Test datastore path.
@@ -27,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
27 protected static $linkDB; 30 protected static $linkDB;
28 31
29 /** 32 /**
30 * Instanciate linkFilter with ReferenceLinkDB data. 33 * Instantiate linkFilter with ReferenceLinkDB data.
31 */ 34 */
32 public static function setUpBeforeClass() 35 public static function setUpBeforeClass()
33 { 36 {
@@ -79,10 +82,14 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
79 count( 82 count(
80 self::$linkFilter->filter( 83 self::$linkFilter->filter(
81 LinkFilter::$FILTER_TAG, 84 LinkFilter::$FILTER_TAG,
82 /*$request=*/'', 85 /*$request=*/
83 /*$casesensitive=*/false, 86 '',
84 /*$visibility=*/'all', 87 /*$casesensitive=*/
85 /*$untaggedonly=*/true 88 false,
89 /*$visibility=*/
90 'all',
91 /*$untaggedonly=*/
92 true
86 ) 93 )
87 ) 94 )
88 ); 95 );
@@ -227,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
227 /** 234 /**
228 * No link for this hash 235 * No link for this hash
229 * 236 *
230 * @expectedException LinkNotFoundException 237 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
231 */ 238 */
232 public function testFilterUnknownSmallHash() 239 public function testFilterUnknownSmallHash()
233 { 240 {
diff --git a/tests/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 5407159a..1b8688e6 100644
--- a/tests/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -1,11 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/LinkUtils.php'; 3namespace Shaarli\Bookmark;
4
5use ReferenceLinkDB;
6
7require_once 'tests/utils/CurlUtils.php';
4 8
5/** 9/**
6* Class LinkUtilsTest. 10 * Class LinkUtilsTest.
7*/ 11 */
8class LinkUtilsTest extends PHPUnit_Framework_TestCase 12class LinkUtilsTest extends \PHPUnit\Framework\TestCase
9{ 13{
10 /** 14 /**
11 * Test html_extract_title() when the title is found. 15 * Test html_extract_title() when the title is found.
@@ -13,9 +17,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
13 public function testHtmlExtractExistentTitle() 17 public function testHtmlExtractExistentTitle()
14 { 18 {
15 $title = 'Read me please.'; 19 $title = 'Read me please.';
16 $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>'; 20 $html = '<html><meta>stuff</meta><title>' . $title . '</title></html>';
17 $this->assertEquals($title, html_extract_title($html)); 21 $this->assertEquals($title, html_extract_title($html));
18 $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>'; 22 $html = '<html><title>' . $title . '</title>blabla<title>another</title></html>';
19 $this->assertEquals($title, html_extract_title($html)); 23 $this->assertEquals($title, html_extract_title($html));
20 } 24 }
21 25
@@ -34,7 +38,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
34 public function testHeadersExtractExistentCharset() 38 public function testHeadersExtractExistentCharset()
35 { 39 {
36 $charset = 'x-MacCroatian'; 40 $charset = 'x-MacCroatian';
37 $headers = 'text/html; charset='. $charset; 41 $headers = 'text/html; charset=' . $charset;
38 $this->assertEquals(strtolower($charset), header_extract_charset($headers)); 42 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
39 } 43 }
40 44
@@ -56,7 +60,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
56 public function testHtmlExtractExistentCharset() 60 public function testHtmlExtractExistentCharset()
57 { 61 {
58 $charset = 'x-MacCroatian'; 62 $charset = 'x-MacCroatian';
59 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>'; 63 $html = '<html><meta>stuff2</meta><meta charset="' . $charset . '"/></html>';
60 $this->assertEquals(strtolower($charset), html_extract_charset($html)); 64 $this->assertEquals(strtolower($charset), html_extract_charset($html));
61 } 65 }
62 66
@@ -84,8 +88,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
84 'Content-Type: text/html; charset=utf-8', 88 'Content-Type: text/html; charset=utf-8',
85 'Status: 200 OK', 89 'Status: 200 OK',
86 'end' => 'th=device-width">' 90 'end' => 'th=device-width">'
87 .'<title>Refactoring · GitHub</title>' 91 . '<title>Refactoring · GitHub</title>'
88 .'<link rel="search" type="application/opensea', 92 . '<link rel="search" type="application/opensea',
89 '<title>ignored</title>', 93 '<title>ignored</title>',
90 ]; 94 ];
91 foreach ($data as $key => $line) { 95 foreach ($data as $key => $line) {
@@ -109,8 +113,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
109 $data = [ 113 $data = [
110 'HTTP/1.1 200 OK', 114 'HTTP/1.1 200 OK',
111 'end' => 'th=device-width">' 115 'end' => 'th=device-width">'
112 .'<title>Refactoring · GitHub</title>' 116 . '<title>Refactoring · GitHub</title>'
113 .'<link rel="search" type="application/opensea', 117 . '<link rel="search" type="application/opensea',
114 '<title>ignored</title>', 118 '<title>ignored</title>',
115 ]; 119 ];
116 foreach ($data as $key => $line) { 120 foreach ($data as $key => $line) {
@@ -131,8 +135,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
131 'HTTP/1.1 200 OK', 135 'HTTP/1.1 200 OK',
132 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', 136 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
133 'end' => 'th=device-width">' 137 'end' => 'th=device-width">'
134 .'<title>Refactoring · GitHub</title>' 138 . '<title>Refactoring · GitHub</title>'
135 .'<link rel="search" type="application/opensea', 139 . '<link rel="search" type="application/opensea',
136 '<title>ignored</title>', 140 '<title>ignored</title>',
137 ]; 141 ];
138 foreach ($data as $key => $line) { 142 foreach ($data as $key => $line) {
@@ -218,19 +222,19 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
218 { 222 {
219 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 223 $text = 'stuff http://hello.there/is=someone#here otherstuff';
220 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' 224 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
221 .'http://hello.there/is=someone#here</a> otherstuff'; 225 . 'http://hello.there/is=someone#here</a> otherstuff';
222 $processedText = text2clickable($text, ''); 226 $processedText = text2clickable($text, '');
223 $this->assertEquals($expectedText, $processedText); 227 $this->assertEquals($expectedText, $processedText);
224 228
225 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; 229 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
226 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' 230 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
227 .'http://hello.there/is=someone#here(please)</a> otherstuff'; 231 . 'http://hello.there/is=someone#here(please)</a> otherstuff';
228 $processedText = text2clickable($text, ''); 232 $processedText = text2clickable($text, '');
229 $this->assertEquals($expectedText, $processedText); 233 $this->assertEquals($expectedText, $processedText);
230 234
231 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; 235 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
232 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' 236 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
233 .'http://hello.there/is=someone#here(please)&no</a> otherstuff'; 237 . 'http://hello.there/is=someone#here(please)&no</a> otherstuff';
234 $processedText = text2clickable($text, ''); 238 $processedText = text2clickable($text, '');
235 $this->assertEquals($expectedText, $processedText); 239 $this->assertEquals($expectedText, $processedText);
236 } 240 }
@@ -242,7 +246,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
242 { 246 {
243 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 247 $text = 'stuff http://hello.there/is=someone#here otherstuff';
244 $redirector = 'http://redirector.to'; 248 $redirector = 'http://redirector.to';
245 $expectedText = 'stuff <a href="'. 249 $expectedText = 'stuff <a href="' .
246 $redirector . 250 $redirector .
247 urlencode('http://hello.there/is=someone#here') . 251 urlencode('http://hello.there/is=someone#here') .
248 '">http://hello.there/is=someone#here</a> otherstuff'; 252 '">http://hello.there/is=someone#here</a> otherstuff';
@@ -257,7 +261,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
257 { 261 {
258 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; 262 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff';
259 $redirector = 'http://redirector.to'; 263 $redirector = 'http://redirector.to';
260 $expectedText = 'stuff <a href="'. 264 $expectedText = 'stuff <a href="' .
261 $redirector . 265 $redirector .
262 'http://hello.there/?is=someone&or=something#here' . 266 'http://hello.there/?is=someone&or=something#here' .
263 '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; 267 '">http://hello.there/?is=someone&or=something#here</a> otherstuff';
@@ -270,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
270 */ 274 */
271 public function testSpace2nbsp() 275 public function testSpace2nbsp()
272 { 276 {
273 $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; 277 $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?';
274 $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?'. PHP_EOL .'&nbsp;Really?'; 278 $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?' . PHP_EOL . '&nbsp;Really?';
275 $processedText = space2nbsp($text); 279 $processedText = space2nbsp($text);
276 $this->assertEquals($expectedText, $processedText); 280 $this->assertEquals($expectedText, $processedText);
277 } 281 }
@@ -317,105 +321,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
317 * Util function to build an hashtag link. 321 * Util function to build an hashtag link.
318 * 322 *
319 * @param string $hashtag Hashtag name. 323 * @param string $hashtag Hashtag name.
320 * @param string $index Index URL. 324 * @param string $index Index URL.
321 * 325 *
322 * @return string HTML hashtag link. 326 * @return string HTML hashtag link.
323 */ 327 */
324 private function getHashtagLink($hashtag, $index = '') 328 private function getHashtagLink($hashtag, $index = '')
325 { 329 {
326 $hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>'; 330 $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>';
327 return str_replace('$1', $hashtag, $hashtagLink); 331 return str_replace('$1', $hashtag, $hashtagLink);
328 } 332 }
329} 333}
330
331// old style mock: PHPUnit doesn't allow function mock
332
333/**
334 * Returns code 200 or html content type.
335 *
336 * @param resource $ch cURL resource
337 * @param int $type cURL info type
338 *
339 * @return int|string 200 or 'text/html'
340 */
341function ut_curl_getinfo_ok($ch, $type)
342{
343 switch ($type) {
344 case CURLINFO_RESPONSE_CODE:
345 return 200;
346 case CURLINFO_CONTENT_TYPE:
347 return 'text/html; charset=utf-8';
348 }
349}
350
351/**
352 * Returns code 200 or html content type without charset.
353 *
354 * @param resource $ch cURL resource
355 * @param int $type cURL info type
356 *
357 * @return int|string 200 or 'text/html'
358 */
359function ut_curl_getinfo_no_charset($ch, $type)
360{
361 switch ($type) {
362 case CURLINFO_RESPONSE_CODE:
363 return 200;
364 case CURLINFO_CONTENT_TYPE:
365 return 'text/html';
366 }
367}
368
369/**
370 * Invalid response code.
371 *
372 * @param resource $ch cURL resource
373 * @param int $type cURL info type
374 *
375 * @return int|string 404 or 'text/html'
376 */
377function ut_curl_getinfo_rc_ko($ch, $type)
378{
379 switch ($type) {
380 case CURLINFO_RESPONSE_CODE:
381 return 404;
382 case CURLINFO_CONTENT_TYPE:
383 return 'text/html; charset=utf-8';
384 }
385}
386
387/**
388 * Invalid content type.
389 *
390 * @param resource $ch cURL resource
391 * @param int $type cURL info type
392 *
393 * @return int|string 200 or 'text/plain'
394 */
395function ut_curl_getinfo_ct_ko($ch, $type)
396{
397 switch ($type) {
398 case CURLINFO_RESPONSE_CODE:
399 return 200;
400 case CURLINFO_CONTENT_TYPE:
401 return 'text/plain';
402 }
403}
404
405/**
406 * Invalid response code and content type.
407 *
408 * @param resource $ch cURL resource
409 * @param int $type cURL info type
410 *
411 * @return int|string 404 or 'text/plain'
412 */
413function ut_curl_getinfo_rs_ct_ko($ch, $type)
414{
415 switch ($type) {
416 case CURLINFO_RESPONSE_CODE:
417 return 404;
418 case CURLINFO_CONTENT_TYPE:
419 return 'text/plain';
420 }
421}
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php
index d237bc80..95ad060b 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -4,7 +4,7 @@ namespace Shaarli\Config;
4/** 4/**
5 * Class ConfigJsonTest 5 * Class ConfigJsonTest
6 */ 6 */
7class ConfigJsonTest extends \PHPUnit_Framework_TestCase 7class ConfigJsonTest extends \PHPUnit\Framework\TestCase
8{ 8{
9 /** 9 /**
10 * @var ConfigJson 10 * @var ConfigJson
@@ -111,7 +111,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
111 /** 111 /**
112 * Write to invalid path. 112 * Write to invalid path.
113 * 113 *
114 * @expectedException \IOException 114 * @expectedException \Shaarli\Exceptions\IOException
115 */ 115 */
116 public function testWriteInvalidArray() 116 public function testWriteInvalidArray()
117 { 117 {
@@ -122,7 +122,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
122 /** 122 /**
123 * Write to invalid path. 123 * Write to invalid path.
124 * 124 *
125 * @expectedException \IOException 125 * @expectedException \Shaarli\Exceptions\IOException
126 */ 126 */
127 public function testWriteInvalidBlank() 127 public function testWriteInvalidBlank()
128 { 128 {
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 4a4e94ac..33830bc9 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Config;
7 * Note: it only test the manager with ConfigJson, 7 * Note: it only test the manager with ConfigJson,
8 * ConfigPhp is only a workaround to handle the transition to JSON type. 8 * ConfigPhp is only a workaround to handle the transition to JSON type.
9 */ 9 */
10class ConfigManagerTest extends \PHPUnit_Framework_TestCase 10class ConfigManagerTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * @var ConfigManager 13 * @var ConfigManager
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php
index be23eea1..67d878ce 100644
--- a/tests/config/ConfigPhpTest.php
+++ b/tests/config/ConfigPhpTest.php
@@ -4,7 +4,7 @@ namespace Shaarli\Config;
4/** 4/**
5 * Class ConfigPhpTest 5 * Class ConfigPhpTest
6 */ 6 */
7class ConfigPhpTest extends \PHPUnit_Framework_TestCase 7class ConfigPhpTest extends \PHPUnit\Framework\TestCase
8{ 8{
9 /** 9 /**
10 * @var ConfigPhp 10 * @var ConfigPhp
diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php
index deb02c9e..d7a70e68 100644
--- a/tests/config/ConfigPluginTest.php
+++ b/tests/config/ConfigPluginTest.php
@@ -8,7 +8,7 @@ require_once 'application/config/ConfigPlugin.php';
8/** 8/**
9 * Unitary tests for Shaarli config related functions 9 * Unitary tests for Shaarli config related functions
10 */ 10 */
11class ConfigPluginTest extends \PHPUnit_Framework_TestCase 11class ConfigPluginTest extends \PHPUnit\Framework\TestCase
12{ 12{
13 /** 13 /**
14 * Test save_plugin_config with valid data. 14 * Test save_plugin_config with valid data.
diff --git a/tests/CacheTest.php b/tests/feed/CacheTest.php
index f60fad91..c0a9f26f 100644
--- a/tests/CacheTest.php
+++ b/tests/feed/CacheTest.php
@@ -2,16 +2,17 @@
2/** 2/**
3 * Cache tests 3 * Cache tests
4 */ 4 */
5namespace Shaarli\Feed;
5 6
6// required to access $_SESSION array 7// required to access $_SESSION array
7session_start(); 8session_start();
8 9
9require_once 'application/Cache.php'; 10require_once 'application/feed/Cache.php';
10 11
11/** 12/**
12 * Unitary tests for cached pages 13 * Unitary tests for cached pages
13 */ 14 */
14class CacheTest extends PHPUnit_Framework_TestCase 15class CacheTest extends \PHPUnit\Framework\TestCase
15{ 16{
16 // test cache directory 17 // test cache directory
17 protected static $testCacheDir = 'sandbox/dummycache'; 18 protected static $testCacheDir = 'sandbox/dummycache';
@@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase
25 */ 26 */
26 public function setUp() 27 public function setUp()
27 { 28 {
28 if (! is_dir(self::$testCacheDir)) { 29 if (!is_dir(self::$testCacheDir)) {
29 mkdir(self::$testCacheDir); 30 mkdir(self::$testCacheDir);
30 } else { 31 } else {
31 array_map('unlink', glob(self::$testCacheDir.'/*')); 32 array_map('unlink', glob(self::$testCacheDir . '/*'));
32 } 33 }
33 34
34 foreach (self::$pages as $page) { 35 foreach (self::$pages as $page) {
35 file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); 36 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
36 } 37 }
37 file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); 38 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
38 } 39 }
39 40
40 /** 41 /**
@@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
42 */ 43 */
43 public function tearDown() 44 public function tearDown()
44 { 45 {
45 array_map('unlink', glob(self::$testCacheDir.'/*')); 46 array_map('unlink', glob(self::$testCacheDir . '/*'));
46 rmdir(self::$testCacheDir); 47 rmdir(self::$testCacheDir);
47 } 48 }
48 49
@@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase
53 { 54 {
54 purgeCachedPages(self::$testCacheDir); 55 purgeCachedPages(self::$testCacheDir);
55 foreach (self::$pages as $page) { 56 foreach (self::$pages as $page) {
56 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
57 } 58 }
58 59
59 $this->assertFileExists(self::$testCacheDir.'/intru.der'); 60 $this->assertFileExists(self::$testCacheDir . '/intru.der');
60 } 61 }
61 62
62 /** 63 /**
@@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
68 ini_set('error_log', '/dev/null'); 69 ini_set('error_log', '/dev/null');
69 $this->assertEquals( 70 $this->assertEquals(
70 'Cannot purge sandbox/dummycache_missing: no directory', 71 'Cannot purge sandbox/dummycache_missing: no directory',
71 purgeCachedPages(self::$testCacheDir.'_missing') 72 purgeCachedPages(self::$testCacheDir . '_missing')
72 ); 73 );
73 ini_set('error_log', $oldlog); 74 ini_set('error_log', $oldlog);
74 } 75 }
@@ -83,7 +84,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
83 84
84 invalidateCaches(self::$testCacheDir); 85 invalidateCaches(self::$testCacheDir);
85 foreach (self::$pages as $page) { 86 foreach (self::$pages as $page) {
86 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 87 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
87 } 88 }
88 89
89 $this->assertArrayNotHasKey('tags', $_SESSION); 90 $this->assertArrayNotHasKey('tags', $_SESSION);
diff --git a/tests/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 51565cd6..0bcc1442 100644
--- a/tests/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -2,13 +2,12 @@
2/** 2/**
3 * PageCache tests 3 * PageCache tests
4 */ 4 */
5 5namespace Shaarli\Feed;
6require_once 'application/CachedPage.php';
7 6
8/** 7/**
9 * Unitary tests for cached pages 8 * Unitary tests for cached pages
10 */ 9 */
11class CachedPageTest extends PHPUnit_Framework_TestCase 10class CachedPageTest extends \PHPUnit\Framework\TestCase
12{ 11{
13 // test cache directory 12 // test cache directory
14 protected static $testCacheDir = 'sandbox/pagecache'; 13 protected static $testCacheDir = 'sandbox/pagecache';
@@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase
20 */ 19 */
21 public static function setUpBeforeClass() 20 public static function setUpBeforeClass()
22 { 21 {
23 if (! is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
24 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
25 } 24 }
26 self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache'; 25 self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache';
27 } 26 }
28 27
29 /** 28 /**
diff --git a/tests/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 4ca58e5a..b496cb4c 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -1,14 +1,17 @@
1<?php 1<?php
2 2
3require_once 'application/FeedBuilder.php'; 3namespace Shaarli\Feed;
4require_once 'application/LinkDB.php'; 4
5use DateTime;
6use ReferenceLinkDB;
7use Shaarli\Bookmark\LinkDB;
5 8
6/** 9/**
7 * FeedBuilderTest class. 10 * FeedBuilderTest class.
8 * 11 *
9 * Unit tests for FeedBuilder. 12 * Unit tests for FeedBuilder.
10 */ 13 */
11class FeedBuilderTest extends PHPUnit_Framework_TestCase 14class FeedBuilderTest extends \PHPUnit\Framework\TestCase
12{ 15{
13 /** 16 /**
14 * @var string locale Basque (Spain). 17 * @var string locale Basque (Spain).
@@ -90,7 +93,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 93 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 94 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
92 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); 95 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
93 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); 96 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
94 $this->assertEquals($pub, $up); 97 $this->assertEquals($pub, $up);
95 $this->assertContains('Stallman has a beard', $link['description']); 98 $this->assertContains('Stallman has a beard', $link['description']);
96 $this->assertContains('Permalink', $link['description']); 99 $this->assertContains('Permalink', $link['description']);
diff --git a/tests/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php
index c15ac5cc..982e57e0 100644
--- a/tests/HttpUtils/ClientIpIdTest.php
+++ b/tests/http/HttpUtils/ClientIpIdTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for client_ip_id() 11 * Unitary tests for client_ip_id()
10 */ 12 */
11class ClientIpIdTest extends PHPUnit_Framework_TestCase 13class ClientIpIdTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Get a remote client ID based on its IP 16 * Get a remote client ID based on its IP
diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php
index ea53de5f..3dc5bc9b 100644
--- a/tests/HttpUtils/GetHttpUrlTest.php
+++ b/tests/http/HttpUtils/GetHttpUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for get_http_response() 11 * Unitary tests for get_http_response()
10 */ 12 */
11class GetHttpUrlTest extends PHPUnit_Framework_TestCase 13class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Get an invalid local URL 16 * Get an invalid local URL
@@ -17,12 +19,12 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase
17 { 19 {
18 // Local 20 // Local
19 list($headers, $content) = get_http_response('/non/existent', 1); 21 list($headers, $content) = get_http_response('/non/existent', 1);
20 $this->assertEquals('Invalid HTTP Url', $headers[0]); 22 $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
21 $this->assertFalse($content); 23 $this->assertFalse($content);
22 24
23 // Non HTTP 25 // Non HTTP
24 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1); 26 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
25 $this->assertEquals('Invalid HTTP Url', $headers[0]); 27 $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
26 $this->assertFalse($content); 28 $this->assertFalse($content);
27 } 29 }
28 30
diff --git a/tests/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
index 7af5bd9d..fe3a639e 100644
--- a/tests/HttpUtils/GetIpAdressFromProxyTest.php
+++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
@@ -1,11 +1,13 @@
1<?php 1<?php
2 2
3require_once 'application/HttpUtils.php'; 3namespace Shaarli\Http;
4
5require_once 'application/http/HttpUtils.php';
4 6
5/** 7/**
6 * Unitary tests for getIpAddressFromProxy() 8 * Unitary tests for getIpAddressFromProxy()
7 */ 9 */
8class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase 10class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
9{ 11{
10 12
11 /** 13 /**
diff --git a/tests/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php
index 337dcab0..bcbe59cb 100644
--- a/tests/HttpUtils/IndexUrlTest.php
+++ b/tests/http/HttpUtils/IndexUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for index_url() 11 * Unitary tests for index_url()
10 */ 12 */
11class IndexUrlTest extends PHPUnit_Framework_TestCase 13class IndexUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * If on the main page, remove "index.php" from the URL resource 16 * If on the main page, remove "index.php" from the URL resource
diff --git a/tests/HttpUtils/IsHttpsTest.php b/tests/http/HttpUtils/IsHttpsTest.php
index 097f2bcf..348956c6 100644
--- a/tests/HttpUtils/IsHttpsTest.php
+++ b/tests/http/HttpUtils/IsHttpsTest.php
@@ -1,12 +1,15 @@
1<?php 1<?php
2 2
3namespace Shaarli\Http;
4
5require_once 'application/http/HttpUtils.php';
3 6
4/** 7/**
5 * Class IsHttpsTest 8 * Class IsHttpsTest
6 * 9 *
7 * Test class for is_https() function. 10 * Test class for is_https() function.
8 */ 11 */
9class IsHttpsTest extends PHPUnit_Framework_TestCase 12class IsHttpsTest extends \PHPUnit\Framework\TestCase
10{ 13{
11 14
12 /** 15 /**
diff --git a/tests/HttpUtils/PageUrlTest.php b/tests/http/HttpUtils/PageUrlTest.php
index 4dbbe9cf..f1991716 100644
--- a/tests/HttpUtils/PageUrlTest.php
+++ b/tests/http/HttpUtils/PageUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for page_url() 11 * Unitary tests for page_url()
10 */ 12 */
11class PageUrlTest extends PHPUnit_Framework_TestCase 13class PageUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * If on the main page, remove "index.php" from the URL resource 16 * If on the main page, remove "index.php" from the URL resource
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/http/HttpUtils/ServerUrlTest.php
index 324b827a..9caf1049 100644
--- a/tests/HttpUtils/ServerUrlTest.php
+++ b/tests/http/HttpUtils/ServerUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for server_url() 11 * Unitary tests for server_url()
10 */ 12 */
11class ServerUrlTest extends PHPUnit_Framework_TestCase 13class ServerUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Detect if the server uses SSL 16 * Detect if the server uses SSL
diff --git a/tests/Url/UrlTest.php b/tests/http/UrlTest.php
index db229ce0..ae92f73a 100644
--- a/tests/Url/UrlTest.php
+++ b/tests/http/UrlTest.php
@@ -1,14 +1,14 @@
1<?php 1<?php
2/** 2/**
3 * Url's tests 3 * UrlUtils's tests
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8/** 8/**
9 * Unitary tests for URL utilities 9 * Unitary tests for URL utilities
10 */ 10 */
11class UrlTest extends PHPUnit_Framework_TestCase 11class UrlTest extends \PHPUnit\Framework\TestCase
12{ 12{
13 // base URL for tests 13 // base URL for tests
14 protected static $baseUrl = 'http://domain.tld:3000'; 14 protected static $baseUrl = 'http://domain.tld:3000';
@@ -18,7 +18,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
18 */ 18 */
19 private function assertUrlIsCleaned($query = '', $fragment = '') 19 private function assertUrlIsCleaned($query = '', $fragment = '')
20 { 20 {
21 $url = new Url(self::$baseUrl.$query.$fragment); 21 $url = new Url(self::$baseUrl . $query . $fragment);
22 $url->cleanup(); 22 $url->cleanup();
23 $this->assertEquals(self::$baseUrl, $url->toString()); 23 $this->assertEquals(self::$baseUrl, $url->toString());
24 } 24 }
@@ -38,7 +38,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
38 public function testConstruct() 38 public function testConstruct()
39 { 39 {
40 $ref = 'http://username:password@hostname:9090/path' 40 $ref = 'http://username:password@hostname:9090/path'
41 .'?arg1=value1&arg2=value2#anchor'; 41 . '?arg1=value1&arg2=value2#anchor';
42 $url = new Url($ref); 42 $url = new Url($ref);
43 $this->assertEquals($ref, $url->toString()); 43 $this->assertEquals($ref, $url->toString());
44 } 44 }
@@ -52,7 +52,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
52 $this->assertUrlIsCleaned(); 52 $this->assertUrlIsCleaned();
53 53
54 // URL with no annoying elements 54 // URL with no annoying elements
55 $ref = self::$baseUrl.'?p1=val1&p2=1234#edit'; 55 $ref = self::$baseUrl . '?p1=val1&p2=1234#edit';
56 $url = new Url($ref); 56 $url = new Url($ref);
57 $this->assertEquals($ref, $url->cleanup()); 57 $this->assertEquals($ref, $url->cleanup());
58 } 58 }
@@ -115,26 +115,26 @@ class UrlTest extends PHPUnit_Framework_TestCase
115 // ditch annoying query params and fragment, keep useful params 115 // ditch annoying query params and fragment, keep useful params
116 $url = new Url( 116 $url = new Url(
117 self::$baseUrl 117 self::$baseUrl
118 .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' 118 . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
119 ); 119 );
120 $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); 120 $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup());
121 121
122 122
123 // ditch annoying query params, keep useful params and fragment 123 // ditch annoying query params, keep useful params and fragment
124 $url = new Url( 124 $url = new Url(
125 self::$baseUrl 125 self::$baseUrl
126 .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' 126 . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
127 ); 127 );
128 $this->assertEquals( 128 $this->assertEquals(
129 self::$baseUrl.'?my=stuff&is=kept#again', 129 self::$baseUrl . '?my=stuff&is=kept#again',
130 $url->cleanup() 130 $url->cleanup()
131 ); 131 );
132 132
133 // test firefox reader url 133 // test firefox reader url
134 $url = new Url( 134 $url = new Url(
135 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') 135 'about://reader?url=' . urlencode(self::$baseUrl . '?my=stuff&is=kept')
136 ); 136 );
137 $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); 137 $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup());
138 } 138 }
139 139
140 /** 140 /**
diff --git a/tests/Url/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php
index 24791948..6c4d124b 100644
--- a/tests/Url/CleanupUrlTest.php
+++ b/tests/http/UrlUtils/CleanupUrlTest.php
@@ -3,9 +3,11 @@
3 * Unitary tests for cleanup_url() 3 * Unitary tests for cleanup_url()
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8class CleanupUrlTest extends PHPUnit_Framework_TestCase 8require_once 'application/http/UrlUtils.php';
9
10class CleanupUrlTest extends \PHPUnit\Framework\TestCase
9{ 11{
10 /** 12 /**
11 * @var string reference URL 13 * @var string reference URL
diff --git a/tests/Url/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php
index 18b932d6..2b97f7be 100644
--- a/tests/Url/GetUrlSchemeTest.php
+++ b/tests/http/UrlUtils/GetUrlSchemeTest.php
@@ -3,12 +3,14 @@
3 * Unitary tests for get_url_scheme() 3 * Unitary tests for get_url_scheme()
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8class GetUrlSchemeTest extends PHPUnit_Framework_TestCase 8require_once 'application/http/UrlUtils.php';
9
10class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase
9{ 11{
10 /** 12 /**
11 * Get empty scheme string for empty Url 13 * Get empty scheme string for empty UrlUtils
12 */ 14 */
13 public function testGetUrlSchemeEmpty() 15 public function testGetUrlSchemeEmpty()
14 { 16 {
@@ -16,7 +18,7 @@ class GetUrlSchemeTest extends PHPUnit_Framework_TestCase
16 } 18 }
17 19
18 /** 20 /**
19 * Get normal scheme of Url 21 * Get normal scheme of UrlUtils
20 */ 22 */
21 public function testGetUrlScheme() 23 public function testGetUrlScheme()
22 { 24 {
diff --git a/tests/Url/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php
index e314b484..040d8c54 100644
--- a/tests/Url/UnparseUrlTest.php
+++ b/tests/http/UrlUtils/UnparseUrlTest.php
@@ -1,14 +1,16 @@
1<?php 1<?php
2/** 2/**
3 * Unpares Url's tests 3 * Unpares UrlUtils's tests
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/UrlUtils.php';
7 9
8/** 10/**
9 * Unitary tests for unparse_url() 11 * Unitary tests for unparse_url()
10 */ 12 */
11class UnparseUrlTest extends PHPUnit_Framework_TestCase 13class UnparseUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Thanks for building nothing 16 * Thanks for building nothing
diff --git a/tests/Url/WhitelistProtocolsTest.php b/tests/http/UrlUtils/WhitelistProtocolsTest.php
index a3156804..69512dbd 100644
--- a/tests/Url/WhitelistProtocolsTest.php
+++ b/tests/http/UrlUtils/WhitelistProtocolsTest.php
@@ -1,15 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/Url.php'; 3namespace Shaarli\Http;
4 4
5use Shaarli\Config\ConfigManager; 5require_once 'application/http/UrlUtils.php';
6 6
7/** 7/**
8 * Class WhitelistProtocolsTest 8 * Class WhitelistProtocolsTest
9 * 9 *
10 * Test whitelist_protocols() function of Url. 10 * Test whitelist_protocols() function of UrlUtils.
11 */ 11 */
12class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase 12class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
13{ 13{
14 /** 14 /**
15 * Test whitelist_protocols() on a note (relative URL). 15 * Test whitelist_protocols() on a note (relative URL).
diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
index 38347de1..b8b7ca3a 100644
--- a/tests/languages/fr/LanguagesFrTest.php
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager;
12 * 12 *
13 * @package Shaarli 13 * @package Shaarli
14 */ 14 */
15class LanguagesFrTest extends \PHPUnit_Framework_TestCase 15class LanguagesFrTest extends \PHPUnit\Framework\TestCase
16{ 16{
17 /** 17 /**
18 * @var string Config file path (without extension). 18 * @var string Config file path (without extension).
diff --git a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 77fbd5f3..6de9876d 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -1,11 +1,14 @@
1<?php 1<?php
2namespace Shaarli\Netscape;
2 3
3require_once 'application/NetscapeBookmarkUtils.php'; 4use Shaarli\Bookmark\LinkDB;
5
6require_once 'tests/utils/ReferenceLinkDB.php';
4 7
5/** 8/**
6 * Netscape bookmark export 9 * Netscape bookmark export
7 */ 10 */
8class BookmarkExportTest extends PHPUnit_Framework_TestCase 11class BookmarkExportTest extends \PHPUnit\Framework\TestCase
9{ 12{
10 /** 13 /**
11 * @var string datastore to test write operations 14 * @var string datastore to test write operations
@@ -13,7 +16,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
13 protected static $testDatastore = 'sandbox/datastore.php'; 16 protected static $testDatastore = 'sandbox/datastore.php';
14 17
15 /** 18 /**
16 * @var ReferenceLinkDB instance. 19 * @var \ReferenceLinkDB instance.
17 */ 20 */
18 protected static $refDb = null; 21 protected static $refDb = null;
19 22
@@ -27,7 +30,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
27 */ 30 */
28 public static function setUpBeforeClass() 31 public static function setUpBeforeClass()
29 { 32 {
30 self::$refDb = new ReferenceLinkDB(); 33 self::$refDb = new \ReferenceLinkDB();
31 self::$refDb->write(self::$testDatastore); 34 self::$refDb->write(self::$testDatastore);
32 self::$linkDb = new LinkDB(self::$testDatastore, true, false); 35 self::$linkDb = new LinkDB(self::$testDatastore, true, false);
33 } 36 }
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php
index f0a958cb..ccafc161 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/netscape/BookmarkImportTest.php
@@ -1,8 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Netscape;
2 3
3require_once 'application/NetscapeBookmarkUtils.php'; 4use DateTime;
4 5use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
6 8
7/** 9/**
8 * Utility function to load a file's metadata in a $_FILES-like array 10 * Utility function to load a file's metadata in a $_FILES-like array
@@ -26,7 +28,7 @@ function file2array($filename)
26/** 28/**
27 * Netscape bookmark import 29 * Netscape bookmark import
28 */ 30 */
29class BookmarkImportTest extends PHPUnit_Framework_TestCase 31class BookmarkImportTest extends \PHPUnit\Framework\TestCase
30{ 32{
31 /** 33 /**
32 * @var string datastore to test write operations 34 * @var string datastore to test write operations
diff --git a/tests/NetscapeBookmarkUtils/input/empty.htm b/tests/netscape/input/empty.htm
index e69de29b..e69de29b 100644
--- a/tests/NetscapeBookmarkUtils/input/empty.htm
+++ b/tests/netscape/input/empty.htm
diff --git a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm b/tests/netscape/input/internet_explorer_encoding.htm
index 18703cf6..18703cf6 100644
--- a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm
+++ b/tests/netscape/input/internet_explorer_encoding.htm
diff --git a/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm b/tests/netscape/input/lowercase_doctype.htm
index 8911ad19..8911ad19 100644
--- a/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm
+++ b/tests/netscape/input/lowercase_doctype.htm
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_basic.htm b/tests/netscape/input/netscape_basic.htm
index affe0cf8..affe0cf8 100644
--- a/tests/NetscapeBookmarkUtils/input/netscape_basic.htm
+++ b/tests/netscape/input/netscape_basic.htm
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_nested.htm b/tests/netscape/input/netscape_nested.htm
index b486fe18..b486fe18 100644
--- a/tests/NetscapeBookmarkUtils/input/netscape_nested.htm
+++ b/tests/netscape/input/netscape_nested.htm
diff --git a/tests/NetscapeBookmarkUtils/input/no_doctype.htm b/tests/netscape/input/no_doctype.htm
index 766d398b..766d398b 100644
--- a/tests/NetscapeBookmarkUtils/input/no_doctype.htm
+++ b/tests/netscape/input/no_doctype.htm
diff --git a/tests/NetscapeBookmarkUtils/input/same_date.htm b/tests/netscape/input/same_date.htm
index 9d58a582..9d58a582 100644
--- a/tests/NetscapeBookmarkUtils/input/same_date.htm
+++ b/tests/netscape/input/same_date.htm
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index b6239e7f..d052f8b9 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -1,17 +1,15 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Addlink;
2 3
3/** 4use Shaarli\Plugin\PluginManager;
4 * PluginPlayvideosTest.php 5use Shaarli\Router;
5 */
6 6
7require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; 7require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
8require_once 'application/Router.php';
9 8
10/** 9/**
11 * Class PluginAddlinkTest
12 * Unit test for the Addlink toolbar plugin 10 * Unit test for the Addlink toolbar plugin
13 */ 11 */
14class PluginAddlinkTest extends PHPUnit_Framework_TestCase 12class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
15{ 13{
16 /** 14 /**
17 * Reset plugin path. 15 * Reset plugin path.
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
index fecd5f2c..510288bb 100644
--- a/tests/plugins/PluginArchiveorgTest.php
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -1,16 +1,19 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Archiveorg;
2 3
3/** 4/**
4 * PluginArchiveorgTest.php 5 * PluginArchiveorgTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9
7require_once 'plugins/archiveorg/archiveorg.php'; 10require_once 'plugins/archiveorg/archiveorg.php';
8 11
9/** 12/**
10 * Class PluginArchiveorgTest 13 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin 14 * Unit test for the archiveorg plugin
12 */ 15 */
13class PluginArchiveorgTest extends PHPUnit_Framework_TestCase 16class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase
14{ 17{
15 /** 18 /**
16 * Reset plugin path 19 * Reset plugin path
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 2c9efbcd..bdfab439 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -1,5 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Isso;
3
4use DateTime;
5use Shaarli\Bookmark\LinkDB;
2use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\Plugin\PluginManager;
3 8
4require_once 'plugins/isso/isso.php'; 9require_once 'plugins/isso/isso.php';
5 10
@@ -8,7 +13,7 @@ require_once 'plugins/isso/isso.php';
8 * 13 *
9 * Test the Isso plugin (comment system). 14 * Test the Isso plugin (comment system).
10 */ 15 */
11class PluginIssoTest extends PHPUnit_Framework_TestCase 16class PluginIssoTest extends \PHPUnit\Framework\TestCase
12{ 17{
13 /** 18 /**
14 * Reset plugin path 19 * Reset plugin path
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index 44364b05..5e7c02b0 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -1,10 +1,14 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Markdown;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
3 6
4/** 7/**
5 * PluginMarkdownTest.php 8 * PluginMarkdownTest.php
6 */ 9 */
7 10
11require_once 'application/bookmark/LinkUtils.php';
8require_once 'application/Utils.php'; 12require_once 'application/Utils.php';
9require_once 'plugins/markdown/markdown.php'; 13require_once 'plugins/markdown/markdown.php';
10 14
@@ -12,7 +16,7 @@ require_once 'plugins/markdown/markdown.php';
12 * Class PluginMarkdownTest 16 * Class PluginMarkdownTest
13 * Unit test for the Markdown plugin 17 * Unit test for the Markdown plugin
14 */ 18 */
15class PluginMarkdownTest extends PHPUnit_Framework_TestCase 19class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
16{ 20{
17 /** 21 /**
18 * @var ConfigManager instance. 22 * @var ConfigManager instance.
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index 29ad047f..51472617 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -1,17 +1,20 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Playvideos;
2 3
3/** 4/**
4 * PluginPlayvideosTest.php 5 * PluginPlayvideosTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
7require_once 'plugins/playvideos/playvideos.php'; 11require_once 'plugins/playvideos/playvideos.php';
8require_once 'application/Router.php';
9 12
10/** 13/**
11 * Class PluginPlayvideosTest 14 * Class PluginPlayvideosTest
12 * Unit test for the PlayVideos plugin 15 * Unit test for the PlayVideos plugin
13 */ 16 */
14class PluginPlayvideosTest extends PHPUnit_Framework_TestCase 17class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase
15{ 18{
16 /** 19 /**
17 * Reset plugin path 20 * Reset plugin path
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
index 69d00936..a7bd8fc9 100644
--- a/tests/plugins/PluginPubsubhubbubTest.php
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -1,14 +1,17 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Pubsubhubbub;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
6use Shaarli\Router;
3 7
4require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; 8require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
5require_once 'application/Router.php';
6 9
7/** 10/**
8 * Class PluginPubsubhubbubTest 11 * Class PluginPubsubhubbubTest
9 * Unit test for the pubsubhubbub plugin 12 * Unit test for the pubsubhubbub plugin
10 */ 13 */
11class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase 14class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
12{ 15{
13 /** 16 /**
14 * @var string Config file path (without extension). 17 * @var string Config file path (without extension).
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index dd632eee..0c61e14a 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -1,16 +1,20 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Qrcode;
3
2/** 4/**
3 * PluginQrcodeTest.php 5 * PluginQrcodeTest.php
4 */ 6 */
5 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
6require_once 'plugins/qrcode/qrcode.php'; 11require_once 'plugins/qrcode/qrcode.php';
7require_once 'application/Router.php';
8 12
9/** 13/**
10 * Class PluginQrcodeTest 14 * Class PluginQrcodeTest
11 * Unit test for the QR-Code plugin 15 * Unit test for the QR-Code plugin
12 */ 16 */
13class PluginQrcodeTest extends PHPUnit_Framework_TestCase 17class PluginQrcodeTest extends \PHPUnit\Framework\TestCase
14{ 18{
15 /** 19 /**
16 * Reset plugin path 20 * Reset plugin path
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 76b7887e..79751921 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -1,9 +1,8 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli\Plugin\Wallabag;
3 3
4/** 4use Shaarli\Config\ConfigManager;
5 * PluginWallabagTest.php.php 5use Shaarli\Plugin\PluginManager;
6 */
7 6
8require_once 'plugins/wallabag/wallabag.php'; 7require_once 'plugins/wallabag/wallabag.php';
9 8
@@ -11,7 +10,7 @@ require_once 'plugins/wallabag/wallabag.php';
11 * Class PluginWallabagTest 10 * Class PluginWallabagTest
12 * Unit test for the Wallabag plugin 11 * Unit test for the Wallabag plugin
13 */ 12 */
14class PluginWallabagTest extends PHPUnit_Framework_TestCase 13class PluginWallabagTest extends \PHPUnit\Framework\TestCase
15{ 14{
16 /** 15 /**
17 * Reset plugin path 16 * Reset plugin path
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index 2c466871..a3cd9076 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -1,11 +1,10 @@
1<?php 1<?php
2 2namespace Shaarli\Plugin\Wallabag;
3require_once 'plugins/wallabag/WallabagInstance.php';
4 3
5/** 4/**
6 * Class WallabagInstanceTest 5 * Class WallabagInstanceTest
7 */ 6 */
8class WallabagInstanceTest extends PHPUnit_Framework_TestCase 7class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
9{ 8{
10 /** 9 /**
11 * @var string wallabag url. 10 * @var string wallabag url.
diff --git a/tests/ThemeUtilsTest.php b/tests/render/ThemeUtilsTest.php
index e44564be..58e3426b 100644
--- a/tests/ThemeUtilsTest.php
+++ b/tests/render/ThemeUtilsTest.php
@@ -1,13 +1,13 @@
1<?php 1<?php
2 2
3namespace Shaarli; 3namespace Shaarli\Render;
4 4
5/** 5/**
6 * Class ThemeUtilsTest 6 * Class ThemeUtilsTest
7 * 7 *
8 * @package Shaarli 8 * @package Shaarli
9 */ 9 */
10class ThemeUtilsTest extends \PHPUnit_Framework_TestCase 10class ThemeUtilsTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * Test getThemes() with existing theme directories. 13 * Test getThemes() with existing theme directories.
diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php
index f26cd1eb..de8055ed 100644
--- a/tests/security/LoginManagerTest.php
+++ b/tests/security/LoginManagerTest.php
@@ -2,7 +2,8 @@
2namespace Shaarli\Security; 2namespace Shaarli\Security;
3 3
4require_once 'tests/utils/FakeConfigManager.php'; 4require_once 'tests/utils/FakeConfigManager.php';
5use \PHPUnit\Framework\TestCase; 5
6use PHPUnit\Framework\TestCase;
6 7
7/** 8/**
8 * Test coverage for LoginManager 9 * Test coverage for LoginManager
diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php
index 7961e771..f264505e 100644
--- a/tests/security/SessionManagerTest.php
+++ b/tests/security/SessionManagerTest.php
@@ -5,8 +5,8 @@ require_once 'tests/utils/FakeConfigManager.php';
5require_once 'tests/utils/ReferenceSessionIdHashes.php'; 5require_once 'tests/utils/ReferenceSessionIdHashes.php';
6ReferenceSessionIdHashes::genAllHashes(); 6ReferenceSessionIdHashes::genAllHashes();
7 7
8use \Shaarli\Security\SessionManager; 8use PHPUnit\Framework\TestCase;
9use \PHPUnit\Framework\TestCase; 9use Shaarli\Security\SessionManager;
10 10
11/** 11/**
12 * Test coverage for SessionManager 12 * Test coverage for SessionManager
diff --git a/tests/Updater/DummyUpdater.php b/tests/updater/DummyUpdater.php
index a805ab5e..9e866f1f 100644
--- a/tests/Updater/DummyUpdater.php
+++ b/tests/updater/DummyUpdater.php
@@ -1,10 +1,15 @@
1<?php 1<?php
2namespace Shaarli\Updater;
2 3
3require_once 'application/Updater.php'; 4use Exception;
5use ReflectionClass;
6use ReflectionMethod;
7use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager;
4 9
5/** 10/**
6 * Class DummyUpdater. 11 * Class DummyUpdater.
7 * Extends Updater to add update method designed for unit tests. 12 * Extends updater to add update method designed for unit tests.
8 */ 13 */
9class DummyUpdater extends Updater 14class DummyUpdater extends Updater
10{ 15{
diff --git a/tests/Updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index c4a6e7ef..d7df5963 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -1,17 +1,24 @@
1<?php 1<?php
2namespace Shaarli\Updater;
3
4use DateTime;
5use Exception;
6use Shaarli\Bookmark\LinkDB;
2use Shaarli\Config\ConfigJson; 7use Shaarli\Config\ConfigJson;
3use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
4use Shaarli\Config\ConfigPhp; 9use Shaarli\Config\ConfigPhp;
5use Shaarli\Thumbnailer; 10use Shaarli\Thumbnailer;
6 11
7require_once 'tests/Updater/DummyUpdater.php'; 12require_once 'application/updater/UpdaterUtils.php';
13require_once 'tests/updater/DummyUpdater.php';
14require_once 'tests/utils/ReferenceLinkDB.php';
8require_once 'inc/rain.tpl.class.php'; 15require_once 'inc/rain.tpl.class.php';
9 16
10/** 17/**
11 * Class UpdaterTest. 18 * Class UpdaterTest.
12 * Runs unit tests against the Updater class. 19 * Runs unit tests against the updater class.
13 */ 20 */
14class UpdaterTest extends PHPUnit_Framework_TestCase 21class UpdaterTest extends \PHPUnit\Framework\TestCase
15{ 22{
16 /** 23 /**
17 * @var string Path to test datastore. 24 * @var string Path to test datastore.
@@ -153,7 +160,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
153 /** 160 /**
154 * Test Update failed. 161 * Test Update failed.
155 * 162 *
156 * @expectedException UpdaterException 163 * @expectedException \Exception
157 */ 164 */
158 public function testUpdateFailed() 165 public function testUpdateFailed()
159 { 166 {
@@ -179,17 +186,17 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
179 $this->conf->setConfigFile('tests/utils/config/configPhp'); 186 $this->conf->setConfigFile('tests/utils/config/configPhp');
180 $this->conf->reset(); 187 $this->conf->reset();
181 188
182 $optionsFile = 'tests/Updater/options.php'; 189 $optionsFile = 'tests/updater/options.php';
183 $options = '<?php 190 $options = '<?php
184$GLOBALS[\'privateLinkByDefault\'] = true;'; 191$GLOBALS[\'privateLinkByDefault\'] = true;';
185 file_put_contents($optionsFile, $options); 192 file_put_contents($optionsFile, $options);
186 193
187 // tmp config file. 194 // tmp config file.
188 $this->conf->setConfigFile('tests/Updater/config'); 195 $this->conf->setConfigFile('tests/updater/config');
189 196
190 // merge configs 197 // merge configs
191 $updater = new Updater(array(), array(), $this->conf, true); 198 $updater = new Updater(array(), array(), $this->conf, true);
192 // This writes a new config file in tests/Updater/config.php 199 // This writes a new config file in tests/updater/config.php
193 $updater->updateMethodMergeDeprecatedConfigFile(); 200 $updater->updateMethodMergeDeprecatedConfigFile();
194 201
195 // make sure updated field is changed 202 // make sure updated field is changed
@@ -216,7 +223,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
216 */ 223 */
217 public function testRenameDashTags() 224 public function testRenameDashTags()
218 { 225 {
219 $refDB = new ReferenceLinkDB(); 226 $refDB = new \ReferenceLinkDB();
220 $refDB->write(self::$testDatastore); 227 $refDB->write(self::$testDatastore);
221 $linkDB = new LinkDB(self::$testDatastore, true, false); 228 $linkDB = new LinkDB(self::$testDatastore, true, false);
222 229
@@ -362,7 +369,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
362 'private' => true, 369 'private' => true,
363 ), 370 ),
364 ); 371 );
365 $refDB = new ReferenceLinkDB(); 372 $refDB = new \ReferenceLinkDB();
366 $refDB->setLinks($links); 373 $refDB->setLinks($links);
367 $refDB->write(self::$testDatastore); 374 $refDB->write(self::$testDatastore);
368 $linkDB = new LinkDB(self::$testDatastore, true, false); 375 $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -426,7 +433,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
426 */ 433 */
427 public function testDatastoreIdsNothingToDo() 434 public function testDatastoreIdsNothingToDo()
428 { 435 {
429 $refDB = new ReferenceLinkDB(); 436 $refDB = new \ReferenceLinkDB();
430 $refDB->write(self::$testDatastore); 437 $refDB->write(self::$testDatastore);
431 $linkDB = new LinkDB(self::$testDatastore, true, false); 438 $linkDB = new LinkDB(self::$testDatastore, true, false);
432 439
@@ -763,7 +770,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
763 1 => ['id' => 1] + $blank, 770 1 => ['id' => 1] + $blank,
764 2 => ['id' => 2] + $blank, 771 2 => ['id' => 2] + $blank,
765 ]; 772 ];
766 $refDB = new ReferenceLinkDB(); 773 $refDB = new \ReferenceLinkDB();
767 $refDB->setLinks($links); 774 $refDB->setLinks($links);
768 $refDB->write(self::$testDatastore); 775 $refDB->write(self::$testDatastore);
769 $linkDB = new LinkDB(self::$testDatastore, true, false); 776 $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -794,7 +801,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
794 1 => ['id' => 1, 'sticky' => true] + $blank, 801 1 => ['id' => 1, 'sticky' => true] + $blank,
795 2 => ['id' => 2] + $blank, 802 2 => ['id' => 2] + $blank,
796 ]; 803 ];
797 $refDB = new ReferenceLinkDB(); 804 $refDB = new \ReferenceLinkDB();
798 $refDB->setLinks($links); 805 $refDB->setLinks($links);
799 $refDB->write(self::$testDatastore); 806 $refDB->write(self::$testDatastore);
800 $linkDB = new LinkDB(self::$testDatastore, true, false); 807 $linkDB = new LinkDB(self::$testDatastore, true, false);
diff --git a/tests/utils/CurlUtils.php b/tests/utils/CurlUtils.php
new file mode 100644
index 00000000..1cc4907e
--- /dev/null
+++ b/tests/utils/CurlUtils.php
@@ -0,0 +1,94 @@
1<?php
2/**
3 * Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions
4 */
5
6/**
7 * Returns code 200 or html content type.
8 *
9 * @param resource $ch cURL resource
10 * @param int $type cURL info type
11 *
12 * @return int|string 200 or 'text/html'
13 */
14function ut_curl_getinfo_ok($ch, $type)
15{
16 switch ($type) {
17 case CURLINFO_RESPONSE_CODE:
18 return 200;
19 case CURLINFO_CONTENT_TYPE:
20 return 'text/html; charset=utf-8';
21 }
22}
23
24/**
25 * Returns code 200 or html content type without charset.
26 *
27 * @param resource $ch cURL resource
28 * @param int $type cURL info type
29 *
30 * @return int|string 200 or 'text/html'
31 */
32function ut_curl_getinfo_no_charset($ch, $type)
33{
34 switch ($type) {
35 case CURLINFO_RESPONSE_CODE:
36 return 200;
37 case CURLINFO_CONTENT_TYPE:
38 return 'text/html';
39 }
40}
41
42/**
43 * Invalid response code.
44 *
45 * @param resource $ch cURL resource
46 * @param int $type cURL info type
47 *
48 * @return int|string 404 or 'text/html'
49 */
50function ut_curl_getinfo_rc_ko($ch, $type)
51{
52 switch ($type) {
53 case CURLINFO_RESPONSE_CODE:
54 return 404;
55 case CURLINFO_CONTENT_TYPE:
56 return 'text/html; charset=utf-8';
57 }
58}
59
60/**
61 * Invalid content type.
62 *
63 * @param resource $ch cURL resource
64 * @param int $type cURL info type
65 *
66 * @return int|string 200 or 'text/plain'
67 */
68function ut_curl_getinfo_ct_ko($ch, $type)
69{
70 switch ($type) {
71 case CURLINFO_RESPONSE_CODE:
72 return 200;
73 case CURLINFO_CONTENT_TYPE:
74 return 'text/plain';
75 }
76}
77
78/**
79 * Invalid response code and content type.
80 *
81 * @param resource $ch cURL resource
82 * @param int $type cURL info type
83 *
84 * @return int|string 404 or 'text/plain'
85 */
86function ut_curl_getinfo_rs_ct_ko($ch, $type)
87{
88 switch ($type) {
89 case CURLINFO_RESPONSE_CODE:
90 return 404;
91 case CURLINFO_CONTENT_TYPE:
92 return 'text/plain';
93 }
94}
diff --git a/tests/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php
new file mode 100644
index 00000000..de83d598
--- /dev/null
+++ b/tests/utils/FakeApplicationUtils.php
@@ -0,0 +1,19 @@
1<?php
2
3namespace Shaarli;
4
5/**
6 * Fake ApplicationUtils class to avoid HTTP requests
7 */
8class FakeApplicationUtils extends ApplicationUtils
9{
10 public static $VERSION_CODE = '';
11
12 /**
13 * Toggle HTTP requests, allow overriding the version code
14 */
15 public static function getVersion($url, $timeout = 0)
16 {
17 return self::$VERSION_CODE;
18 }
19}
diff --git a/tests/utils/ReferenceHistory.php b/tests/utils/ReferenceHistory.php
index 75cbb326..e411c417 100644
--- a/tests/utils/ReferenceHistory.php
+++ b/tests/utils/ReferenceHistory.php
@@ -1,5 +1,8 @@
1<?php 1<?php
2 2
3use Shaarli\FileUtils;
4use Shaarli\History;
5
3/** 6/**
4 * Populates a reference history 7 * Populates a reference history
5 */ 8 */
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index 59679e38..c12bcb67 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -1,4 +1,7 @@
1<?php 1<?php
2
3use Shaarli\Bookmark\LinkDB;
4
2/** 5/**
3 * Populates a reference datastore to test LinkDB 6 * Populates a reference datastore to test LinkDB
4 */ 7 */
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php
index 34b11fcd..7dc81e22 100644
--- a/tests/utils/config/configPhp.php
+++ b/tests/utils/config/configPhp.php
@@ -8,7 +8,7 @@ $GLOBALS['titleLink'] = 'titleLink';
8$GLOBALS['redirector'] = 'lala'; 8$GLOBALS['redirector'] = 'lala';
9$GLOBALS['disablesessionprotection'] = false; 9$GLOBALS['disablesessionprotection'] = false;
10$GLOBALS['privateLinkByDefault'] = false; 10$GLOBALS['privateLinkByDefault'] = false;
11$GLOBALS['config']['DATADIR'] = 'tests/Updater'; 11$GLOBALS['config']['DATADIR'] = 'tests/updater';
12$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache'; 12$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
13$GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; 13$GLOBALS['config']['DATASTORE'] = 'data/datastore.php';
14$GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; 14$GLOBALS['plugins']['WALLABAG_VERSION'] = '1';