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 $redirectorUrl = '<script>alert("redirector");</script>';
291 $this->conf
->set('general.title', $title);
292 $this->conf
->set('general.header_link', $headerLink);
293 $this->conf
->set('redirector.url', $redirectorUrl);
294 $updater = new Updater(array(), array(), $this->conf
, true);
295 $done = $updater->updateMethodEscapeUnescapedConfig();
296 $this->assertTrue($done);
297 $this->conf
->reload();
298 $this->assertEquals(escape($title), $this->conf
->get('general.title'));
299 $this->assertEquals(escape($headerLink), $this->conf
->get('general.header_link'));
300 $this->assertEquals(escape($redirectorUrl), $this->conf
->get('redirector.url'));
301 unlink($sandbox . '.json.php');
305 * Test updateMethodApiSettings(): create default settings for the API (enabled + secret).
307 public function testUpdateApiSettings()
309 $confFile = 'sandbox/config';
310 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
311 $conf = new ConfigManager($confFile);
312 $updater = new Updater(array(), array(), $conf, true);
314 $this->assertFalse($conf->exists('api.enabled'));
315 $this->assertFalse($conf->exists('api.secret'));
316 $updater->updateMethodApiSettings();
318 $this->assertTrue($conf->get('api.enabled'));
319 $this->assertTrue($conf->exists('api.secret'));
320 unlink($confFile .'.json.php');
324 * Test updateMethodApiSettings(): already set, do nothing.
326 public function testUpdateApiSettingsNothingToDo()
328 $confFile = 'sandbox/config';
329 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
330 $conf = new ConfigManager($confFile);
331 $conf->set('api.enabled', false);
332 $conf->set('api.secret', '');
333 $updater = new Updater(array(), array(), $conf, true);
334 $updater->updateMethodApiSettings();
335 $this->assertFalse($conf->get('api.enabled'));
336 $this->assertEmpty($conf->get('api.secret'));
337 unlink($confFile .'.json.php');
341 * Test updateMethodDatastoreIds().
343 public function testDatastoreIds()
346 '20121206_182539' => array(
347 'linkdate' => '20121206_182539',
348 'title' => 'Geek and Poke',
349 'url' => 'http://geek-and-poke.com/',
350 'description' => 'desc',
351 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
352 'updated' => '20121206_190301',
355 '20121206_172539' => array(
356 'linkdate' => '20121206_172539',
357 'title' => 'UserFriendly - Samba',
358 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
360 'tags' => 'samba cartoon web',
363 '20121206_142300' => array(
364 'linkdate' => '20121206_142300',
365 'title' => 'UserFriendly - Web Designer',
366 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
367 'description' => 'Naming conventions... #private',
368 'tags' => 'samba cartoon web',
372 $refDB = new \
ReferenceLinkDB();
373 $refDB->setLinks($links);
374 $refDB->write(self
::$testDatastore);
375 $linkDB = new LinkDB(self
::$testDatastore, true, false);
377 $checksum = hash_file('sha1', self
::$testDatastore);
379 $this->conf
->set('resource.data_dir', 'sandbox');
380 $this->conf
->set('resource.datastore', self
::$testDatastore);
382 $updater = new Updater(array(), $linkDB, $this->conf
, true);
383 $this->assertTrue($updater->updateMethodDatastoreIds());
385 $linkDB = new LinkDB(self
::$testDatastore, true, false);
387 $backup = glob($this->conf
->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
388 $backup = $backup[0];
390 $this->assertFileExists($backup);
391 $this->assertEquals($checksum, hash_file('sha1', $backup));
394 $this->assertEquals(3, count($linkDB));
395 $this->assertTrue(isset($linkDB[0]));
396 $this->assertFalse(isset($linkDB[0]['linkdate']));
397 $this->assertEquals(0, $linkDB[0]['id']);
398 $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
399 $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
400 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
401 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
402 $this->assertTrue($linkDB[0]['private']);
404 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_142300'),
405 $linkDB[0]['created']
408 $this->assertTrue(isset($linkDB[1]));
409 $this->assertFalse(isset($linkDB[1]['linkdate']));
410 $this->assertEquals(1, $linkDB[1]['id']);
411 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
413 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_172539'),
414 $linkDB[1]['created']
417 $this->assertTrue(isset($linkDB[2]));
418 $this->assertFalse(isset($linkDB[2]['linkdate']));
419 $this->assertEquals(2, $linkDB[2]['id']);
420 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
422 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_182539'),
423 $linkDB[2]['created']
426 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_190301'),
427 $linkDB[2]['updated']
432 * Test updateMethodDatastoreIds() with the update already applied: nothing to do.
434 public function testDatastoreIdsNothingToDo()
436 $refDB = new \
ReferenceLinkDB();
437 $refDB->write(self
::$testDatastore);
438 $linkDB = new LinkDB(self
::$testDatastore, true, false);
440 $this->conf
->set('resource.data_dir', 'sandbox');
441 $this->conf
->set('resource.datastore', self
::$testDatastore);
443 $checksum = hash_file('sha1', self
::$testDatastore);
444 $updater = new Updater(array(), $linkDB, $this->conf
, true);
445 $this->assertTrue($updater->updateMethodDatastoreIds());
446 $this->assertEquals($checksum, hash_file('sha1', self
::$testDatastore));
450 * Test defaultTheme update with default settings: nothing to do.
452 public function testDefaultThemeWithDefaultSettings()
454 $sandbox = 'sandbox/config';
455 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
456 $this->conf
= new ConfigManager($sandbox);
457 $updater = new Updater([], [], $this->conf
, true);
458 $this->assertTrue($updater->updateMethodDefaultTheme());
460 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
461 $this->assertEquals('default', $this->conf
->get('resource.theme'));
462 $this->conf
= new ConfigManager($sandbox);
463 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
464 $this->assertEquals('default', $this->conf
->get('resource.theme'));
465 unlink($sandbox . '.json.php');
469 * Test defaultTheme update with a custom theme in a subfolder
471 public function testDefaultThemeWithCustomTheme()
473 $theme = 'iamanartist';
474 $sandbox = 'sandbox/config';
475 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
476 $this->conf
= new ConfigManager($sandbox);
477 mkdir('sandbox/'. $theme);
478 touch('sandbox/'. $theme .'/linklist.html');
479 $this->conf
->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
480 $updater = new Updater([], [], $this->conf
, true);
481 $this->assertTrue($updater->updateMethodDefaultTheme());
483 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
484 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
485 $this->conf
= new ConfigManager($sandbox);
486 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
487 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
488 unlink($sandbox . '.json.php');
489 unlink('sandbox/'. $theme .'/linklist.html');
490 rmdir('sandbox/'. $theme);
494 * Test updateMethodEscapeMarkdown with markdown plugin enabled
495 * => setting markdown_escape set to false.
497 public function testEscapeMarkdownSettingToFalse()
499 $sandboxConf = 'sandbox/config';
500 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
501 $this->conf
= new ConfigManager($sandboxConf);
503 $this->conf
->set('general.enabled_plugins', ['markdown']);
504 $updater = new Updater([], [], $this->conf
, true);
505 $this->assertTrue($updater->updateMethodEscapeMarkdown());
506 $this->assertFalse($this->conf
->get('security.markdown_escape'));
509 $this->conf
= new ConfigManager($sandboxConf);
510 $this->assertFalse($this->conf
->get('security.markdown_escape'));
515 * Test updateMethodEscapeMarkdown with markdown plugin disabled
516 * => setting markdown_escape set to true.
518 public function testEscapeMarkdownSettingToTrue()
520 $sandboxConf = 'sandbox/config';
521 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
522 $this->conf
= new ConfigManager($sandboxConf);
524 $this->conf
->set('general.enabled_plugins', []);
525 $updater = new Updater([], [], $this->conf
, true);
526 $this->assertTrue($updater->updateMethodEscapeMarkdown());
527 $this->assertTrue($this->conf
->get('security.markdown_escape'));
530 $this->conf
= new ConfigManager($sandboxConf);
531 $this->assertTrue($this->conf
->get('security.markdown_escape'));
535 * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled)
537 public function testEscapeMarkdownSettingNothingToDoEnabled()
539 $sandboxConf = 'sandbox/config';
540 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
541 $this->conf
= new ConfigManager($sandboxConf);
542 $this->conf
->set('security.markdown_escape', true);
543 $updater = new Updater([], [], $this->conf
, true);
544 $this->assertTrue($updater->updateMethodEscapeMarkdown());
545 $this->assertTrue($this->conf
->get('security.markdown_escape'));
549 * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled)
551 public function testEscapeMarkdownSettingNothingToDoDisabled()
553 $this->conf
->set('security.markdown_escape', false);
554 $updater = new Updater([], [], $this->conf
, true);
555 $this->assertTrue($updater->updateMethodEscapeMarkdown());
556 $this->assertFalse($this->conf
->get('security.markdown_escape'));
560 * Test updateMethodPiwikUrl with valid data
562 public function testUpdatePiwikUrlValid()
564 $sandboxConf = 'sandbox/config';
565 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
566 $this->conf
= new ConfigManager($sandboxConf);
567 $url = 'mypiwik.tld';
568 $this->conf
->set('plugins.PIWIK_URL', $url);
569 $updater = new Updater([], [], $this->conf
, true);
570 $this->assertTrue($updater->updateMethodPiwikUrl());
571 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
574 $this->conf
= new ConfigManager($sandboxConf);
575 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
579 * Test updateMethodPiwikUrl without setting
581 public function testUpdatePiwikUrlEmpty()
583 $updater = new Updater([], [], $this->conf
, true);
584 $this->assertTrue($updater->updateMethodPiwikUrl());
585 $this->assertEmpty($this->conf
->get('plugins.PIWIK_URL'));
589 * Test updateMethodPiwikUrl: valid URL, nothing to do
591 public function testUpdatePiwikUrlNothingToDo()
593 $url = 'https://mypiwik.tld';
594 $this->conf
->set('plugins.PIWIK_URL', $url);
595 $updater = new Updater([], [], $this->conf
, true);
596 $this->assertTrue($updater->updateMethodPiwikUrl());
597 $this->assertEquals($url, $this->conf
->get('plugins.PIWIK_URL'));
601 * Test updateMethodAtomDefault with show_atom set to false
604 public function testUpdateMethodAtomDefault()
606 $sandboxConf = 'sandbox/config';
607 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
608 $this->conf
= new ConfigManager($sandboxConf);
609 $this->conf
->set('feed.show_atom', false);
610 $updater = new Updater([], [], $this->conf
, true);
611 $this->assertTrue($updater->updateMethodAtomDefault());
612 $this->assertTrue($this->conf
->get('feed.show_atom'));
614 $this->conf
= new ConfigManager($sandboxConf);
615 $this->assertTrue($this->conf
->get('feed.show_atom'));
618 * Test updateMethodAtomDefault with show_atom not set.
621 public function testUpdateMethodAtomDefaultNoExist()
623 $sandboxConf = 'sandbox/config';
624 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
625 $this->conf
= new ConfigManager($sandboxConf);
626 $updater = new Updater([], [], $this->conf
, true);
627 $this->assertTrue($updater->updateMethodAtomDefault());
628 $this->assertTrue($this->conf
->get('feed.show_atom'));
631 * Test updateMethodAtomDefault with show_atom set to true.
634 public function testUpdateMethodAtomDefaultAlreadyTrue()
636 $sandboxConf = 'sandbox/config';
637 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
638 $this->conf
= new ConfigManager($sandboxConf);
639 $this->conf
->set('feed.show_atom', true);
640 $updater = new Updater([], [], $this->conf
, true);
641 $this->assertTrue($updater->updateMethodAtomDefault());
642 $this->assertTrue($this->conf
->get('feed.show_atom'));
646 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
648 public function testUpdateMethodDownloadSizeAndTimeoutConf()
650 $sandboxConf = 'sandbox/config';
651 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
652 $this->conf
= new ConfigManager($sandboxConf);
653 $updater = new Updater([], [], $this->conf
, true);
654 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
655 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
656 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
658 $this->conf
= new ConfigManager($sandboxConf);
659 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
660 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
664 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
666 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
668 $sandboxConf = 'sandbox/config';
669 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
670 $this->conf
= new ConfigManager($sandboxConf);
671 $this->conf
->set('general.download_max_size', 38);
672 $this->conf
->set('general.download_timeout', 70);
673 $updater = new Updater([], [], $this->conf
, true);
674 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
675 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
676 $this->assertEquals(70, $this->conf
->get('general.download_timeout'));
680 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
682 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
684 $sandboxConf = 'sandbox/config';
685 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
686 $this->conf
= new ConfigManager($sandboxConf);
687 $this->conf
->set('general.download_max_size', 38);
688 $updater = new Updater([], [], $this->conf
, true);
689 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
690 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
691 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
695 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
697 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
699 $sandboxConf = 'sandbox/config';
700 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
701 $this->conf
= new ConfigManager($sandboxConf);
702 $this->conf
->set('general.download_timeout', 3);
703 $updater = new Updater([], [], $this->conf
, true);
704 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
705 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
706 $this->assertEquals(3, $this->conf
->get('general.download_timeout'));
711 * Test updateMethodWebThumbnailer with thumbnails enabled.
713 public function testUpdateMethodWebThumbnailerEnabled()
715 $this->conf
->remove('thumbnails');
716 $this->conf
->set('thumbnail.enable_thumbnails', true);
717 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
718 $this->assertTrue($updater->updateMethodWebThumbnailer());
719 $this->assertFalse($this->conf
->exists('thumbnail'));
720 $this->assertEquals(\Shaarli\Thumbnailer
::MODE_ALL
, $this->conf
->get('thumbnails.mode'));
721 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
722 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
723 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
727 * Test updateMethodWebThumbnailer with thumbnails disabled.
729 public function testUpdateMethodWebThumbnailerDisabled()
731 $this->conf
->remove('thumbnails');
732 $this->conf
->set('thumbnail.enable_thumbnails', false);
733 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
734 $this->assertTrue($updater->updateMethodWebThumbnailer());
735 $this->assertFalse($this->conf
->exists('thumbnail'));
736 $this->assertEquals(Thumbnailer
::MODE_NONE
, $this->conf
->get('thumbnails.mode'));
737 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
738 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
739 $this->assertTrue(empty($_SESSION['warnings']));
743 * Test updateMethodWebThumbnailer with thumbnails disabled.
745 public function testUpdateMethodWebThumbnailerNothingToDo()
747 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
748 $this->assertTrue($updater->updateMethodWebThumbnailer());
749 $this->assertFalse($this->conf
->exists('thumbnail'));
750 $this->assertEquals(Thumbnailer
::MODE_COMMON
, $this->conf
->get('thumbnails.mode'));
751 $this->assertEquals(90, $this->conf
->get('thumbnails.width'));
752 $this->assertEquals(53, $this->conf
->get('thumbnails.height'));
753 $this->assertTrue(empty($_SESSION['warnings']));
757 * Test updateMethodSetSticky().
759 public function testUpdateStickyValid()
767 'created' => new DateTime(),
770 1 => ['id' => 1] +
$blank,
771 2 => ['id' => 2] +
$blank,
773 $refDB = new \
ReferenceLinkDB();
774 $refDB->setLinks($links);
775 $refDB->write(self
::$testDatastore);
776 $linkDB = new LinkDB(self
::$testDatastore, true, false);
778 $updater = new Updater(array(), $linkDB, $this->conf
, true);
779 $this->assertTrue($updater->updateMethodSetSticky());
781 $linkDB = new LinkDB(self
::$testDatastore, true, false);
782 foreach ($linkDB as $link) {
783 $this->assertFalse($link['sticky']);
788 * Test updateMethodSetSticky().
790 public function testUpdateStickyNothingToDo()
798 'created' => new DateTime(),
801 1 => ['id' => 1, 'sticky' => true] +
$blank,
802 2 => ['id' => 2] +
$blank,
804 $refDB = new \
ReferenceLinkDB();
805 $refDB->setLinks($links);
806 $refDB->write(self
::$testDatastore);
807 $linkDB = new LinkDB(self
::$testDatastore, true, false);
809 $updater = new Updater(array(), $linkDB, $this->conf
, true);
810 $this->assertTrue($updater->updateMethodSetSticky());
812 $linkDB = new LinkDB(self
::$testDatastore, true, false);
813 $this->assertTrue($linkDB[1]['sticky']);