2 use Shaarli\Config\ConfigJson
;
3 use Shaarli\Config\ConfigManager
;
4 use Shaarli\Config\ConfigPhp
;
6 require_once 'tests/Updater/DummyUpdater.php';
7 require_once 'inc/rain.tpl.class.php';
11 * Runs unit tests against the Updater class.
13 class UpdaterTest
extends PHPUnit_Framework_TestCase
16 * @var string Path to test datastore.
18 protected static $testDatastore = 'sandbox/datastore.php';
21 * @var string Config file path (without extension).
23 protected static $configFile = 'sandbox/config';
31 * Executed before each test.
33 public function setUp()
35 copy('tests/utils/config/configJson.json.php', self
::$configFile .'.json.php');
36 $this->conf
= new ConfigManager(self
::$configFile);
40 * Test read_updates_file with an empty/missing file.
42 public function testReadEmptyUpdatesFile()
44 $this->assertEquals(array(), read_updates_file(''));
45 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
47 $this->assertEquals(array(), read_updates_file($updatesFile));
52 * Test read/write updates file.
54 public function testReadWriteUpdatesFile()
56 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
57 $updatesMethods = array('m1', 'm2', 'm3');
59 write_updates_file($updatesFile, $updatesMethods);
60 $readMethods = read_updates_file($updatesFile);
61 $this->assertEquals($readMethods, $updatesMethods);
64 $updatesMethods[] = 'm4';
65 write_updates_file($updatesFile, $updatesMethods);
66 $readMethods = read_updates_file($updatesFile);
67 $this->assertEquals($readMethods, $updatesMethods);
72 * Test errors in write_updates_file(): empty updates file.
74 * @expectedException Exception
75 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
77 public function testWriteEmptyUpdatesFile()
79 write_updates_file('', array('test'));
83 * Test errors in write_updates_file(): not writable updates file.
85 * @expectedException Exception
86 * @expectedExceptionMessageRegExp /Unable to write(.*)/
88 public function testWriteUpdatesFileNotWritable()
90 $updatesFile = $this->conf
->get('resource.data_dir') . '/updates.txt';
92 chmod($updatesFile, 0444);
94 @write_updates_file($updatesFile, array('test'));
95 } catch (Exception
$e) {
102 * Test the update() method, with no update to run.
103 * 1. Everything already run.
104 * 2. User is logged out.
106 public function testNoUpdates()
109 'updateMethodDummy1',
110 'updateMethodDummy2',
111 'updateMethodDummy3',
112 'updateMethodException',
114 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
115 $this->assertEquals(array(), $updater->update());
117 $updater = new DummyUpdater(array(), array(), $this->conf
, false);
118 $this->assertEquals(array(), $updater->update());
122 * Test the update() method, with all updates to run (except the failing one).
124 public function testUpdatesFirstTime()
126 $updates = array('updateMethodException',);
127 $expectedUpdates = array(
128 'updateMethodDummy1',
129 'updateMethodDummy2',
130 'updateMethodDummy3',
132 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
133 $this->assertEquals($expectedUpdates, $updater->update());
137 * Test the update() method, only one update to run.
139 public function testOneUpdate()
142 'updateMethodDummy1',
143 'updateMethodDummy3',
144 'updateMethodException',
146 $expectedUpdate = array('updateMethodDummy2');
148 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
149 $this->assertEquals($expectedUpdate, $updater->update());
153 * Test Update failed.
155 * @expectedException UpdaterException
157 public function testUpdateFailed()
160 'updateMethodDummy1',
161 'updateMethodDummy2',
162 'updateMethodDummy3',
165 $updater = new DummyUpdater($updates, array(), $this->conf
, true);
170 * Test update mergeDeprecatedConfig:
171 * 1. init a config file.
172 * 2. init a options.php file with update value.
174 * 4. check updated value in config file.
176 public function testUpdateMergeDeprecatedConfig()
178 $this->conf
->setConfigFile('tests/utils/config/configPhp');
179 $this->conf
->reset();
181 $optionsFile = 'tests/Updater/options.php';
183 $GLOBALS[\'privateLinkByDefault\'] = true;';
184 file_put_contents($optionsFile, $options);
187 $this->conf
->setConfigFile('tests/Updater/config');
190 $updater = new Updater(array(), array(), $this->conf
, true);
191 // This writes a new config file in tests/Updater/config.php
192 $updater->updateMethodMergeDeprecatedConfigFile();
194 // make sure updated field is changed
195 $this->conf
->reload();
196 $this->assertTrue($this->conf
->get('privacy.default_private_links'));
197 $this->assertFalse(is_file($optionsFile));
198 // Delete the generated file.
199 unlink($this->conf
->getConfigFileExt());
203 * Test mergeDeprecatedConfig in without options file.
205 public function testMergeDeprecatedConfigNoFile()
207 $updater = new Updater(array(), array(), $this->conf
, true);
208 $updater->updateMethodMergeDeprecatedConfigFile();
210 $this->assertEquals('root', $this->conf
->get('credentials.login'));
214 * Test renameDashTags update method.
216 public function testRenameDashTags()
218 $refDB = new ReferenceLinkDB();
219 $refDB->write(self
::$testDatastore);
220 $linkDB = new LinkDB(self
::$testDatastore, true, false);
222 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
223 $updater = new Updater(array(), $linkDB, $this->conf
, true);
224 $updater->updateMethodRenameDashTags();
225 $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
229 * Convert old PHP config file to JSON config.
231 public function testConfigToJson()
233 $configFile = 'tests/utils/config/configPhp';
234 $this->conf
->setConfigFile($configFile);
235 $this->conf
->reset();
237 // The ConfigIO is initialized with ConfigPhp.
238 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigPhp
);
240 $updater = new Updater(array(), array(), $this->conf
, false);
241 $done = $updater->updateMethodConfigToJson();
242 $this->assertTrue($done);
244 // The ConfigIO has been updated to ConfigJson.
245 $this->assertTrue($this->conf
->getConfigIO() instanceof ConfigJson
);
246 $this->assertTrue(file_exists($this->conf
->getConfigFileExt()));
248 // Check JSON config data.
249 $this->conf
->reload();
250 $this->assertEquals('root', $this->conf
->get('credentials.login'));
251 $this->assertEquals('lala', $this->conf
->get('redirector.url'));
252 $this->assertEquals('data/datastore.php', $this->conf
->get('resource.datastore'));
253 $this->assertEquals('1', $this->conf
->get('plugins.WALLABAG_VERSION'));
255 rename($configFile . '.save.php', $configFile . '.php');
256 unlink($this->conf
->getConfigFileExt());
260 * Launch config conversion update with an existing JSON file => nothing to do.
262 public function testConfigToJsonNothingToDo()
264 $filetime = filemtime($this->conf
->getConfigFileExt());
265 $updater = new Updater(array(), array(), $this->conf
, false);
266 $done = $updater->updateMethodConfigToJson();
267 $this->assertTrue($done);
268 $expected = filemtime($this->conf
->getConfigFileExt());
269 $this->assertEquals($expected, $filetime);
273 * Test escapeUnescapedConfig with valid data.
275 public function testEscapeConfig()
277 $sandbox = 'sandbox/config';
278 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
279 $this->conf
= new ConfigManager($sandbox);
280 $title = '<script>alert("title");</script>';
281 $headerLink = '<script>alert("header_link");</script>';
282 $redirectorUrl = '<script>alert("redirector");</script>';
283 $this->conf
->set('general.title', $title);
284 $this->conf
->set('general.header_link', $headerLink);
285 $this->conf
->set('redirector.url', $redirectorUrl);
286 $updater = new Updater(array(), array(), $this->conf
, true);
287 $done = $updater->updateMethodEscapeUnescapedConfig();
288 $this->assertTrue($done);
289 $this->conf
->reload();
290 $this->assertEquals(escape($title), $this->conf
->get('general.title'));
291 $this->assertEquals(escape($headerLink), $this->conf
->get('general.header_link'));
292 $this->assertEquals(escape($redirectorUrl), $this->conf
->get('redirector.url'));
293 unlink($sandbox . '.json.php');
297 * Test updateMethodApiSettings(): create default settings for the API (enabled + secret).
299 public function testUpdateApiSettings()
301 $confFile = 'sandbox/config';
302 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
303 $conf = new ConfigManager($confFile);
304 $updater = new Updater(array(), array(), $conf, true);
306 $this->assertFalse($conf->exists('api.enabled'));
307 $this->assertFalse($conf->exists('api.secret'));
308 $updater->updateMethodApiSettings();
310 $this->assertTrue($conf->get('api.enabled'));
311 $this->assertTrue($conf->exists('api.secret'));
312 unlink($confFile .'.json.php');
316 * Test updateMethodApiSettings(): already set, do nothing.
318 public function testUpdateApiSettingsNothingToDo()
320 $confFile = 'sandbox/config';
321 copy(self
::$configFile .'.json.php', $confFile .'.json.php');
322 $conf = new ConfigManager($confFile);
323 $conf->set('api.enabled', false);
324 $conf->set('api.secret', '');
325 $updater = new Updater(array(), array(), $conf, true);
326 $updater->updateMethodApiSettings();
327 $this->assertFalse($conf->get('api.enabled'));
328 $this->assertEmpty($conf->get('api.secret'));
329 unlink($confFile .'.json.php');
333 * Test updateMethodDatastoreIds().
335 public function testDatastoreIds()
338 '20121206_182539' => array(
339 'linkdate' => '20121206_182539',
340 'title' => 'Geek and Poke',
341 'url' => 'http://geek-and-poke.com/',
342 'description' => 'desc',
343 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
344 'updated' => '20121206_190301',
347 '20121206_172539' => array(
348 'linkdate' => '20121206_172539',
349 'title' => 'UserFriendly - Samba',
350 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
352 'tags' => 'samba cartoon web',
355 '20121206_142300' => array(
356 'linkdate' => '20121206_142300',
357 'title' => 'UserFriendly - Web Designer',
358 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
359 'description' => 'Naming conventions... #private',
360 'tags' => 'samba cartoon web',
364 $refDB = new ReferenceLinkDB();
365 $refDB->setLinks($links);
366 $refDB->write(self
::$testDatastore);
367 $linkDB = new LinkDB(self
::$testDatastore, true, false);
369 $checksum = hash_file('sha1', self
::$testDatastore);
371 $this->conf
->set('resource.data_dir', 'sandbox');
372 $this->conf
->set('resource.datastore', self
::$testDatastore);
374 $updater = new Updater(array(), $linkDB, $this->conf
, true);
375 $this->assertTrue($updater->updateMethodDatastoreIds());
377 $linkDB = new LinkDB(self
::$testDatastore, true, false);
379 $backup = glob($this->conf
->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
380 $backup = $backup[0];
382 $this->assertFileExists($backup);
383 $this->assertEquals($checksum, hash_file('sha1', $backup));
386 $this->assertEquals(3, count($linkDB));
387 $this->assertTrue(isset($linkDB[0]));
388 $this->assertFalse(isset($linkDB[0]['linkdate']));
389 $this->assertEquals(0, $linkDB[0]['id']);
390 $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
391 $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
392 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
393 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
394 $this->assertTrue($linkDB[0]['private']);
395 $this->assertEquals(DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_142300'), $linkDB[0]['created']);
397 $this->assertTrue(isset($linkDB[1]));
398 $this->assertFalse(isset($linkDB[1]['linkdate']));
399 $this->assertEquals(1, $linkDB[1]['id']);
400 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
401 $this->assertEquals(DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_172539'), $linkDB[1]['created']);
403 $this->assertTrue(isset($linkDB[2]));
404 $this->assertFalse(isset($linkDB[2]['linkdate']));
405 $this->assertEquals(2, $linkDB[2]['id']);
406 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
407 $this->assertEquals(DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_182539'), $linkDB[2]['created']);
408 $this->assertEquals(DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, '20121206_190301'), $linkDB[2]['updated']);
412 * Test updateMethodDatastoreIds() with the update already applied: nothing to do.
414 public function testDatastoreIdsNothingToDo()
416 $refDB = new ReferenceLinkDB();
417 $refDB->write(self
::$testDatastore);
418 $linkDB = new LinkDB(self
::$testDatastore, true, false);
420 $this->conf
->set('resource.data_dir', 'sandbox');
421 $this->conf
->set('resource.datastore', self
::$testDatastore);
423 $checksum = hash_file('sha1', self
::$testDatastore);
424 $updater = new Updater(array(), $linkDB, $this->conf
, true);
425 $this->assertTrue($updater->updateMethodDatastoreIds());
426 $this->assertEquals($checksum, hash_file('sha1', self
::$testDatastore));
430 * Test defaultTheme update with default settings: nothing to do.
432 public function testDefaultThemeWithDefaultSettings()
434 $sandbox = 'sandbox/config';
435 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
436 $this->conf
= new ConfigManager($sandbox);
437 $updater = new Updater([], [], $this->conf
, true);
438 $this->assertTrue($updater->updateMethodDefaultTheme());
440 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
441 $this->assertEquals('default', $this->conf
->get('resource.theme'));
442 $this->conf
= new ConfigManager($sandbox);
443 $this->assertEquals('tpl/', $this->conf
->get('resource.raintpl_tpl'));
444 $this->assertEquals('default', $this->conf
->get('resource.theme'));
445 unlink($sandbox . '.json.php');
449 * Test defaultTheme update with a custom theme in a subfolder
451 public function testDefaultThemeWithCustomTheme()
453 $theme = 'iamanartist';
454 $sandbox = 'sandbox/config';
455 copy(self
::$configFile . '.json.php', $sandbox . '.json.php');
456 $this->conf
= new ConfigManager($sandbox);
457 mkdir('sandbox/'. $theme);
458 touch('sandbox/'. $theme .'/linklist.html');
459 $this->conf
->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
460 $updater = new Updater([], [], $this->conf
, true);
461 $this->assertTrue($updater->updateMethodDefaultTheme());
463 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
464 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
465 $this->conf
= new ConfigManager($sandbox);
466 $this->assertEquals('sandbox', $this->conf
->get('resource.raintpl_tpl'));
467 $this->assertEquals($theme, $this->conf
->get('resource.theme'));
468 unlink($sandbox . '.json.php');
469 unlink('sandbox/'. $theme .'/linklist.html');
470 rmdir('sandbox/'. $theme);
474 * Test updateMethodEscapeMarkdown with markdown plugin enabled
475 * => setting markdown_escape set to false.
477 public function testEscapeMarkdownSettingToFalse()
479 $sandboxConf = 'sandbox/config';
480 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
481 $this->conf
= new ConfigManager($sandboxConf);
483 $this->conf
->set('general.enabled_plugins', ['markdown']);
484 $updater = new Updater([], [], $this->conf
, true);
485 $this->assertTrue($updater->updateMethodEscapeMarkdown());
486 $this->assertFalse($this->conf
->get('security.markdown_escape'));
489 $this->conf
= new ConfigManager($sandboxConf);
490 $this->assertFalse($this->conf
->get('security.markdown_escape'));
495 * Test updateMethodEscapeMarkdown with markdown plugin disabled
496 * => setting markdown_escape set to true.
498 public function testEscapeMarkdownSettingToTrue()
500 $sandboxConf = 'sandbox/config';
501 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
502 $this->conf
= new ConfigManager($sandboxConf);
504 $this->conf
->set('general.enabled_plugins', []);
505 $updater = new Updater([], [], $this->conf
, true);
506 $this->assertTrue($updater->updateMethodEscapeMarkdown());
507 $this->assertTrue($this->conf
->get('security.markdown_escape'));
510 $this->conf
= new ConfigManager($sandboxConf);
511 $this->assertTrue($this->conf
->get('security.markdown_escape'));
515 * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled)
517 public function testEscapeMarkdownSettingNothingToDoEnabled()
519 $sandboxConf = 'sandbox/config';
520 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
521 $this->conf
= new ConfigManager($sandboxConf);
522 $this->conf
->set('security.markdown_escape', true);
523 $updater = new Updater([], [], $this->conf
, true);
524 $this->assertTrue($updater->updateMethodEscapeMarkdown());
525 $this->assertTrue($this->conf
->get('security.markdown_escape'));
529 * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled)
531 public function testEscapeMarkdownSettingNothingToDoDisabled()
533 $this->conf
->set('security.markdown_escape', false);
534 $updater = new Updater([], [], $this->conf
, true);
535 $this->assertTrue($updater->updateMethodEscapeMarkdown());
536 $this->assertFalse($this->conf
->get('security.markdown_escape'));
540 * Test updateMethodPiwikUrl with valid data
542 public function testUpdatePiwikUrlValid()
544 $sandboxConf = 'sandbox/config';
545 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
546 $this->conf
= new ConfigManager($sandboxConf);
547 $url = 'mypiwik.tld';
548 $this->conf
->set('plugins.PIWIK_URL', $url);
549 $updater = new Updater([], [], $this->conf
, true);
550 $this->assertTrue($updater->updateMethodPiwikUrl());
551 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
554 $this->conf
= new ConfigManager($sandboxConf);
555 $this->assertEquals('http://'. $url, $this->conf
->get('plugins.PIWIK_URL'));
559 * Test updateMethodPiwikUrl without setting
561 public function testUpdatePiwikUrlEmpty()
563 $updater = new Updater([], [], $this->conf
, true);
564 $this->assertTrue($updater->updateMethodPiwikUrl());
565 $this->assertEmpty($this->conf
->get('plugins.PIWIK_URL'));
569 * Test updateMethodPiwikUrl: valid URL, nothing to do
571 public function testUpdatePiwikUrlNothingToDo()
573 $url = 'https://mypiwik.tld';
574 $this->conf
->set('plugins.PIWIK_URL', $url);
575 $updater = new Updater([], [], $this->conf
, true);
576 $this->assertTrue($updater->updateMethodPiwikUrl());
577 $this->assertEquals($url, $this->conf
->get('plugins.PIWIK_URL'));
581 * Test updateMethodAtomDefault with show_atom set to false
584 public function testUpdateMethodAtomDefault()
586 $sandboxConf = 'sandbox/config';
587 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
588 $this->conf
= new ConfigManager($sandboxConf);
589 $this->conf
->set('feed.show_atom', false);
590 $updater = new Updater([], [], $this->conf
, true);
591 $this->assertTrue($updater->updateMethodAtomDefault());
592 $this->assertTrue($this->conf
->get('feed.show_atom'));
594 $this->conf
= new ConfigManager($sandboxConf);
595 $this->assertTrue($this->conf
->get('feed.show_atom'));
598 * Test updateMethodAtomDefault with show_atom not set.
601 public function testUpdateMethodAtomDefaultNoExist()
603 $sandboxConf = 'sandbox/config';
604 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
605 $this->conf
= new ConfigManager($sandboxConf);
606 $updater = new Updater([], [], $this->conf
, true);
607 $this->assertTrue($updater->updateMethodAtomDefault());
608 $this->assertTrue($this->conf
->get('feed.show_atom'));
611 * Test updateMethodAtomDefault with show_atom set to true.
614 public function testUpdateMethodAtomDefaultAlreadyTrue()
616 $sandboxConf = 'sandbox/config';
617 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
618 $this->conf
= new ConfigManager($sandboxConf);
619 $this->conf
->set('feed.show_atom', true);
620 $updater = new Updater([], [], $this->conf
, true);
621 $this->assertTrue($updater->updateMethodAtomDefault());
622 $this->assertTrue($this->conf
->get('feed.show_atom'));
626 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
628 public function testUpdateMethodDownloadSizeAndTimeoutConf()
630 $sandboxConf = 'sandbox/config';
631 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
632 $this->conf
= new ConfigManager($sandboxConf);
633 $updater = new Updater([], [], $this->conf
, true);
634 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
635 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
636 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
638 $this->conf
= new ConfigManager($sandboxConf);
639 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
640 $this->assertEquals(30, $this->conf
->get('general.download_timeout'));
644 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
646 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
648 $sandboxConf = 'sandbox/config';
649 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
650 $this->conf
= new ConfigManager($sandboxConf);
651 $this->conf
->set('general.download_max_size', 38);
652 $this->conf
->set('general.download_timeout', 70);
653 $updater = new Updater([], [], $this->conf
, true);
654 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
655 $this->assertEquals(38, $this->conf
->get('general.download_max_size'));
656 $this->assertEquals(70, $this->conf
->get('general.download_timeout'));
660 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
662 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
664 $sandboxConf = 'sandbox/config';
665 copy(self
::$configFile . '.json.php', $sandboxConf . '.json.php');
666 $this->conf
= new ConfigManager($sandboxConf);
667 $this->conf
->set('general.download_max_size', 38);
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(30, $this->conf
->get('general.download_timeout'));
675 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
677 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
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_timeout', 3);
683 $updater = new Updater([], [], $this->conf
, true);
684 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
685 $this->assertEquals(4194304, $this->conf
->get('general.download_max_size'));
686 $this->assertEquals(3, $this->conf
->get('general.download_timeout'));
690 * Test updateMethodWebThumbnailer with thumbnails enabled.
692 public function testUpdateMethodWebThumbnailerEnabled()
694 $this->conf
->remove('thumbnails');
695 $this->conf
->set('thumbnail.enable_thumbnails', true);
696 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
697 $this->assertTrue($updater->updateMethodWebThumbnailer());
698 $this->assertFalse($this->conf
->exists('thumbnail'));
699 $this->assertTrue($this->conf
->get('thumbnails.enabled'));
700 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
701 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
702 $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]);
706 * Test updateMethodWebThumbnailer with thumbnails disabled.
708 public function testUpdateMethodWebThumbnailerDisabled()
710 $this->conf
->remove('thumbnails');
711 $this->conf
->set('thumbnail.enable_thumbnails', false);
712 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
713 $this->assertTrue($updater->updateMethodWebThumbnailer());
714 $this->assertFalse($this->conf
->exists('thumbnail'));
715 $this->assertFalse($this->conf
->get('thumbnails.enabled'));
716 $this->assertEquals(125, $this->conf
->get('thumbnails.width'));
717 $this->assertEquals(90, $this->conf
->get('thumbnails.height'));
718 $this->assertTrue(empty($_SESSION['warnings']));
722 * Test updateMethodWebThumbnailer with thumbnails disabled.
724 public function testUpdateMethodWebThumbnailerNothingToDo()
726 $updater = new Updater([], [], $this->conf
, true, $_SESSION);
727 $this->assertTrue($updater->updateMethodWebThumbnailer());
728 $this->assertFalse($this->conf
->exists('thumbnail'));
729 $this->assertTrue($this->conf
->get('thumbnails.enabled'));
730 $this->assertEquals(90, $this->conf
->get('thumbnails.width'));
731 $this->assertEquals(53, $this->conf
->get('thumbnails.height'));
732 $this->assertTrue(empty($_SESSION['warnings']));