3 use Shaarli\Bookmark\LinkDB
;
4 use Shaarli\Config\ConfigJson
;
5 use Shaarli\Config\ConfigManager
;
6 use Shaarli\Config\ConfigPhp
;
7 use Shaarli\Thumbnailer
;
9 require_once 'tests/Updater/DummyUpdater.php';
10 require_once 'inc/rain.tpl.class.php';
14 * Runs unit tests against the Updater class.
16 class UpdaterTest
extends PHPUnit_Framework_TestCase
19 * @var string Path to test datastore.
21 protected static $testDatastore = 'sandbox/datastore.php';
24 * @var string Config file path (without extension).
26 protected static $configFile = 'sandbox/config';
34 * Executed before each test.
36 public function setUp()
38 copy('tests/utils/config/configJson.json.php', self
::$configFile .'.json.php');
39 $this->conf
= new ConfigManager(self
::$configFile);
43 * Test read_updates_file with an empty/missing file.
45 public function testReadEmptyUpdatesFile()
47 $this->assertEquals(array(), read_updates_file(''));
48 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
50 $this->assertEquals(array(), read_updates_file($updatesFile));
55 * Test read/write updates file.
57 public function testReadWriteUpdatesFile()
59 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
60 $updatesMethods = array('m1', 'm2', 'm3');
62 write_updates_file($updatesFile, $updatesMethods);
63 $readMethods = read_updates_file($updatesFile);
64 $this->assertEquals($readMethods, $updatesMethods);
67 $updatesMethods[] = 'm4';
68 write_updates_file($updatesFile, $updatesMethods);
69 $readMethods = read_updates_file($updatesFile);
70 $this->assertEquals($readMethods, $updatesMethods);
75 * Test errors in write_updates_file(): empty updates file.
77 * @expectedException Exception
78 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
80 public function testWriteEmptyUpdatesFile()
82 write_updates_file('', array('test'));
86 * Test errors in write_updates_file(): not writable updates file.
88 * @expectedException Exception
89 * @expectedExceptionMessageRegExp /Unable to write(.*)/
91 public function testWriteUpdatesFileNotWritable()
93 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
95 chmod($updatesFile, 0444);
97 @write_updates_file($updatesFile, array('test'));
98 } catch (Exception
$e) {
105 * Test the update() method, with no update to run.
106 * 1. Everything already run.
107 * 2. User is logged out.
109 public function testNoUpdates()
112 'updateMethodDummy1',
113 'updateMethodDummy2',
114 'updateMethodDummy3',
115 'updateMethodException',
117 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
118 $this->assertEquals(array(), $updater->update());
120 $updater = new DummyUpdater(array(), array(), $this->conf
, false);
121 $this->assertEquals(array(), $updater->update());
125 * Test the update() method, with all updates to run (except the failing one).
127 public function testUpdatesFirstTime()
129 $updates = array('updateMethodException',);
130 $expectedUpdates = array(
131 'updateMethodDummy1',
132 'updateMethodDummy2',
133 'updateMethodDummy3',
135 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
136 $this->assertEquals($expectedUpdates, $updater->update());
140 * Test the update() method, only one update to run.
142 public function testOneUpdate()
145 'updateMethodDummy1',
146 'updateMethodDummy3',
147 'updateMethodException',
149 $expectedUpdate = array('updateMethodDummy2');
151 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
152 $this->assertEquals($expectedUpdate, $updater->update());
156 * Test Update failed.
158 * @expectedException UpdaterException
160 public function testUpdateFailed()
163 'updateMethodDummy1',
164 'updateMethodDummy2',
165 'updateMethodDummy3',
168 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
173 * Test update mergeDeprecatedConfig:
174 * 1. init a config file.
175 * 2. init a options.php file with update value.
177 * 4. check updated value in config file.
179 public function testUpdateMergeDeprecatedConfig()
181 $this->conf
->setConfigFile('tests/utils/config/configPhp');
182 $this->conf
->reset();
184 $optionsFile = 'tests/Updater/options.php';
186 $GLOBALS[\'privateLinkByDefault\'] = true;';
187 file_put_contents($optionsFile, $options);
190 $this->conf
->setConfigFile('tests/Updater/config');
193 $updater = new Updater(array(), array(), $this->conf
, true);
194 // This writes a new config file in tests/Updater/config.php
195 $updater->updateMethodMergeDeprecatedConfigFile();
197 // make sure updated field is changed
198 $this->conf
->reload();
199 $this->assertTrue($this->conf
->get('privacy.default_private_links'));
200 $this->assertFalse(is_file($optionsFile));
201 // Delete the generated file.
202 unlink($this->conf
->getConfigFileExt());
206 * Test mergeDeprecatedConfig in without options file.
208 public function testMergeDeprecatedConfigNoFile()
210 $updater = new Updater(array(), array(), $this->conf
, true);
211 $updater->updateMethodMergeDeprecatedConfigFile();
213 $this->assertEquals('root', $this->conf
->get('credentials.login'));
217 * Test renameDashTags update method.
219 public function testRenameDashTags()
221 $refDB = new ReferenceLinkDB();
222 $refDB->write(self
::$testDatastore);
223 $linkDB = new LinkDB(self
::$testDatastore, true, false);
225 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
226 $updater = new Updater(array(), $linkDB, $this->conf
, true);
227 $updater->updateMethodRenameDashTags();
228 $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
232 * Convert old PHP config file to JSON config.
234 public function testConfigToJson()
236 $configFile = 'tests/utils/config/configPhp';
237 $this->conf
->setConfigFile($configFile);
238 $this->conf
->reset();
240 // The ConfigIO is initialized with ConfigPhp.
241 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigPhp
);
243 $updater = new Updater(array(), array(), $this->conf
, false);
244 $done = $updater->updateMethodConfigToJson();
245 $this->assertTrue($done);
247 // The ConfigIO has been updated to ConfigJson.
248 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigJson
);
249 $this->assertTrue(file_exists($this->conf
->getConfigFileExt()));
251 // Check JSON config data.
252 $this->conf
->reload();
253 $this->assertEquals('root', $this->conf
->get('credentials.login'));
254 $this->assertEquals('lala', $this->conf
->get('redirector.url'));
255 $this->assertEquals('data/datastore.php', $this->conf
->get('resource.datastore'));
256 $this->assertEquals('1', $this->conf
->get('plugins.WALLABAG_VERSION'));
258 rename($configFile . '.save.php', $configFile . '.php');
259 unlink($this->conf
->getConfigFileExt());
263 * Launch config conversion update with an existing JSON file => nothing to do.
265 public function testConfigToJsonNothingToDo()
267 $filetime = filemtime($this->conf
->getConfigFileExt());
268 $updater = new Updater(array(), array(), $this->conf
, false);
269 $done = $updater->updateMethodConfigToJson();
270 $this->assertTrue($done);
271 $expected = filemtime($this->conf
->getConfigFileExt());
272 $this->assertEquals($expected, $filetime);
276 * Test escapeUnescapedConfig with valid data.
278 public function testEscapeConfig()
280 $sandbox = 'sandbox/config';
281 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
282 $this->conf
= new ConfigManager($sandbox);
283 $title = '<script>alert("title");</script>';
284 $headerLink = '<script>alert("header_link");</script>';
285 $redirectorUrl = '<script>alert("redirector");</script>';
286 $this->conf
->set('general.title', $title);
287 $this->conf
->set('general.header_link', $headerLink);
288 $this->conf
->set('redirector.url', $redirectorUrl);
289 $updater = new Updater(array(), array(), $this->conf
, true);
290 $done = $updater->updateMethodEscapeUnescapedConfig();
291 $this->assertTrue($done);
292 $this->conf
->reload();
293 $this->assertEquals(escape($title), $this->conf
->get('general.title'));
294 $this->assertEquals(escape($headerLink), $this->conf
->get('general.header_link'));
295 $this->assertEquals(escape($redirectorUrl), $this->conf
->get('redirector.url'));
296 unlink($sandbox . '.json.php');
300 * Test updateMethodApiSettings(): create default settings for the API (enabled + secret).
302 public function testUpdateApiSettings()
304 $confFile = 'sandbox/config';
305 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
306 $conf = new ConfigManager($confFile);
307 $updater = new Updater(array(), array(), $conf, true);
309 $this->assertFalse($conf->exists('api.enabled'));
310 $this->assertFalse($conf->exists('api.secret'));
311 $updater->updateMethodApiSettings();
313 $this->assertTrue($conf->get('api.enabled'));
314 $this->assertTrue($conf->exists('api.secret'));
315 unlink($confFile .'.json.php');
319 * Test updateMethodApiSettings(): already set, do nothing.
321 public function testUpdateApiSettingsNothingToDo()
323 $confFile = 'sandbox/config';
324 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
325 $conf = new ConfigManager($confFile);
326 $conf->set('api.enabled', false);
327 $conf->set('api.secret', '');
328 $updater = new Updater(array(), array(), $conf, true);
329 $updater->updateMethodApiSettings();
330 $this->assertFalse($conf->get('api.enabled'));
331 $this->assertEmpty($conf->get('api.secret'));
332 unlink($confFile .'.json.php');
336 * Test updateMethodDatastoreIds().
338 public function testDatastoreIds()
341 '20121206_182539' => array(
342 'linkdate' => '20121206_182539',
343 'title' => 'Geek and Poke',
344 'url' => 'http://geek-and-poke.com/',
345 'description' => 'desc',
346 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
347 'updated' => '20121206_190301',
350 '20121206_172539' => array(
351 'linkdate' => '20121206_172539',
352 'title' => 'UserFriendly - Samba',
353 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
355 'tags' => 'samba cartoon web',
358 '20121206_142300' => array(
359 'linkdate' => '20121206_142300',
360 'title' => 'UserFriendly - Web Designer',
361 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
362 'description' => 'Naming conventions... #private',
363 'tags' => 'samba cartoon web',
367 $refDB = new ReferenceLinkDB();
368 $refDB->setLinks($links);
369 $refDB->write(self
::$testDatastore);
370 $linkDB = new LinkDB(self
::$testDatastore, true, false);
372 $checksum = hash_file('sha1', self
::$testDatastore);
374 $this->conf
->set('resource.data_dir', 'sandbox');
375 $this->conf
->set('resource.datastore', self
::$testDatastore);
377 $updater = new Updater(array(), $linkDB, $this->conf
, true);
378 $this->assertTrue($updater->updateMethodDatastoreIds());
380 $linkDB = new LinkDB(self
::$testDatastore, true, false);
382 $backup = glob($this->conf
->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
383 $backup = $backup[0];
385 $this->assertFileExists($backup);
386 $this->assertEquals($checksum, hash_file('sha1', $backup));
389 $this->assertEquals(3, count($linkDB));
390 $this->assertTrue(isset($linkDB[0]));
391 $this->assertFalse(isset($linkDB[0]['linkdate']));
392 $this->assertEquals(0, $linkDB[0]['id']);
393 $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
394 $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
395 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
396 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
397 $this->assertTrue($linkDB[0]['private']);
399 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_142300'),
400 $linkDB[0]['created']
403 $this->assertTrue(isset($linkDB[1]));
404 $this->assertFalse(isset($linkDB[1]['linkdate']));
405 $this->assertEquals(1, $linkDB[1]['id']);
406 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
408 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_172539'),
409 $linkDB[1]['created']
412 $this->assertTrue(isset($linkDB[2]));
413 $this->assertFalse(isset($linkDB[2]['linkdate']));
414 $this->assertEquals(2, $linkDB[2]['id']);
415 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
417 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_182539'),
418 $linkDB[2]['created']
421 DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_190301'),
422 $linkDB[2]['updated']
427 * Test updateMethodDatastoreIds() with the update already applied: nothing to do.
429 public function testDatastoreIdsNothingToDo()
431 $refDB = new ReferenceLinkDB();
432 $refDB->write(self
::$testDatastore);
433 $linkDB = new LinkDB(self
::$testDatastore, true, false);
435 $this->conf
->set('resource.data_dir', 'sandbox');
436 $this->conf
->set('resource.datastore', self
::$testDatastore);
438 $checksum = hash_file('sha1', self
::$testDatastore);
439 $updater = new Updater(array(), $linkDB, $this->conf
, true);
440 $this->assertTrue($updater->updateMethodDatastoreIds());
441 $this->assertEquals($checksum, hash_file('sha1', self
::$testDatastore));
445 * Test defaultTheme update with default settings: nothing to do.
447 public function testDefaultThemeWithDefaultSettings()
449 $sandbox = 'sandbox/config';
450 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
451 $this->conf
= new ConfigManager($sandbox);
452 $updater = new Updater([], [], $this->conf
, true);
453 $this->assertTrue($updater->updateMethodDefaultTheme());
455 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
456 $this->assertEquals('default', $this->conf
->get('resource.theme'));
457 $this->conf
= new ConfigManager($sandbox);
458 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
459 $this->assertEquals('default', $this->conf
->get('resource.theme'));
460 unlink($sandbox . '.json.php');
464 * Test defaultTheme update with a custom theme in a subfolder
466 public function testDefaultThemeWithCustomTheme()
468 $theme = 'iamanartist';
469 $sandbox = 'sandbox/config';
470 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
471 $this->conf
= new ConfigManager($sandbox);
472 mkdir('sandbox/'. $theme);
473 touch('sandbox/'. $theme .'/linklist.html');
474 $this->conf
->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
475 $updater = new Updater([], [], $this->conf
, true);
476 $this->assertTrue($updater->updateMethodDefaultTheme());
478 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
479 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
480 $this->conf
= new ConfigManager($sandbox);
481 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
482 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
483 unlink($sandbox . '.json.php');
484 unlink('sandbox/'. $theme .'/linklist.html');
485 rmdir('sandbox/'. $theme);
489 * Test updateMethodEscapeMarkdown with markdown plugin enabled
490 * => setting markdown_escape set to false.
492 public function testEscapeMarkdownSettingToFalse()
494 $sandboxConf = 'sandbox/config';
495 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
496 $this->conf
= new ConfigManager($sandboxConf);
498 $this->conf
->set('general.enabled_plugins', ['markdown']);
499 $updater = new Updater([], [], $this->conf
, true);
500 $this->assertTrue($updater->updateMethodEscapeMarkdown());
501 $this->assertFalse($this->conf
->get('security.markdown_escape'));
504 $this->conf
= new ConfigManager($sandboxConf);
505 $this->assertFalse($this->conf
->get('security.markdown_escape'));
510 * Test updateMethodEscapeMarkdown with markdown plugin disabled
511 * => setting markdown_escape set to true.
513 public function testEscapeMarkdownSettingToTrue()
515 $sandboxConf = 'sandbox/config';
516 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
517 $this->conf
= new ConfigManager($sandboxConf);
519 $this->conf
->set('general.enabled_plugins', []);
520 $updater = new Updater([], [], $this->conf
, true);
521 $this->assertTrue($updater->updateMethodEscapeMarkdown());
522 $this->assertTrue($this->conf
->get('security.markdown_escape'));
525 $this->conf
= new ConfigManager($sandboxConf);
526 $this->assertTrue($this->conf
->get('security.markdown_escape'));
530 * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled)
532 public function testEscapeMarkdownSettingNothingToDoEnabled()
534 $sandboxConf = 'sandbox/config';
535 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
536 $this->conf
= new ConfigManager($sandboxConf);
537 $this->conf
->set('security.markdown_escape', true);
538 $updater = new Updater([], [], $this->conf
, true);
539 $this->assertTrue($updater->updateMethodEscapeMarkdown());
540 $this->assertTrue($this->conf
->get('security.markdown_escape'));
544 * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled)
546 public function testEscapeMarkdownSettingNothingToDoDisabled()
548 $this->conf
->set('security.markdown_escape', false);
549 $updater = new Updater([], [], $this->conf
, true);
550 $this->assertTrue($updater->updateMethodEscapeMarkdown());
551 $this->assertFalse($this->conf
->get('security.markdown_escape'));
555 * Test updateMethodPiwikUrl with valid data
557 public function testUpdatePiwikUrlValid()
559 $sandboxConf = 'sandbox/config';
560 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
561 $this->conf
= new ConfigManager($sandboxConf);
562 $url = 'mypiwik.tld';
563 $this->conf
->set('plugins.PIWIK_URL', $url);
564 $updater = new Updater([], [], $this->conf
, true);
565 $this->assertTrue($updater->updateMethodPiwikUrl());
566 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
569 $this->conf
= new ConfigManager($sandboxConf);
570 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
574 * Test updateMethodPiwikUrl without setting
576 public function testUpdatePiwikUrlEmpty()
578 $updater = new Updater([], [], $this->conf
, true);
579 $this->assertTrue($updater->updateMethodPiwikUrl());
580 $this->assertEmpty($this->conf
->get('plugins.PIWIK_URL'));
584 * Test updateMethodPiwikUrl: valid URL, nothing to do
586 public function testUpdatePiwikUrlNothingToDo()
588 $url = 'https://mypiwik.tld';
589 $this->conf
->set('plugins.PIWIK_URL', $url);
590 $updater = new Updater([], [], $this->conf
, true);
591 $this->assertTrue($updater->updateMethodPiwikUrl());
592 $this->assertEquals($url, $this->conf
->get('plugins.PIWIK_URL'));
596 * Test updateMethodAtomDefault with show_atom set to false
599 public function testUpdateMethodAtomDefault()
601 $sandboxConf = 'sandbox/config';
602 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
603 $this->conf
= new ConfigManager($sandboxConf);
604 $this->conf
->set('feed.show_atom', false);
605 $updater = new Updater([], [], $this->conf
, true);
606 $this->assertTrue($updater->updateMethodAtomDefault());
607 $this->assertTrue($this->conf
->get('feed.show_atom'));
609 $this->conf
= new ConfigManager($sandboxConf);
610 $this->assertTrue($this->conf
->get('feed.show_atom'));
613 * Test updateMethodAtomDefault with show_atom not set.
616 public function testUpdateMethodAtomDefaultNoExist()
618 $sandboxConf = 'sandbox/config';
619 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
620 $this->conf
= new ConfigManager($sandboxConf);
621 $updater = new Updater([], [], $this->conf
, true);
622 $this->assertTrue($updater->updateMethodAtomDefault());
623 $this->assertTrue($this->conf
->get('feed.show_atom'));
626 * Test updateMethodAtomDefault with show_atom set to true.
629 public function testUpdateMethodAtomDefaultAlreadyTrue()
631 $sandboxConf = 'sandbox/config';
632 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
633 $this->conf
= new ConfigManager($sandboxConf);
634 $this->conf
->set('feed.show_atom', true);
635 $updater = new Updater([], [], $this->conf
, true);
636 $this->assertTrue($updater->updateMethodAtomDefault());
637 $this->assertTrue($this->conf
->get('feed.show_atom'));
641 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
643 public function testUpdateMethodDownloadSizeAndTimeoutConf()
645 $sandboxConf = 'sandbox/config';
646 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
647 $this->conf
= new ConfigManager($sandboxConf);
648 $updater = new Updater([], [], $this->conf
, true);
649 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
650 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
651 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
653 $this->conf
= new ConfigManager($sandboxConf);
654 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
655 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
659 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
661 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
663 $sandboxConf = 'sandbox/config';
664 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
665 $this->conf
= new ConfigManager($sandboxConf);
666 $this->conf
->set('general.download_max_size', 38);
667 $this->conf
->set('general.download_timeout', 70);
668 $updater = new Updater([], [], $this->conf
, true);
669 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
670 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
671 $this->assertEquals(70, $this->conf
->get('general.download_timeout'));
675 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
677 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
679 $sandboxConf = 'sandbox/config';
680 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
681 $this->conf
= new ConfigManager($sandboxConf);
682 $this->conf
->set('general.download_max_size', 38);
683 $updater = new Updater([], [], $this->conf
, true);
684 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
685 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
686 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
690 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
692 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
694 $sandboxConf = 'sandbox/config';
695 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
696 $this->conf
= new ConfigManager($sandboxConf);
697 $this->conf
->set('general.download_timeout', 3);
698 $updater = new Updater([], [], $this->conf
, true);
699 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
700 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
701 $this->assertEquals(3, $this->conf
->get('general.download_timeout'));
706 * Test updateMethodWebThumbnailer with thumbnails enabled.
708 public function testUpdateMethodWebThumbnailerEnabled()
710 $this->conf
->remove('thumbnails');
711 $this->conf
->set('thumbnail.enable_thumbnails', true);
712 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
713 $this->assertTrue($updater->updateMethodWebThumbnailer());
714 $this->assertFalse($this->conf
->exists('thumbnail'));
715 $this->assertEquals(\Shaarli\Thumbnailer
::MODE_ALL
, $this->conf
->get('thumbnails.mode'));
716 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
717 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
718 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
722 * Test updateMethodWebThumbnailer with thumbnails disabled.
724 public function testUpdateMethodWebThumbnailerDisabled()
726 $this->conf
->remove('thumbnails');
727 $this->conf
->set('thumbnail.enable_thumbnails', false);
728 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
729 $this->assertTrue($updater->updateMethodWebThumbnailer());
730 $this->assertFalse($this->conf
->exists('thumbnail'));
731 $this->assertEquals(Thumbnailer
::MODE_NONE
, $this->conf
->get('thumbnails.mode'));
732 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
733 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
734 $this->assertTrue(empty($_SESSION['warnings']));
738 * Test updateMethodWebThumbnailer with thumbnails disabled.
740 public function testUpdateMethodWebThumbnailerNothingToDo()
742 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
743 $this->assertTrue($updater->updateMethodWebThumbnailer());
744 $this->assertFalse($this->conf
->exists('thumbnail'));
745 $this->assertEquals(Thumbnailer
::MODE_COMMON
, $this->conf
->get('thumbnails.mode'));
746 $this->assertEquals(90, $this->conf
->get('thumbnails.width'));
747 $this->assertEquals(53, $this->conf
->get('thumbnails.height'));
748 $this->assertTrue(empty($_SESSION['warnings']));
752 * Test updateMethodSetSticky().
754 public function testUpdateStickyValid()
762 'created' => new DateTime(),
765 1 => ['id' => 1] +
$blank,
766 2 => ['id' => 2] +
$blank,
768 $refDB = new ReferenceLinkDB();
769 $refDB->setLinks($links);
770 $refDB->write(self
::$testDatastore);
771 $linkDB = new LinkDB(self
::$testDatastore, true, false);
773 $updater = new Updater(array(), $linkDB, $this->conf
, true);
774 $this->assertTrue($updater->updateMethodSetSticky());
776 $linkDB = new LinkDB(self
::$testDatastore, true, false);
777 foreach ($linkDB as $link) {
778 $this->assertFalse($link['sticky']);
783 * Test updateMethodSetSticky().
785 public function testUpdateStickyNothingToDo()
793 'created' => new DateTime(),
796 1 => ['id' => 1, 'sticky' => true] +
$blank,
797 2 => ['id' => 2] +
$blank,
799 $refDB = new ReferenceLinkDB();
800 $refDB->setLinks($links);
801 $refDB->write(self
::$testDatastore);
802 $linkDB = new LinkDB(self
::$testDatastore, true, false);
804 $updater = new Updater(array(), $linkDB, $this->conf
, true);
805 $this->assertTrue($updater->updateMethodSetSticky());
807 $linkDB = new LinkDB(self
::$testDatastore, true, false);
808 $this->assertTrue($linkDB[1]['sticky']);