aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Updater/UpdaterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Updater/UpdaterTest.php')
-rw-r--r--tests/Updater/UpdaterTest.php114
1 files changed, 113 insertions, 1 deletions
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index fed175df..cacee2d2 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -2,6 +2,7 @@
2use Shaarli\Config\ConfigJson; 2use Shaarli\Config\ConfigJson;
3use Shaarli\Config\ConfigManager; 3use Shaarli\Config\ConfigManager;
4use Shaarli\Config\ConfigPhp; 4use Shaarli\Config\ConfigPhp;
5use Shaarli\Thumbnailer;
5 6
6require_once 'tests/Updater/DummyUpdater.php'; 7require_once 'tests/Updater/DummyUpdater.php';
7require_once 'inc/rain.tpl.class.php'; 8require_once 'inc/rain.tpl.class.php';
@@ -20,7 +21,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
20 /** 21 /**
21 * @var string Config file path (without extension). 22 * @var string Config file path (without extension).
22 */ 23 */
23 protected static $configFile = 'tests/utils/config/configJson'; 24 protected static $configFile = 'sandbox/config';
24 25
25 /** 26 /**
26 * @var ConfigManager 27 * @var ConfigManager
@@ -32,6 +33,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
32 */ 33 */
33 public function setUp() 34 public function setUp()
34 { 35 {
36 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
35 $this->conf = new ConfigManager(self::$configFile); 37 $this->conf = new ConfigManager(self::$configFile);
36 } 38 }
37 39
@@ -620,4 +622,114 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
620 $this->assertTrue($updater->updateMethodAtomDefault()); 622 $this->assertTrue($updater->updateMethodAtomDefault());
621 $this->assertTrue($this->conf->get('feed.show_atom')); 623 $this->assertTrue($this->conf->get('feed.show_atom'));
622 } 624 }
625
626 /**
627 * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
628 */
629 public function testUpdateMethodDownloadSizeAndTimeoutConf()
630 {
631 $sandboxConf = 'sandbox/config';
632 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
633 $this->conf = new ConfigManager($sandboxConf);
634 $updater = new Updater([], [], $this->conf, true);
635 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
636 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
637 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
638
639 $this->conf = new ConfigManager($sandboxConf);
640 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
641 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
642 }
643
644 /**
645 * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
646 */
647 public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
648 {
649 $sandboxConf = 'sandbox/config';
650 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
651 $this->conf = new ConfigManager($sandboxConf);
652 $this->conf->set('general.download_max_size', 38);
653 $this->conf->set('general.download_timeout', 70);
654 $updater = new Updater([], [], $this->conf, true);
655 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
656 $this->assertEquals(38, $this->conf->get('general.download_max_size'));
657 $this->assertEquals(70, $this->conf->get('general.download_timeout'));
658 }
659
660 /**
661 * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
662 */
663 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
664 {
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 $updater = new Updater([], [], $this->conf, true);
670 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
671 $this->assertEquals(38, $this->conf->get('general.download_max_size'));
672 $this->assertEquals(30, $this->conf->get('general.download_timeout'));
673 }
674
675 /**
676 * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
677 */
678 public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
679 {
680 $sandboxConf = 'sandbox/config';
681 copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
682 $this->conf = new ConfigManager($sandboxConf);
683 $this->conf->set('general.download_timeout', 3);
684 $updater = new Updater([], [], $this->conf, true);
685 $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
686 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
687 $this->assertEquals(3, $this->conf->get('general.download_timeout'));
688 }
689
690 /**
691 * Test updateMethodWebThumbnailer with thumbnails enabled.
692 */
693 public function testUpdateMethodWebThumbnailerEnabled()
694 {
695 $this->conf->remove('thumbnails');
696 $this->conf->set('thumbnail.enable_thumbnails', true);
697 $updater = new Updater([], [], $this->conf, true, $_SESSION);
698 $this->assertTrue($updater->updateMethodWebThumbnailer());
699 $this->assertFalse($this->conf->exists('thumbnail'));
700 $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode'));
701 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
702 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
703 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
704 }
705
706 /**
707 * Test updateMethodWebThumbnailer with thumbnails disabled.
708 */
709 public function testUpdateMethodWebThumbnailerDisabled()
710 {
711 $this->conf->remove('thumbnails');
712 $this->conf->set('thumbnail.enable_thumbnails', false);
713 $updater = new Updater([], [], $this->conf, true, $_SESSION);
714 $this->assertTrue($updater->updateMethodWebThumbnailer());
715 $this->assertFalse($this->conf->exists('thumbnail'));
716 $this->assertEquals(Thumbnailer::MODE_NONE, $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->assertTrue(empty($_SESSION['warnings']));
720 }
721
722 /**
723 * Test updateMethodWebThumbnailer with thumbnails disabled.
724 */
725 public function testUpdateMethodWebThumbnailerNothingToDo()
726 {
727 $updater = new Updater([], [], $this->conf, true, $_SESSION);
728 $this->assertTrue($updater->updateMethodWebThumbnailer());
729 $this->assertFalse($this->conf->exists('thumbnail'));
730 $this->assertEquals(Thumbnailer::MODE_COMMON, $this->conf->get('thumbnails.mode'));
731 $this->assertEquals(90, $this->conf->get('thumbnails.width'));
732 $this->assertEquals(53, $this->conf->get('thumbnails.height'));
733 $this->assertTrue(empty($_SESSION['warnings']));
734 }
623} 735}