]>
Commit | Line | Data |
---|---|---|
510377d2 | 1 | <?php |
3c66e564 V |
2 | use Shaarli\Config\ConfigJson; |
3 | use Shaarli\Config\ConfigManager; | |
4 | use Shaarli\Config\ConfigPhp; | |
510377d2 A |
5 | |
6 | require_once 'tests/Updater/DummyUpdater.php'; | |
a0df0651 | 7 | require_once 'inc/rain.tpl.class.php'; |
510377d2 A |
8 | |
9 | /** | |
10 | * Class UpdaterTest. | |
11 | * Runs unit tests against the Updater class. | |
12 | */ | |
13 | class UpdaterTest extends PHPUnit_Framework_TestCase | |
14 | { | |
21979ff1 A |
15 | /** |
16 | * @var string Path to test datastore. | |
17 | */ | |
18 | protected static $testDatastore = 'sandbox/datastore.php'; | |
19 | ||
684e662a | 20 | /** |
b74b96bf | 21 | * @var string Config file path (without extension). |
684e662a | 22 | */ |
da10377b | 23 | protected static $configFile = 'tests/utils/config/configJson'; |
684e662a A |
24 | |
25 | /** | |
26 | * @var ConfigManager | |
27 | */ | |
28 | protected $conf; | |
29 | ||
510377d2 A |
30 | /** |
31 | * Executed before each test. | |
32 | */ | |
33 | public function setUp() | |
34 | { | |
278d9ee2 | 35 | $this->conf = new ConfigManager(self::$configFile); |
510377d2 A |
36 | } |
37 | ||
38 | /** | |
39 | * Test read_updates_file with an empty/missing file. | |
40 | */ | |
41 | public function testReadEmptyUpdatesFile() | |
42 | { | |
43 | $this->assertEquals(array(), read_updates_file('')); | |
894a3c4b | 44 | $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; |
510377d2 A |
45 | touch($updatesFile); |
46 | $this->assertEquals(array(), read_updates_file($updatesFile)); | |
da10377b | 47 | unlink($updatesFile); |
510377d2 A |
48 | } |
49 | ||
50 | /** | |
51 | * Test read/write updates file. | |
52 | */ | |
53 | public function testReadWriteUpdatesFile() | |
54 | { | |
894a3c4b | 55 | $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; |
510377d2 A |
56 | $updatesMethods = array('m1', 'm2', 'm3'); |
57 | ||
58 | write_updates_file($updatesFile, $updatesMethods); | |
59 | $readMethods = read_updates_file($updatesFile); | |
60 | $this->assertEquals($readMethods, $updatesMethods); | |
61 | ||
62 | // Update | |
63 | $updatesMethods[] = 'm4'; | |
64 | write_updates_file($updatesFile, $updatesMethods); | |
65 | $readMethods = read_updates_file($updatesFile); | |
66 | $this->assertEquals($readMethods, $updatesMethods); | |
da10377b | 67 | unlink($updatesFile); |
510377d2 A |
68 | } |
69 | ||
70 | /** | |
71 | * Test errors in write_updates_file(): empty updates file. | |
72 | * | |
73 | * @expectedException Exception | |
74 | * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/ | |
75 | */ | |
76 | public function testWriteEmptyUpdatesFile() | |
77 | { | |
78 | write_updates_file('', array('test')); | |
79 | } | |
80 | ||
81 | /** | |
82 | * Test errors in write_updates_file(): not writable updates file. | |
83 | * | |
84 | * @expectedException Exception | |
85 | * @expectedExceptionMessageRegExp /Unable to write(.*)/ | |
86 | */ | |
87 | public function testWriteUpdatesFileNotWritable() | |
88 | { | |
894a3c4b | 89 | $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; |
510377d2 A |
90 | touch($updatesFile); |
91 | chmod($updatesFile, 0444); | |
da10377b A |
92 | try { |
93 | @write_updates_file($updatesFile, array('test')); | |
94 | } catch (Exception $e) { | |
95 | unlink($updatesFile); | |
96 | throw $e; | |
97 | } | |
510377d2 A |
98 | } |
99 | ||
100 | /** | |
101 | * Test the update() method, with no update to run. | |
102 | * 1. Everything already run. | |
103 | * 2. User is logged out. | |
104 | */ | |
105 | public function testNoUpdates() | |
106 | { | |
107 | $updates = array( | |
108 | 'updateMethodDummy1', | |
109 | 'updateMethodDummy2', | |
110 | 'updateMethodDummy3', | |
111 | 'updateMethodException', | |
112 | ); | |
278d9ee2 | 113 | $updater = new DummyUpdater($updates, array(), $this->conf, true); |
510377d2 A |
114 | $this->assertEquals(array(), $updater->update()); |
115 | ||
278d9ee2 | 116 | $updater = new DummyUpdater(array(), array(), $this->conf, false); |
510377d2 A |
117 | $this->assertEquals(array(), $updater->update()); |
118 | } | |
119 | ||
120 | /** | |
121 | * Test the update() method, with all updates to run (except the failing one). | |
122 | */ | |
123 | public function testUpdatesFirstTime() | |
124 | { | |
125 | $updates = array('updateMethodException',); | |
126 | $expectedUpdates = array( | |
127 | 'updateMethodDummy1', | |
128 | 'updateMethodDummy2', | |
129 | 'updateMethodDummy3', | |
130 | ); | |
278d9ee2 | 131 | $updater = new DummyUpdater($updates, array(), $this->conf, true); |
510377d2 A |
132 | $this->assertEquals($expectedUpdates, $updater->update()); |
133 | } | |
134 | ||
135 | /** | |
136 | * Test the update() method, only one update to run. | |
137 | */ | |
138 | public function testOneUpdate() | |
139 | { | |
140 | $updates = array( | |
141 | 'updateMethodDummy1', | |
142 | 'updateMethodDummy3', | |
143 | 'updateMethodException', | |
144 | ); | |
145 | $expectedUpdate = array('updateMethodDummy2'); | |
146 | ||
278d9ee2 | 147 | $updater = new DummyUpdater($updates, array(), $this->conf, true); |
510377d2 A |
148 | $this->assertEquals($expectedUpdate, $updater->update()); |
149 | } | |
150 | ||
151 | /** | |
152 | * Test Update failed. | |
153 | * | |
154 | * @expectedException UpdaterException | |
155 | */ | |
156 | public function testUpdateFailed() | |
157 | { | |
158 | $updates = array( | |
159 | 'updateMethodDummy1', | |
160 | 'updateMethodDummy2', | |
161 | 'updateMethodDummy3', | |
162 | ); | |
163 | ||
278d9ee2 | 164 | $updater = new DummyUpdater($updates, array(), $this->conf, true); |
510377d2 A |
165 | $updater->update(); |
166 | } | |
167 | ||
168 | /** | |
169 | * Test update mergeDeprecatedConfig: | |
170 | * 1. init a config file. | |
171 | * 2. init a options.php file with update value. | |
172 | * 3. merge. | |
173 | * 4. check updated value in config file. | |
174 | */ | |
175 | public function testUpdateMergeDeprecatedConfig() | |
176 | { | |
278d9ee2 A |
177 | $this->conf->setConfigFile('tests/utils/config/configPhp'); |
178 | $this->conf->reset(); | |
684e662a A |
179 | |
180 | $optionsFile = 'tests/Updater/options.php'; | |
da10377b A |
181 | $options = '<?php |
182 | $GLOBALS[\'privateLinkByDefault\'] = true;'; | |
183 | file_put_contents($optionsFile, $options); | |
510377d2 | 184 | |
da10377b | 185 | // tmp config file. |
278d9ee2 | 186 | $this->conf->setConfigFile('tests/Updater/config'); |
510377d2 A |
187 | |
188 | // merge configs | |
278d9ee2 | 189 | $updater = new Updater(array(), array(), $this->conf, true); |
b74b96bf | 190 | // This writes a new config file in tests/Updater/config.php |
510377d2 A |
191 | $updater->updateMethodMergeDeprecatedConfigFile(); |
192 | ||
193 | // make sure updated field is changed | |
684e662a | 194 | $this->conf->reload(); |
894a3c4b | 195 | $this->assertTrue($this->conf->get('privacy.default_private_links')); |
684e662a | 196 | $this->assertFalse(is_file($optionsFile)); |
b74b96bf | 197 | // Delete the generated file. |
278d9ee2 | 198 | unlink($this->conf->getConfigFileExt()); |
510377d2 A |
199 | } |
200 | ||
201 | /** | |
202 | * Test mergeDeprecatedConfig in without options file. | |
203 | */ | |
204 | public function testMergeDeprecatedConfigNoFile() | |
205 | { | |
278d9ee2 | 206 | $updater = new Updater(array(), array(), $this->conf, true); |
510377d2 A |
207 | $updater->updateMethodMergeDeprecatedConfigFile(); |
208 | ||
da10377b | 209 | $this->assertEquals('root', $this->conf->get('credentials.login')); |
510377d2 | 210 | } |
21979ff1 | 211 | |
684e662a A |
212 | /** |
213 | * Test renameDashTags update method. | |
214 | */ | |
21979ff1 A |
215 | public function testRenameDashTags() |
216 | { | |
217 | $refDB = new ReferenceLinkDB(); | |
218 | $refDB->write(self::$testDatastore); | |
219 | $linkDB = new LinkDB(self::$testDatastore, true, false); | |
c3dfd899 | 220 | |
528a6f8a | 221 | $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
278d9ee2 | 222 | $updater = new Updater(array(), $linkDB, $this->conf, true); |
21979ff1 | 223 | $updater->updateMethodRenameDashTags(); |
528a6f8a | 224 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
21979ff1 | 225 | } |
b74b96bf A |
226 | |
227 | /** | |
228 | * Convert old PHP config file to JSON config. | |
229 | */ | |
230 | public function testConfigToJson() | |
231 | { | |
232 | $configFile = 'tests/utils/config/configPhp'; | |
278d9ee2 A |
233 | $this->conf->setConfigFile($configFile); |
234 | $this->conf->reset(); | |
b74b96bf A |
235 | |
236 | // The ConfigIO is initialized with ConfigPhp. | |
278d9ee2 | 237 | $this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp); |
b74b96bf | 238 | |
278d9ee2 | 239 | $updater = new Updater(array(), array(), $this->conf, false); |
b74b96bf A |
240 | $done = $updater->updateMethodConfigToJson(); |
241 | $this->assertTrue($done); | |
242 | ||
243 | // The ConfigIO has been updated to ConfigJson. | |
278d9ee2 A |
244 | $this->assertTrue($this->conf->getConfigIO() instanceof ConfigJson); |
245 | $this->assertTrue(file_exists($this->conf->getConfigFileExt())); | |
b74b96bf A |
246 | |
247 | // Check JSON config data. | |
278d9ee2 A |
248 | $this->conf->reload(); |
249 | $this->assertEquals('root', $this->conf->get('credentials.login')); | |
894a3c4b A |
250 | $this->assertEquals('lala', $this->conf->get('redirector.url')); |
251 | $this->assertEquals('data/datastore.php', $this->conf->get('resource.datastore')); | |
278d9ee2 | 252 | $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION')); |
b74b96bf A |
253 | |
254 | rename($configFile . '.save.php', $configFile . '.php'); | |
278d9ee2 | 255 | unlink($this->conf->getConfigFileExt()); |
b74b96bf A |
256 | } |
257 | ||
258 | /** | |
259 | * Launch config conversion update with an existing JSON file => nothing to do. | |
260 | */ | |
261 | public function testConfigToJsonNothingToDo() | |
262 | { | |
278d9ee2 A |
263 | $filetime = filemtime($this->conf->getConfigFileExt()); |
264 | $updater = new Updater(array(), array(), $this->conf, false); | |
b74b96bf A |
265 | $done = $updater->updateMethodConfigToJson(); |
266 | $this->assertTrue($done); | |
278d9ee2 | 267 | $expected = filemtime($this->conf->getConfigFileExt()); |
b74b96bf A |
268 | $this->assertEquals($expected, $filetime); |
269 | } | |
b9f8b837 A |
270 | |
271 | /** | |
272 | * Test escapeUnescapedConfig with valid data. | |
273 | */ | |
274 | public function testEscapeConfig() | |
275 | { | |
276 | $sandbox = 'sandbox/config'; | |
cbfdcff2 | 277 | copy(self::$configFile . '.json.php', $sandbox . '.json.php'); |
b9f8b837 A |
278 | $this->conf = new ConfigManager($sandbox); |
279 | $title = '<script>alert("title");</script>'; | |
280 | $headerLink = '<script>alert("header_link");</script>'; | |
281 | $redirectorUrl = '<script>alert("redirector");</script>'; | |
282 | $this->conf->set('general.title', $title); | |
283 | $this->conf->set('general.header_link', $headerLink); | |
284 | $this->conf->set('redirector.url', $redirectorUrl); | |
285 | $updater = new Updater(array(), array(), $this->conf, true); | |
286 | $done = $updater->updateMethodEscapeUnescapedConfig(); | |
287 | $this->assertTrue($done); | |
288 | $this->conf->reload(); | |
289 | $this->assertEquals(escape($title), $this->conf->get('general.title')); | |
290 | $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link')); | |
291 | $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url')); | |
cbfdcff2 A |
292 | unlink($sandbox . '.json.php'); |
293 | } | |
294 | ||
295 | /** | |
296 | * Test updateMethodApiSettings(): create default settings for the API (enabled + secret). | |
297 | */ | |
298 | public function testUpdateApiSettings() | |
299 | { | |
300 | $confFile = 'sandbox/config'; | |
301 | copy(self::$configFile .'.json.php', $confFile .'.json.php'); | |
302 | $conf = new ConfigManager($confFile); | |
303 | $updater = new Updater(array(), array(), $conf, true); | |
304 | ||
305 | $this->assertFalse($conf->exists('api.enabled')); | |
306 | $this->assertFalse($conf->exists('api.secret')); | |
307 | $updater->updateMethodApiSettings(); | |
308 | $conf->reload(); | |
309 | $this->assertTrue($conf->get('api.enabled')); | |
310 | $this->assertTrue($conf->exists('api.secret')); | |
311 | unlink($confFile .'.json.php'); | |
312 | } | |
313 | ||
314 | /** | |
315 | * Test updateMethodApiSettings(): already set, do nothing. | |
316 | */ | |
317 | public function testUpdateApiSettingsNothingToDo() | |
318 | { | |
319 | $confFile = 'sandbox/config'; | |
320 | copy(self::$configFile .'.json.php', $confFile .'.json.php'); | |
321 | $conf = new ConfigManager($confFile); | |
322 | $conf->set('api.enabled', false); | |
323 | $conf->set('api.secret', ''); | |
324 | $updater = new Updater(array(), array(), $conf, true); | |
325 | $updater->updateMethodApiSettings(); | |
326 | $this->assertFalse($conf->get('api.enabled')); | |
327 | $this->assertEmpty($conf->get('api.secret')); | |
328 | unlink($confFile .'.json.php'); | |
b9f8b837 | 329 | } |
c3dfd899 A |
330 | |
331 | /** | |
332 | * Test updateMethodDatastoreIds(). | |
333 | */ | |
334 | public function testDatastoreIds() | |
335 | { | |
336 | $links = array( | |
337 | '20121206_182539' => array( | |
338 | 'linkdate' => '20121206_182539', | |
339 | 'title' => 'Geek and Poke', | |
340 | 'url' => 'http://geek-and-poke.com/', | |
341 | 'description' => 'desc', | |
342 | 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ', | |
343 | 'updated' => '20121206_190301', | |
344 | 'private' => false, | |
345 | ), | |
346 | '20121206_172539' => array( | |
347 | 'linkdate' => '20121206_172539', | |
348 | 'title' => 'UserFriendly - Samba', | |
349 | 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306', | |
350 | 'description' => '', | |
351 | 'tags' => 'samba cartoon web', | |
352 | 'private' => false, | |
353 | ), | |
354 | '20121206_142300' => array( | |
355 | 'linkdate' => '20121206_142300', | |
356 | 'title' => 'UserFriendly - Web Designer', | |
357 | 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206', | |
358 | 'description' => 'Naming conventions... #private', | |
359 | 'tags' => 'samba cartoon web', | |
360 | 'private' => true, | |
361 | ), | |
362 | ); | |
363 | $refDB = new ReferenceLinkDB(); | |
364 | $refDB->setLinks($links); | |
365 | $refDB->write(self::$testDatastore); | |
366 | $linkDB = new LinkDB(self::$testDatastore, true, false); | |
367 | ||
368 | $checksum = hash_file('sha1', self::$testDatastore); | |
369 | ||
370 | $this->conf->set('resource.data_dir', 'sandbox'); | |
371 | $this->conf->set('resource.datastore', self::$testDatastore); | |
372 | ||
373 | $updater = new Updater(array(), $linkDB, $this->conf, true); | |
374 | $this->assertTrue($updater->updateMethodDatastoreIds()); | |
375 | ||
376 | $linkDB = new LinkDB(self::$testDatastore, true, false); | |
377 | ||
378 | $backup = glob($this->conf->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php'); | |
379 | $backup = $backup[0]; | |
380 | ||
381 | $this->assertFileExists($backup); | |
382 | $this->assertEquals($checksum, hash_file('sha1', $backup)); | |
383 | unlink($backup); | |
384 | ||
385 | $this->assertEquals(3, count($linkDB)); | |
386 | $this->assertTrue(isset($linkDB[0])); | |
387 | $this->assertFalse(isset($linkDB[0]['linkdate'])); | |
388 | $this->assertEquals(0, $linkDB[0]['id']); | |
389 | $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']); | |
390 | $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']); | |
391 | $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']); | |
392 | $this->assertEquals('samba cartoon web', $linkDB[0]['tags']); | |
393 | $this->assertTrue($linkDB[0]['private']); | |
d592daea | 394 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), $linkDB[0]['created']); |
c3dfd899 A |
395 | |
396 | $this->assertTrue(isset($linkDB[1])); | |
397 | $this->assertFalse(isset($linkDB[1]['linkdate'])); | |
398 | $this->assertEquals(1, $linkDB[1]['id']); | |
399 | $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']); | |
d592daea | 400 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), $linkDB[1]['created']); |
c3dfd899 A |
401 | |
402 | $this->assertTrue(isset($linkDB[2])); | |
403 | $this->assertFalse(isset($linkDB[2]['linkdate'])); | |
404 | $this->assertEquals(2, $linkDB[2]['id']); | |
405 | $this->assertEquals('Geek and Poke', $linkDB[2]['title']); | |
d592daea A |
406 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), $linkDB[2]['created']); |
407 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), $linkDB[2]['updated']); | |
c3dfd899 A |
408 | } |
409 | ||
410 | /** | |
411 | * Test updateMethodDatastoreIds() with the update already applied: nothing to do. | |
412 | */ | |
413 | public function testDatastoreIdsNothingToDo() | |
414 | { | |
415 | $refDB = new ReferenceLinkDB(); | |
416 | $refDB->write(self::$testDatastore); | |
417 | $linkDB = new LinkDB(self::$testDatastore, true, false); | |
418 | ||
419 | $this->conf->set('resource.data_dir', 'sandbox'); | |
420 | $this->conf->set('resource.datastore', self::$testDatastore); | |
421 | ||
422 | $checksum = hash_file('sha1', self::$testDatastore); | |
423 | $updater = new Updater(array(), $linkDB, $this->conf, true); | |
424 | $this->assertTrue($updater->updateMethodDatastoreIds()); | |
425 | $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore)); | |
426 | } | |
04a0e8ea A |
427 | |
428 | /** | |
429 | * Test defaultTheme update with default settings: nothing to do. | |
430 | */ | |
431 | public function testDefaultThemeWithDefaultSettings() | |
432 | { | |
433 | $sandbox = 'sandbox/config'; | |
434 | copy(self::$configFile . '.json.php', $sandbox . '.json.php'); | |
435 | $this->conf = new ConfigManager($sandbox); | |
436 | $updater = new Updater([], [], $this->conf, true); | |
437 | $this->assertTrue($updater->updateMethodDefaultTheme()); | |
438 | ||
439 | $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); | |
440 | $this->assertEquals('default', $this->conf->get('resource.theme')); | |
441 | $this->conf = new ConfigManager($sandbox); | |
442 | $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); | |
443 | $this->assertEquals('default', $this->conf->get('resource.theme')); | |
444 | unlink($sandbox . '.json.php'); | |
445 | } | |
446 | ||
447 | /** | |
448 | * Test defaultTheme update with a custom theme in a subfolder | |
449 | */ | |
450 | public function testDefaultThemeWithCustomTheme() | |
451 | { | |
452 | $theme = 'iamanartist'; | |
453 | $sandbox = 'sandbox/config'; | |
454 | copy(self::$configFile . '.json.php', $sandbox . '.json.php'); | |
455 | $this->conf = new ConfigManager($sandbox); | |
456 | mkdir('sandbox/'. $theme); | |
457 | touch('sandbox/'. $theme .'/linklist.html'); | |
458 | $this->conf->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/'); | |
459 | $updater = new Updater([], [], $this->conf, true); | |
460 | $this->assertTrue($updater->updateMethodDefaultTheme()); | |
461 | ||
462 | $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); | |
463 | $this->assertEquals($theme, $this->conf->get('resource.theme')); | |
464 | $this->conf = new ConfigManager($sandbox); | |
465 | $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); | |
466 | $this->assertEquals($theme, $this->conf->get('resource.theme')); | |
467 | unlink($sandbox . '.json.php'); | |
468 | unlink('sandbox/'. $theme .'/linklist.html'); | |
469 | rmdir('sandbox/'. $theme); | |
470 | } | |
7dcbfde5 | 471 | |
e0376101 A |
472 | /** |
473 | * Test updateMethodEscapeMarkdown with markdown plugin enabled | |
474 | * => setting markdown_escape set to false. | |
475 | */ | |
476 | public function testEscapeMarkdownSettingToFalse() | |
477 | { | |
478 | $sandboxConf = 'sandbox/config'; | |
479 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
480 | $this->conf = new ConfigManager($sandboxConf); | |
481 | ||
482 | $this->conf->set('general.enabled_plugins', ['markdown']); | |
483 | $updater = new Updater([], [], $this->conf, true); | |
484 | $this->assertTrue($updater->updateMethodEscapeMarkdown()); | |
485 | $this->assertFalse($this->conf->get('security.markdown_escape')); | |
486 | ||
487 | // reload from file | |
488 | $this->conf = new ConfigManager($sandboxConf); | |
489 | $this->assertFalse($this->conf->get('security.markdown_escape')); | |
490 | } | |
491 | ||
492 | ||
493 | /** | |
494 | * Test updateMethodEscapeMarkdown with markdown plugin disabled | |
495 | * => setting markdown_escape set to true. | |
496 | */ | |
497 | public function testEscapeMarkdownSettingToTrue() | |
498 | { | |
499 | $sandboxConf = 'sandbox/config'; | |
500 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
501 | $this->conf = new ConfigManager($sandboxConf); | |
502 | ||
503 | $this->conf->set('general.enabled_plugins', []); | |
504 | $updater = new Updater([], [], $this->conf, true); | |
505 | $this->assertTrue($updater->updateMethodEscapeMarkdown()); | |
506 | $this->assertTrue($this->conf->get('security.markdown_escape')); | |
507 | ||
508 | // reload from file | |
509 | $this->conf = new ConfigManager($sandboxConf); | |
510 | $this->assertTrue($this->conf->get('security.markdown_escape')); | |
511 | } | |
512 | ||
513 | /** | |
514 | * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled) | |
515 | */ | |
516 | public function testEscapeMarkdownSettingNothingToDoEnabled() | |
517 | { | |
518 | $sandboxConf = 'sandbox/config'; | |
519 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
520 | $this->conf = new ConfigManager($sandboxConf); | |
521 | $this->conf->set('security.markdown_escape', true); | |
522 | $updater = new Updater([], [], $this->conf, true); | |
523 | $this->assertTrue($updater->updateMethodEscapeMarkdown()); | |
524 | $this->assertTrue($this->conf->get('security.markdown_escape')); | |
525 | } | |
526 | ||
527 | /** | |
528 | * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled) | |
529 | */ | |
530 | public function testEscapeMarkdownSettingNothingToDoDisabled() | |
531 | { | |
532 | $this->conf->set('security.markdown_escape', false); | |
533 | $updater = new Updater([], [], $this->conf, true); | |
534 | $this->assertTrue($updater->updateMethodEscapeMarkdown()); | |
535 | $this->assertFalse($this->conf->get('security.markdown_escape')); | |
536 | } | |
fe83d45c A |
537 | |
538 | /** | |
539 | * Test updateMethodPiwikUrl with valid data | |
540 | */ | |
541 | public function testUpdatePiwikUrlValid() | |
542 | { | |
543 | $sandboxConf = 'sandbox/config'; | |
544 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
545 | $this->conf = new ConfigManager($sandboxConf); | |
546 | $url = 'mypiwik.tld'; | |
547 | $this->conf->set('plugins.PIWIK_URL', $url); | |
548 | $updater = new Updater([], [], $this->conf, true); | |
549 | $this->assertTrue($updater->updateMethodPiwikUrl()); | |
550 | $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL')); | |
551 | ||
552 | // reload from file | |
553 | $this->conf = new ConfigManager($sandboxConf); | |
554 | $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL')); | |
555 | } | |
556 | ||
557 | /** | |
558 | * Test updateMethodPiwikUrl without setting | |
559 | */ | |
560 | public function testUpdatePiwikUrlEmpty() | |
561 | { | |
562 | $updater = new Updater([], [], $this->conf, true); | |
563 | $this->assertTrue($updater->updateMethodPiwikUrl()); | |
564 | $this->assertEmpty($this->conf->get('plugins.PIWIK_URL')); | |
565 | } | |
566 | ||
567 | /** | |
568 | * Test updateMethodPiwikUrl: valid URL, nothing to do | |
569 | */ | |
570 | public function testUpdatePiwikUrlNothingToDo() | |
571 | { | |
572 | $url = 'https://mypiwik.tld'; | |
573 | $this->conf->set('plugins.PIWIK_URL', $url); | |
574 | $updater = new Updater([], [], $this->conf, true); | |
575 | $this->assertTrue($updater->updateMethodPiwikUrl()); | |
576 | $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); | |
577 | } | |
2ea89aba A |
578 | |
579 | /** | |
580 | * Test updateMethodAtomDefault with show_atom set to false | |
581 | * => update to true. | |
582 | */ | |
583 | public function testUpdateMethodAtomDefault() | |
584 | { | |
585 | $sandboxConf = 'sandbox/config'; | |
586 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
587 | $this->conf = new ConfigManager($sandboxConf); | |
588 | $this->conf->set('feed.show_atom', false); | |
589 | $updater = new Updater([], [], $this->conf, true); | |
590 | $this->assertTrue($updater->updateMethodAtomDefault()); | |
591 | $this->assertTrue($this->conf->get('feed.show_atom')); | |
592 | // reload from file | |
593 | $this->conf = new ConfigManager($sandboxConf); | |
594 | $this->assertTrue($this->conf->get('feed.show_atom')); | |
595 | } | |
596 | /** | |
597 | * Test updateMethodAtomDefault with show_atom not set. | |
598 | * => nothing to do | |
599 | */ | |
600 | public function testUpdateMethodAtomDefaultNoExist() | |
601 | { | |
602 | $sandboxConf = 'sandbox/config'; | |
603 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
604 | $this->conf = new ConfigManager($sandboxConf); | |
605 | $updater = new Updater([], [], $this->conf, true); | |
606 | $this->assertTrue($updater->updateMethodAtomDefault()); | |
607 | $this->assertTrue($this->conf->get('feed.show_atom')); | |
608 | } | |
609 | /** | |
610 | * Test updateMethodAtomDefault with show_atom set to true. | |
611 | * => nothing to do | |
612 | */ | |
613 | public function testUpdateMethodAtomDefaultAlreadyTrue() | |
614 | { | |
615 | $sandboxConf = 'sandbox/config'; | |
616 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | |
617 | $this->conf = new ConfigManager($sandboxConf); | |
618 | $this->conf->set('feed.show_atom', true); | |
619 | $updater = new Updater([], [], $this->conf, true); | |
620 | $this->assertTrue($updater->updateMethodAtomDefault()); | |
621 | $this->assertTrue($this->conf->get('feed.show_atom')); | |
622 | } | |
510377d2 | 623 | } |