diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
commit | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch) | |
tree | dae4c7c47532380eac3ae641db99122fc77c93dc /tests/Updater/UpdaterTest.php | |
parent | 83faedadff76c5bdca036f39f13943f63b27e164 (diff) | |
parent | 1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff) | |
download | Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip |
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'tests/Updater/UpdaterTest.php')
-rw-r--r-- | tests/Updater/UpdaterTest.php | 195 |
1 files changed, 190 insertions, 5 deletions
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 77578528..608e331d 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | use Shaarli\Config\ConfigJson; | 2 | use Shaarli\Config\ConfigJson; |
3 | use Shaarli\Config\ConfigManager; | 3 | use Shaarli\Config\ConfigManager; |
4 | use Shaarli\Config\ConfigPhp; | 4 | use Shaarli\Config\ConfigPhp; |
5 | use Shaarli\Thumbnailer; | ||
5 | 6 | ||
6 | require_once 'tests/Updater/DummyUpdater.php'; | 7 | require_once 'tests/Updater/DummyUpdater.php'; |
7 | require_once 'inc/rain.tpl.class.php'; | 8 | require_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 | ||
@@ -391,20 +393,32 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
391 | $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']); | 393 | $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']); |
392 | $this->assertEquals('samba cartoon web', $linkDB[0]['tags']); | 394 | $this->assertEquals('samba cartoon web', $linkDB[0]['tags']); |
393 | $this->assertTrue($linkDB[0]['private']); | 395 | $this->assertTrue($linkDB[0]['private']); |
394 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), $linkDB[0]['created']); | 396 | $this->assertEquals( |
397 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), | ||
398 | $linkDB[0]['created'] | ||
399 | ); | ||
395 | 400 | ||
396 | $this->assertTrue(isset($linkDB[1])); | 401 | $this->assertTrue(isset($linkDB[1])); |
397 | $this->assertFalse(isset($linkDB[1]['linkdate'])); | 402 | $this->assertFalse(isset($linkDB[1]['linkdate'])); |
398 | $this->assertEquals(1, $linkDB[1]['id']); | 403 | $this->assertEquals(1, $linkDB[1]['id']); |
399 | $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']); | 404 | $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']); |
400 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), $linkDB[1]['created']); | 405 | $this->assertEquals( |
406 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), | ||
407 | $linkDB[1]['created'] | ||
408 | ); | ||
401 | 409 | ||
402 | $this->assertTrue(isset($linkDB[2])); | 410 | $this->assertTrue(isset($linkDB[2])); |
403 | $this->assertFalse(isset($linkDB[2]['linkdate'])); | 411 | $this->assertFalse(isset($linkDB[2]['linkdate'])); |
404 | $this->assertEquals(2, $linkDB[2]['id']); | 412 | $this->assertEquals(2, $linkDB[2]['id']); |
405 | $this->assertEquals('Geek and Poke', $linkDB[2]['title']); | 413 | $this->assertEquals('Geek and Poke', $linkDB[2]['title']); |
406 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), $linkDB[2]['created']); | 414 | $this->assertEquals( |
407 | $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), $linkDB[2]['updated']); | 415 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), |
416 | $linkDB[2]['created'] | ||
417 | ); | ||
418 | $this->assertEquals( | ||
419 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), | ||
420 | $linkDB[2]['updated'] | ||
421 | ); | ||
408 | } | 422 | } |
409 | 423 | ||
410 | /** | 424 | /** |
@@ -619,4 +633,175 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
619 | $this->assertTrue($updater->updateMethodAtomDefault()); | 633 | $this->assertTrue($updater->updateMethodAtomDefault()); |
620 | $this->assertTrue($this->conf->get('feed.show_atom')); | 634 | $this->assertTrue($this->conf->get('feed.show_atom')); |
621 | } | 635 | } |
636 | |||
637 | /** | ||
638 | * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined. | ||
639 | */ | ||
640 | public function testUpdateMethodDownloadSizeAndTimeoutConf() | ||
641 | { | ||
642 | $sandboxConf = 'sandbox/config'; | ||
643 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
644 | $this->conf = new ConfigManager($sandboxConf); | ||
645 | $updater = new Updater([], [], $this->conf, true); | ||
646 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
647 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
648 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
649 | |||
650 | $this->conf = new ConfigManager($sandboxConf); | ||
651 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
652 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
653 | } | ||
654 | |||
655 | /** | ||
656 | * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined. | ||
657 | */ | ||
658 | public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore() | ||
659 | { | ||
660 | $sandboxConf = 'sandbox/config'; | ||
661 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
662 | $this->conf = new ConfigManager($sandboxConf); | ||
663 | $this->conf->set('general.download_max_size', 38); | ||
664 | $this->conf->set('general.download_timeout', 70); | ||
665 | $updater = new Updater([], [], $this->conf, true); | ||
666 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
667 | $this->assertEquals(38, $this->conf->get('general.download_max_size')); | ||
668 | $this->assertEquals(70, $this->conf->get('general.download_timeout')); | ||
669 | } | ||
670 | |||
671 | /** | ||
672 | * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here. | ||
673 | */ | ||
674 | public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize() | ||
675 | { | ||
676 | $sandboxConf = 'sandbox/config'; | ||
677 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
678 | $this->conf = new ConfigManager($sandboxConf); | ||
679 | $this->conf->set('general.download_max_size', 38); | ||
680 | $updater = new Updater([], [], $this->conf, true); | ||
681 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
682 | $this->assertEquals(38, $this->conf->get('general.download_max_size')); | ||
683 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here. | ||
688 | */ | ||
689 | public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout() | ||
690 | { | ||
691 | $sandboxConf = 'sandbox/config'; | ||
692 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
693 | $this->conf = new ConfigManager($sandboxConf); | ||
694 | $this->conf->set('general.download_timeout', 3); | ||
695 | $updater = new Updater([], [], $this->conf, true); | ||
696 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
697 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
698 | $this->assertEquals(3, $this->conf->get('general.download_timeout')); | ||
699 | } | ||
700 | |||
701 | /** | ||
702 | <<<<<<< HEAD | ||
703 | * Test updateMethodWebThumbnailer with thumbnails enabled. | ||
704 | */ | ||
705 | public function testUpdateMethodWebThumbnailerEnabled() | ||
706 | { | ||
707 | $this->conf->remove('thumbnails'); | ||
708 | $this->conf->set('thumbnail.enable_thumbnails', true); | ||
709 | $updater = new Updater([], [], $this->conf, true, $_SESSION); | ||
710 | $this->assertTrue($updater->updateMethodWebThumbnailer()); | ||
711 | $this->assertFalse($this->conf->exists('thumbnail')); | ||
712 | $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode')); | ||
713 | $this->assertEquals(125, $this->conf->get('thumbnails.width')); | ||
714 | $this->assertEquals(90, $this->conf->get('thumbnails.height')); | ||
715 | $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]); | ||
716 | } | ||
717 | |||
718 | /** | ||
719 | * Test updateMethodWebThumbnailer with thumbnails disabled. | ||
720 | */ | ||
721 | public function testUpdateMethodWebThumbnailerDisabled() | ||
722 | { | ||
723 | $this->conf->remove('thumbnails'); | ||
724 | $this->conf->set('thumbnail.enable_thumbnails', false); | ||
725 | $updater = new Updater([], [], $this->conf, true, $_SESSION); | ||
726 | $this->assertTrue($updater->updateMethodWebThumbnailer()); | ||
727 | $this->assertFalse($this->conf->exists('thumbnail')); | ||
728 | $this->assertEquals(Thumbnailer::MODE_NONE, $this->conf->get('thumbnails.mode')); | ||
729 | $this->assertEquals(125, $this->conf->get('thumbnails.width')); | ||
730 | $this->assertEquals(90, $this->conf->get('thumbnails.height')); | ||
731 | $this->assertTrue(empty($_SESSION['warnings'])); | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * Test updateMethodWebThumbnailer with thumbnails disabled. | ||
736 | */ | ||
737 | public function testUpdateMethodWebThumbnailerNothingToDo() | ||
738 | { | ||
739 | $updater = new Updater([], [], $this->conf, true, $_SESSION); | ||
740 | $this->assertTrue($updater->updateMethodWebThumbnailer()); | ||
741 | $this->assertFalse($this->conf->exists('thumbnail')); | ||
742 | $this->assertEquals(Thumbnailer::MODE_COMMON, $this->conf->get('thumbnails.mode')); | ||
743 | $this->assertEquals(90, $this->conf->get('thumbnails.width')); | ||
744 | $this->assertEquals(53, $this->conf->get('thumbnails.height')); | ||
745 | $this->assertTrue(empty($_SESSION['warnings'])); | ||
746 | } | ||
747 | |||
748 | /** | ||
749 | * Test updateMethodSetSticky(). | ||
750 | */ | ||
751 | public function testUpdateStickyValid() | ||
752 | { | ||
753 | $blank = [ | ||
754 | 'id' => 1, | ||
755 | 'url' => 'z', | ||
756 | 'title' => '', | ||
757 | 'description' => '', | ||
758 | 'tags' => '', | ||
759 | 'created' => new DateTime(), | ||
760 | ]; | ||
761 | $links = [ | ||
762 | 1 => ['id' => 1] + $blank, | ||
763 | 2 => ['id' => 2] + $blank, | ||
764 | ]; | ||
765 | $refDB = new ReferenceLinkDB(); | ||
766 | $refDB->setLinks($links); | ||
767 | $refDB->write(self::$testDatastore); | ||
768 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
769 | |||
770 | $updater = new Updater(array(), $linkDB, $this->conf, true); | ||
771 | $this->assertTrue($updater->updateMethodSetSticky()); | ||
772 | |||
773 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
774 | foreach ($linkDB as $link) { | ||
775 | $this->assertFalse($link['sticky']); | ||
776 | } | ||
777 | } | ||
778 | |||
779 | /** | ||
780 | * Test updateMethodSetSticky(). | ||
781 | */ | ||
782 | public function testUpdateStickyNothingToDo() | ||
783 | { | ||
784 | $blank = [ | ||
785 | 'id' => 1, | ||
786 | 'url' => 'z', | ||
787 | 'title' => '', | ||
788 | 'description' => '', | ||
789 | 'tags' => '', | ||
790 | 'created' => new DateTime(), | ||
791 | ]; | ||
792 | $links = [ | ||
793 | 1 => ['id' => 1, 'sticky' => true] + $blank, | ||
794 | 2 => ['id' => 2] + $blank, | ||
795 | ]; | ||
796 | $refDB = new ReferenceLinkDB(); | ||
797 | $refDB->setLinks($links); | ||
798 | $refDB->write(self::$testDatastore); | ||
799 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
800 | |||
801 | $updater = new Updater(array(), $linkDB, $this->conf, true); | ||
802 | $this->assertTrue($updater->updateMethodSetSticky()); | ||
803 | |||
804 | $linkDB = new LinkDB(self::$testDatastore, true, false); | ||
805 | $this->assertTrue($linkDB[1]['sticky']); | ||
806 | } | ||
622 | } | 807 | } |