diff options
-rw-r--r-- | application/ApplicationUtils.php | 75 | ||||
-rw-r--r-- | application/render/PageBuilder.php | 2 | ||||
-rw-r--r-- | application/updater/Updater.php | 2 | ||||
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | tests/ApplicationUtilsTest.php | 27 | ||||
-rw-r--r-- | tests/utils/FakeApplicationUtils.php | 19 |
6 files changed, 67 insertions, 62 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 |
2 | namespace Shaarli; | ||
3 | |||
4 | use Exception; | ||
5 | use 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/render/PageBuilder.php b/application/render/PageBuilder.php index 9a0fe61a..1c5b9251 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Render; | 3 | namespace Shaarli\Render; |
4 | 4 | ||
5 | use ApplicationUtils; | 5 | use Shaarli\ApplicationUtils; |
6 | use Exception; | 6 | use Exception; |
7 | use Shaarli\Bookmark\LinkDB; | 7 | use Shaarli\Bookmark\LinkDB; |
8 | use RainTPL; | 8 | use RainTPL; |
diff --git a/application/updater/Updater.php b/application/updater/Updater.php index 55251a30..89f0ff7f 100644 --- a/application/updater/Updater.php +++ b/application/updater/Updater.php | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Updater; | 3 | namespace Shaarli\Updater; |
4 | 4 | ||
5 | use ApplicationUtils; | 5 | use Shaarli\ApplicationUtils; |
6 | use Exception; | 6 | use Exception; |
7 | use RainTPL; | 7 | use RainTPL; |
8 | use ReflectionClass; | 8 | use ReflectionClass; |
@@ -56,7 +56,6 @@ require_once 'inc/rain.tpl.class.php'; | |||
56 | require_once __DIR__ . '/vendor/autoload.php'; | 56 | require_once __DIR__ . '/vendor/autoload.php'; |
57 | 57 | ||
58 | // Shaarli library | 58 | // Shaarli library |
59 | require_once 'application/ApplicationUtils.php'; | ||
60 | require_once 'application/bookmark/LinkUtils.php'; | 59 | require_once 'application/bookmark/LinkUtils.php'; |
61 | require_once 'application/config/ConfigPlugin.php'; | 60 | require_once 'application/config/ConfigPlugin.php'; |
62 | require_once 'application/feed/Cache.php'; | 61 | require_once 'application/feed/Cache.php'; |
@@ -71,6 +70,7 @@ require_once 'application/Utils.php'; | |||
71 | require_once 'application/PluginManager.php'; | 70 | require_once 'application/PluginManager.php'; |
72 | require_once 'application/Router.php'; | 71 | require_once 'application/Router.php'; |
73 | 72 | ||
73 | use \Shaarli\ApplicationUtils; | ||
74 | use \Shaarli\Bookmark\Exception\LinkNotFoundException; | 74 | use \Shaarli\Bookmark\Exception\LinkNotFoundException; |
75 | use \Shaarli\Bookmark\LinkDB; | 75 | use \Shaarli\Bookmark\LinkDB; |
76 | use \Shaarli\Config\ConfigManager; | 76 | use \Shaarli\Config\ConfigManager; |
@@ -83,7 +83,7 @@ use \Shaarli\Render\ThemeUtils; | |||
83 | use \Shaarli\Security\LoginManager; | 83 | use \Shaarli\Security\LoginManager; |
84 | use \Shaarli\Security\SessionManager; | 84 | use \Shaarli\Security\SessionManager; |
85 | use \Shaarli\Thumbnailer; | 85 | use \Shaarli\Thumbnailer; |
86 | use Shaarli\Updater\Updater; | 86 | use \Shaarli\Updater\Updater; |
87 | 87 | ||
88 | // Ensure the PHP version is supported | 88 | // Ensure the PHP version is supported |
89 | try { | 89 | try { |
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 |
2 | use Shaarli\Config\ConfigManager; | 2 | namespace Shaarli; |
3 | |||
4 | /** | ||
5 | * ApplicationUtils' tests | ||
6 | */ | ||
7 | 3 | ||
8 | require_once 'application/ApplicationUtils.php'; | 4 | use Shaarli\Config\ConfigManager; |
9 | |||
10 | /** | ||
11 | * Fake ApplicationUtils class to avoid HTTP requests | ||
12 | */ | ||
13 | class 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 | ||
6 | require_once 'tests/utils/FakeApplicationUtils.php'; | ||
26 | 7 | ||
27 | /** | 8 | /** |
28 | * Unitary tests for Shaarli utilities | 9 | * Unitary tests for Shaarli utilities |
29 | */ | 10 | */ |
30 | class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | 11 | class 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/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 | |||
3 | namespace Shaarli; | ||
4 | |||
5 | /** | ||
6 | * Fake ApplicationUtils class to avoid HTTP requests | ||
7 | */ | ||
8 | class 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 | } | ||