2 namespace Shaarli\Updater
;
6 use Shaarli\Bookmark\LinkDB
;
7 use Shaarli\Config\ConfigJson
;
8 use Shaarli\Config\ConfigManager
;
9 use Shaarli\Config\ConfigPhp
;
10 use Shaarli\Thumbnailer
;
12 require_once 'application/updater/UpdaterUtils.php';
13 require_once 'tests/updater/DummyUpdater.php';
14 require_once 'tests/utils/ReferenceLinkDB.php';
15 require_once 'inc/rain.tpl.class.php';
19 * Runs unit tests against the updater class.
21 class UpdaterTest
extends \PHPUnit\Framework\TestCase
24 * @var string Path to test datastore.
26 protected static $testDatastore = 'sandbox/datastore.php';
29 * @var string Config file path (without extension).
31 protected static $configFile = 'sandbox/config';
39 * Executed before each test.
41 public function setUp()
43 copy('tests/utils/config/configJson.json.php', self
::$configFile .'.json.php');
44 $this->conf
= new ConfigManager(self
::$configFile);
48 * Test read_updates_file with an empty/missing file.
50 public function testReadEmptyUpdatesFile()
52 $this->assertEquals(array(), read_updates_file(''));
53 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
55 $this->assertEquals(array(), read_updates_file($updatesFile));
60 * Test read/write updates file.
62 public function testReadWriteUpdatesFile()
64 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
65 $updatesMethods = array('m1', 'm2', 'm3');
67 write_updates_file($updatesFile, $updatesMethods);
68 $readMethods = read_updates_file($updatesFile);
69 $this->assertEquals($readMethods, $updatesMethods);
72 $updatesMethods[] = 'm4';
73 write_updates_file($updatesFile, $updatesMethods);
74 $readMethods = read_updates_file($updatesFile);
75 $this->assertEquals($readMethods, $updatesMethods);
80 * Test errors in write_updates_file(): empty updates file.
82 * @expectedException Exception
83 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
85 public function testWriteEmptyUpdatesFile()
87 write_updates_file('', array('test'));
91 * Test errors in write_updates_file(): not writable updates file.
93 * @expectedException Exception
94 * @expectedExceptionMessageRegExp /Unable to write(.*)/
96 public function testWriteUpdatesFileNotWritable()
98 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
100 chmod($updatesFile, 0444);
102 @write_updates_file($updatesFile, array('test'));
103 } catch (Exception
$e) {
104 unlink($updatesFile);
110 * Test the update() method, with no update to run.
111 * 1. Everything already run.
112 * 2. User is logged out.
114 public function testNoUpdates()
117 'updateMethodDummy1',
118 'updateMethodDummy2',
119 'updateMethodDummy3',
120 'updateMethodException',
122 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
123 $this->assertEquals(array(), $updater->update());
125 $updater = new DummyUpdater(array(), array(), $this->conf
, false);
126 $this->assertEquals(array(), $updater->update());
130 * Test the update() method, with all updates to run (except the failing one).
132 public function testUpdatesFirstTime()
134 $updates = array('updateMethodException',);
135 $expectedUpdates = array(
136 'updateMethodDummy1',
137 'updateMethodDummy2',
138 'updateMethodDummy3',
140 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
141 $this->assertEquals($expectedUpdates, $updater->update());
145 * Test the update() method, only one update to run.
147 public function testOneUpdate()
150 'updateMethodDummy1',
151 'updateMethodDummy3',
152 'updateMethodException',
154 $expectedUpdate = array('updateMethodDummy2');
156 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
157 $this->assertEquals($expectedUpdate, $updater->update());
161 * Test Update failed.
163 * @expectedException \Exception
165 public function testUpdateFailed()
168 'updateMethodDummy1',
169 'updateMethodDummy2',
170 'updateMethodDummy3',
173 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
178 * Test update mergeDeprecatedConfig:
179 * 1. init a config file.
180 * 2. init a options.php file with update value.
182 * 4. check updated value in config file.
184 public function testUpdateMergeDeprecatedConfig()
186 $this->conf
->setConfigFile('tests/utils/config/configPhp');
187 $this->conf
->reset();
189 $optionsFile = 'tests/updater/options.php';
191 $GLOBALS[\'privateLinkByDefault\'] = true;';
192 file_put_contents($optionsFile, $options);
195 $this->conf
->setConfigFile('tests/updater/config');
198 $updater = new Updater(array(), array(), $this->conf
, true);
199 // This writes a new config file in tests/updater/config.php
200 $updater->updateMethodMergeDeprecatedConfigFile();
202 // make sure updated field is changed
203 $this->conf
->reload();
204 $this->assertTrue($this->conf
->get('privacy.default_private_links'));
205 $this->assertFalse(is_file($optionsFile));
206 // Delete the generated file.
207 unlink($this->conf
->getConfigFileExt());
211 * Test mergeDeprecatedConfig in without options file.
213 public function testMergeDeprecatedConfigNoFile()
215 $updater = new Updater(array(), array(), $this->conf
, true);
216 $updater->updateMethodMergeDeprecatedConfigFile();
218 $this->assertEquals('root', $this->conf
->get('credentials.login'));
222 * Test renameDashTags update method.
224 public function testRenameDashTags()
226 $refDB = new \
ReferenceLinkDB();
227 $refDB->write(self
::$testDatastore);
228 $linkDB = new LinkDB(self
::$testDatastore, true, false);
230 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
231 $updater = new Updater(array(), $linkDB, $this->conf
, true);
232 $updater->updateMethodRenameDashTags();
233 $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
237 * Convert old PHP config file to JSON config.
239 public function testConfigToJson()
241 $configFile = 'tests/utils/config/configPhp';
242 $this->conf
->setConfigFile($configFile);
243 $this->conf
->reset();
245 // The ConfigIO is initialized with ConfigPhp.
246 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigPhp
);
248 $updater = new Updater(array(), array(), $this->conf
, false);
249 $done = $updater->updateMethodConfigToJson();
250 $this->assertTrue($done);
252 // The ConfigIO has been updated to ConfigJson.
253 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigJson
);
254 $this->assertTrue(file_exists($this->conf
->getConfigFileExt()));
256 // Check JSON config data.
257 $this->conf
->reload();
258 $this->assertEquals('root', $this->conf
->get('credentials.login'));
259 $this->assertEquals('lala', $this->conf
->get('redirector.url'));
260 $this->assertEquals('data/datastore.php', $this->conf
->get('resource.datastore'));
261 $this->assertEquals('1', $this->conf
->get('plugins.WALLABAG_VERSION'));
263 rename($configFile . '.save.php', $configFile . '.php');
264 unlink($this->conf
->getConfigFileExt());
268 * Launch config conversion update with an existing JSON file => nothing to do.
270 public function testConfigToJsonNothingToDo()
272 $filetime = filemtime($this->conf
->getConfigFileExt());
273 $updater = new Updater(array(), array(), $this->conf
, false);
274 $done = $updater->updateMethodConfigToJson();
275 $this->assertTrue($done);
276 $expected = filemtime($this->conf
->getConfigFileExt());
277 $this->assertEquals($expected, $filetime);
281 * Test escapeUnescapedConfig with valid data.
283 public function testEscapeConfig()
285 $sandbox = 'sandbox/config';
286 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
287 $this->conf
= new ConfigManager($sandbox);
288 $title = '<script>alert("title");</script>';
289 $headerLink = '<script>alert("header_link");</script>';
290 $this->conf
->set('general.title', $title);
291 $this->conf
->set('general.header_link', $headerLink);
292 $updater = new Updater(array(), array(), $this->conf
, true);
293 $done = $updater->updateMethodEscapeUnescapedConfig();
294 $this->assertTrue($done);
295 $this->conf
->reload();
296 $this->assertEquals(escape($title), $this->conf
->get('general.title'));
297 $this->assertEquals(escape($headerLink), $this->conf
->get('general.header_link'));
298 unlink($sandbox . '.json.php');
302 * Test updateMethodApiSettings(): create default settings for the API (enabled + secret).
304 public function testUpdateApiSettings()
306 $confFile = 'sandbox/config';
307 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
308 $conf = new ConfigManager($confFile);
309 $updater = new Updater(array(), array(), $conf, true);
311 $this->assertFalse($conf->exists('api.enabled'));
312 $this->assertFalse($conf->exists('api.secret'));
313 $updater->updateMethodApiSettings();
315 $this->assertTrue($conf->get('api.enabled'));
316 $this->assertTrue($conf->exists('api.secret'));
317 unlink($confFile .'.json.php');
321 * Test updateMethodApiSettings(): already set, do nothing.
323 public function testUpdateApiSettingsNothingToDo()
325 $confFile = 'sandbox/config';
326 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
327 $conf = new ConfigManager($confFile);
328 $conf->set('api.enabled', false);
329 $conf->set('api.secret', '');
330 $updater = new Updater(array(), array(), $conf, true);
331 $updater->updateMethodApiSettings();
332 $this->assertFalse($conf->get('api.enabled'));
333 $this->assertEmpty($conf->get('api.secret'));
334 unlink($confFile .'.json.php');
338 * Test updateMethodDatastoreIds().
340 public function testDatastoreIds()
343 '20121206_182539' => array(
344 'linkdate' => '20121206_182539',
345 'title' => 'Geek and Poke',
346 'url' => 'http://geek-and-poke.com/',
347 'description' => 'desc',
348 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
349 'updated' => '20121206_190301',
352 '20121206_172539' => array(
353 'linkdate' => '20121206_172539',
354 'title' => 'UserFriendly - Samba',
355 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
357 'tags' => 'samba cartoon web',
360 '20121206_142300' => array(
361 'linkdate' => '20121206_142300',
362 'title' => 'UserFriendly - Web Designer',
363 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
364 'description' => 'Naming conventions... #private',
365 'tags' => 'samba cartoon web',
369 $refDB = new \
ReferenceLinkDB();
370 $refDB->setLinks($links);
371 $refDB->write(self
::$testDatastore);
372 $linkDB = new LinkDB(self
::$testDatastore, true, false);
374 $checksum = hash_file('sha1', self
::$testDatastore);
376 $this->conf
->set('resource.data_dir', 'sandbox');
377 $this->conf
->set('resource.datastore', self
::$testDatastore);
379 $updater = new Updater(array(), $linkDB, $this->conf
, true);
380 $this->assertTrue($updater->updateMethodDatastoreIds());
382 $linkDB = new LinkDB(self
::$testDatastore, true, false);
384 $backup = glob($this->conf
->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
385 $backup = $backup[0];
387 $this->assertFileExists($backup);
388 $this->assertEquals($checksum, hash_file('sha1', $backup));
391 $this->assertEquals(3, count($linkDB));
392 $this->assertTrue(isset($linkDB[0]));
393 $this->assertFalse(isset($linkDB[0]['linkdate']));
394 $this->assertEquals(0, $linkDB[0]['id']);
395 $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
396 $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
397 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
398 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
399 $this->assertTrue($linkDB[0]['private']);
401 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_142300'),
402 $linkDB[0]['created']
405 $this->assertTrue(isset($linkDB[1]));
406 $this->assertFalse(isset($linkDB[1]['linkdate']));
407 $this->assertEquals(1, $linkDB[1]['id']);
408 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
410 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_172539'),
411 $linkDB[1]['created']
414 $this->assertTrue(isset($linkDB[2]));
415 $this->assertFalse(isset($linkDB[2]['linkdate']));
416 $this->assertEquals(2, $linkDB[2]['id']);
417 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
419 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_182539'),
420 $linkDB[2]['created']
423 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_190301'),
424 $linkDB[2]['updated']
429 * Test updateMethodDatastoreIds() with the update already applied: nothing to do.
431 public function testDatastoreIdsNothingToDo()
433 $refDB = new \
ReferenceLinkDB();
434 $refDB->write(self
::$testDatastore);
435 $linkDB = new LinkDB(self
::$testDatastore, true, false);
437 $this->conf
->set('resource.data_dir', 'sandbox');
438 $this->conf
->set('resource.datastore', self
::$testDatastore);
440 $checksum = hash_file('sha1', self
::$testDatastore);
441 $updater = new Updater(array(), $linkDB, $this->conf
, true);
442 $this->assertTrue($updater->updateMethodDatastoreIds());
443 $this->assertEquals($checksum, hash_file('sha1', self
::$testDatastore));
447 * Test defaultTheme update with default settings: nothing to do.
449 public function testDefaultThemeWithDefaultSettings()
451 $sandbox = 'sandbox/config';
452 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
453 $this->conf
= new ConfigManager($sandbox);
454 $updater = new Updater([], [], $this->conf
, true);
455 $this->assertTrue($updater->updateMethodDefaultTheme());
457 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
458 $this->assertEquals('default', $this->conf
->get('resource.theme'));
459 $this->conf
= new ConfigManager($sandbox);
460 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
461 $this->assertEquals('default', $this->conf
->get('resource.theme'));
462 unlink($sandbox . '.json.php');
466 * Test defaultTheme update with a custom theme in a subfolder
468 public function testDefaultThemeWithCustomTheme()
470 $theme = 'iamanartist';
471 $sandbox = 'sandbox/config';
472 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
473 $this->conf
= new ConfigManager($sandbox);
474 mkdir('sandbox/'. $theme);
475 touch('sandbox/'. $theme .'/linklist.html');
476 $this->conf
->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
477 $updater = new Updater([], [], $this->conf
, true);
478 $this->assertTrue($updater->updateMethodDefaultTheme());
480 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
481 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
482 $this->conf
= new ConfigManager($sandbox);
483 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
484 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
485 unlink($sandbox . '.json.php');
486 unlink('sandbox/'. $theme .'/linklist.html');
487 rmdir('sandbox/'. $theme);
491 * Test updateMethodEscapeMarkdown with markdown plugin enabled
492 * => setting markdown_escape set to false.
494 public function testEscapeMarkdownSettingToFalse()
496 $sandboxConf = 'sandbox/config';
497 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
498 $this->conf
= new ConfigManager($sandboxConf);
500 $this->conf
->set('general.enabled_plugins', ['markdown']);
501 $updater = new Updater([], [], $this->conf
, true);
502 $this->assertTrue($updater->updateMethodEscapeMarkdown());
503 $this->assertFalse($this->conf
->get('security.markdown_escape'));
506 $this->conf
= new ConfigManager($sandboxConf);
507 $this->assertFalse($this->conf
->get('security.markdown_escape'));
512 * Test updateMethodEscapeMarkdown with markdown plugin disabled
513 * => setting markdown_escape set to true.
515 public function testEscapeMarkdownSettingToTrue()
517 $sandboxConf = 'sandbox/config';
518 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
519 $this->conf
= new ConfigManager($sandboxConf);
521 $this->conf
->set('general.enabled_plugins', []);
522 $updater = new Updater([], [], $this->conf
, true);
523 $this->assertTrue($updater->updateMethodEscapeMarkdown());
524 $this->assertTrue($this->conf
->get('security.markdown_escape'));
527 $this->conf
= new ConfigManager($sandboxConf);
528 $this->assertTrue($this->conf
->get('security.markdown_escape'));
532 * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled)
534 public function testEscapeMarkdownSettingNothingToDoEnabled()
536 $sandboxConf = 'sandbox/config';
537 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
538 $this->conf
= new ConfigManager($sandboxConf);
539 $this->conf
->set('security.markdown_escape', true);
540 $updater = new Updater([], [], $this->conf
, true);
541 $this->assertTrue($updater->updateMethodEscapeMarkdown());
542 $this->assertTrue($this->conf
->get('security.markdown_escape'));
546 * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled)
548 public function testEscapeMarkdownSettingNothingToDoDisabled()
550 $this->conf
->set('security.markdown_escape', false);
551 $updater = new Updater([], [], $this->conf
, true);
552 $this->assertTrue($updater->updateMethodEscapeMarkdown());
553 $this->assertFalse($this->conf
->get('security.markdown_escape'));
557 * Test updateMethodPiwikUrl with valid data
559 public function testUpdatePiwikUrlValid()
561 $sandboxConf = 'sandbox/config';
562 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
563 $this->conf
= new ConfigManager($sandboxConf);
564 $url = 'mypiwik.tld';
565 $this->conf
->set('plugins.PIWIK_URL', $url);
566 $updater = new Updater([], [], $this->conf
, true);
567 $this->assertTrue($updater->updateMethodPiwikUrl());
568 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
571 $this->conf
= new ConfigManager($sandboxConf);
572 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
576 * Test updateMethodPiwikUrl without setting
578 public function testUpdatePiwikUrlEmpty()
580 $updater = new Updater([], [], $this->conf
, true);
581 $this->assertTrue($updater->updateMethodPiwikUrl());
582 $this->assertEmpty($this->conf
->get('plugins.PIWIK_URL'));
586 * Test updateMethodPiwikUrl: valid URL, nothing to do
588 public function testUpdatePiwikUrlNothingToDo()
590 $url = 'https://mypiwik.tld';
591 $this->conf
->set('plugins.PIWIK_URL', $url);
592 $updater = new Updater([], [], $this->conf
, true);
593 $this->assertTrue($updater->updateMethodPiwikUrl());
594 $this->assertEquals($url, $this->conf
->get('plugins.PIWIK_URL'));
598 * Test updateMethodAtomDefault with show_atom set to false
601 public function testUpdateMethodAtomDefault()
603 $sandboxConf = 'sandbox/config';
604 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
605 $this->conf
= new ConfigManager($sandboxConf);
606 $this->conf
->set('feed.show_atom', false);
607 $updater = new Updater([], [], $this->conf
, true);
608 $this->assertTrue($updater->updateMethodAtomDefault());
609 $this->assertTrue($this->conf
->get('feed.show_atom'));
611 $this->conf
= new ConfigManager($sandboxConf);
612 $this->assertTrue($this->conf
->get('feed.show_atom'));
615 * Test updateMethodAtomDefault with show_atom not set.
618 public function testUpdateMethodAtomDefaultNoExist()
620 $sandboxConf = 'sandbox/config';
621 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
622 $this->conf
= new ConfigManager($sandboxConf);
623 $updater = new Updater([], [], $this->conf
, true);
624 $this->assertTrue($updater->updateMethodAtomDefault());
625 $this->assertTrue($this->conf
->get('feed.show_atom'));
628 * Test updateMethodAtomDefault with show_atom set to true.
631 public function testUpdateMethodAtomDefaultAlreadyTrue()
633 $sandboxConf = 'sandbox/config';
634 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
635 $this->conf
= new ConfigManager($sandboxConf);
636 $this->conf
->set('feed.show_atom', true);
637 $updater = new Updater([], [], $this->conf
, true);
638 $this->assertTrue($updater->updateMethodAtomDefault());
639 $this->assertTrue($this->conf
->get('feed.show_atom'));
643 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
645 public function testUpdateMethodDownloadSizeAndTimeoutConf()
647 $sandboxConf = 'sandbox/config';
648 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
649 $this->conf
= new ConfigManager($sandboxConf);
650 $updater = new Updater([], [], $this->conf
, true);
651 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
652 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
653 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
655 $this->conf
= new ConfigManager($sandboxConf);
656 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
657 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
661 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
663 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
665 $sandboxConf = 'sandbox/config';
666 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
667 $this->conf
= new ConfigManager($sandboxConf);
668 $this->conf
->set('general.download_max_size', 38);
669 $this->conf
->set('general.download_timeout', 70);
670 $updater = new Updater([], [], $this->conf
, true);
671 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
672 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
673 $this->assertEquals(70, $this->conf
->get('general.download_timeout'));
677 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
679 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
681 $sandboxConf = 'sandbox/config';
682 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
683 $this->conf
= new ConfigManager($sandboxConf);
684 $this->conf
->set('general.download_max_size', 38);
685 $updater = new Updater([], [], $this->conf
, true);
686 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
687 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
688 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
692 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
694 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
696 $sandboxConf = 'sandbox/config';
697 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
698 $this->conf
= new ConfigManager($sandboxConf);
699 $this->conf
->set('general.download_timeout', 3);
700 $updater = new Updater([], [], $this->conf
, true);
701 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
702 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
703 $this->assertEquals(3, $this->conf
->get('general.download_timeout'));
707 * Test updateMethodWebThumbnailer with thumbnails enabled.
709 public function testUpdateMethodWebThumbnailerEnabled()
711 $this->conf
->remove('thumbnails');
712 $this->conf
->set('thumbnail.enable_thumbnails', true);
713 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
714 $this->assertTrue($updater->updateMethodWebThumbnailer());
715 $this->assertFalse($this->conf
->exists('thumbnail'));
716 $this->assertEquals(\Shaarli\Thumbnailer
::MODE_ALL
, $this->conf
->get('thumbnails.mode'));
717 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
718 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
719 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
723 * Test updateMethodWebThumbnailer with thumbnails disabled.
725 public function testUpdateMethodWebThumbnailerDisabled()
727 $this->conf
->remove('thumbnails');
728 $this->conf
->set('thumbnail.enable_thumbnails', false);
729 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
730 $this->assertTrue($updater->updateMethodWebThumbnailer());
731 $this->assertFalse($this->conf
->exists('thumbnail'));
732 $this->assertEquals(Thumbnailer
::MODE_NONE
, $this->conf
->get('thumbnails.mode'));
733 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
734 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
735 $this->assertTrue(empty($_SESSION['warnings']));
739 * Test updateMethodWebThumbnailer with thumbnails disabled.
741 public function testUpdateMethodWebThumbnailerNothingToDo()
743 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
744 $this->assertTrue($updater->updateMethodWebThumbnailer());
745 $this->assertFalse($this->conf
->exists('thumbnail'));
746 $this->assertEquals(Thumbnailer
::MODE_COMMON
, $this->conf
->get('thumbnails.mode'));
747 $this->assertEquals(90, $this->conf
->get('thumbnails.width'));
748 $this->assertEquals(53, $this->conf
->get('thumbnails.height'));
749 $this->assertTrue(empty($_SESSION['warnings']));
753 * Test updateMethodSetSticky().
755 public function testUpdateStickyValid()
763 'created' => new DateTime(),
766 1 => ['id' => 1] +
$blank,
767 2 => ['id' => 2] +
$blank,
769 $refDB = new \
ReferenceLinkDB();
770 $refDB->setLinks($links);
771 $refDB->write(self
::$testDatastore);
772 $linkDB = new LinkDB(self
::$testDatastore, true, false);
774 $updater = new Updater(array(), $linkDB, $this->conf
, true);
775 $this->assertTrue($updater->updateMethodSetSticky());
777 $linkDB = new LinkDB(self
::$testDatastore, true, false);
778 foreach ($linkDB as $link) {
779 $this->assertFalse($link['sticky']);
784 * Test updateMethodSetSticky().
786 public function testUpdateStickyNothingToDo()
794 'created' => new DateTime(),
797 1 => ['id' => 1, 'sticky' => true] +
$blank,
798 2 => ['id' => 2] +
$blank,
800 $refDB = new \
ReferenceLinkDB();
801 $refDB->setLinks($links);
802 $refDB->write(self
::$testDatastore);
803 $linkDB = new LinkDB(self
::$testDatastore, true, false);
805 $updater = new Updater(array(), $linkDB, $this->conf
, true);
806 $this->assertTrue($updater->updateMethodSetSticky());
808 $linkDB = new LinkDB(self
::$testDatastore, true, false);
809 $this->assertTrue($linkDB[1]['sticky']);
813 * Test updateMethodRemoveRedirector().
815 public function testUpdateRemoveRedirector()
817 $sandboxConf = 'sandbox/config';
818 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
819 $this->conf
= new ConfigManager($sandboxConf);
820 $updater = new Updater([], null, $this->conf
, true);
821 $this->assertTrue($updater->updateMethodRemoveRedirector());
822 $this->assertFalse($this->conf
->exists('redirector'));
823 $this->conf
= new ConfigManager($sandboxConf);
824 $this->assertFalse($this->conf
->exists('redirector'));