aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-07-05 20:29:55 +0200
committerArthurHoaro <arthur@hoa.ro>2018-07-05 20:34:22 +0200
commitb302b3c584b84f22f0e6f187b072180ecbacdfab (patch)
tree297f72d8fcf6d158ebbb8198dee4e35a30ab0d7e /tests
parentfcba541e2f12c85ac56c6915ba1319fbdd3e6962 (diff)
downloadShaarli-b302b3c584b84f22f0e6f187b072180ecbacdfab.tar.gz
Shaarli-b302b3c584b84f22f0e6f187b072180ecbacdfab.tar.zst
Shaarli-b302b3c584b84f22f0e6f187b072180ecbacdfab.zip
Thumbnails: add a common mode to only retrieve thumbs from popular media websites
Diffstat (limited to 'tests')
-rw-r--r--tests/ThumbnailerTest.php43
-rw-r--r--tests/Updater/UpdaterTest.php7
-rw-r--r--tests/utils/config/configJson.json.php2
3 files changed, 41 insertions, 11 deletions
diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php
index c04b8fb5..08311545 100644
--- a/tests/ThumbnailerTest.php
+++ b/tests/ThumbnailerTest.php
@@ -25,14 +25,20 @@ class ThumbnailerTest extends TestCase
25 */ 25 */
26 protected $thumbnailer; 26 protected $thumbnailer;
27 27
28 /**
29 * @var ConfigManager
30 */
31 protected $conf;
32
28 public function setUp() 33 public function setUp()
29 { 34 {
30 $conf = new ConfigManager('tests/utils/config/configJson'); 35 $this->conf = new ConfigManager('tests/utils/config/configJson');
31 $conf->set('thumbnails.width', self::WIDTH); 36 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL);
32 $conf->set('thumbnails.height', self::HEIGHT); 37 $this->conf->set('thumbnails.width', self::WIDTH);
33 $conf->set('dev.debug', true); 38 $this->conf->set('thumbnails.height', self::HEIGHT);
39 $this->conf->set('dev.debug', true);
34 40
35 $this->thumbnailer = new Thumbnailer($conf); 41 $this->thumbnailer = new Thumbnailer($this->conf);
36 // cache files in the sandbox 42 // cache files in the sandbox
37 WTConfigManager::addFile('tests/utils/config/wt.json'); 43 WTConfigManager::addFile('tests/utils/config/wt.json');
38 } 44 }
@@ -43,9 +49,9 @@ class ThumbnailerTest extends TestCase
43 } 49 }
44 50
45 /** 51 /**
46 * Test a thumbnail with a custom size. 52 * Test a thumbnail with a custom size in 'all' mode.
47 */ 53 */
48 public function testThumbnailValid() 54 public function testThumbnailAllValid()
49 { 55 {
50 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); 56 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/');
51 $this->assertNotFalse($thumb); 57 $this->assertNotFalse($thumb);
@@ -55,6 +61,29 @@ class ThumbnailerTest extends TestCase
55 } 61 }
56 62
57 /** 63 /**
64 * Test a thumbnail with a custom size in 'common' mode.
65 */
66 public function testThumbnailCommonValid()
67 {
68 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON);
69 $thumb = $this->thumbnailer->get('https://imgur.com/jlFgGpe');
70 $this->assertNotFalse($thumb);
71 $image = imagecreatefromstring(file_get_contents($thumb));
72 $this->assertEquals(self::WIDTH, imagesx($image));
73 $this->assertEquals(self::HEIGHT, imagesy($image));
74 }
75
76 /**
77 * Test a thumbnail in 'common' mode which isn't include in common websites.
78 */
79 public function testThumbnailCommonInvalid()
80 {
81 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON);
82 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/');
83 $this->assertFalse($thumb);
84 }
85
86 /**
58 * Test a thumbnail that can't be retrieved. 87 * Test a thumbnail that can't be retrieved.
59 */ 88 */
60 public function testThumbnailNotValid() 89 public function testThumbnailNotValid()
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index 92ff5690..05f4b8e1 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';
@@ -696,7 +697,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
696 $updater = new Updater([], [], $this->conf, true, $_SESSION); 697 $updater = new Updater([], [], $this->conf, true, $_SESSION);
697 $this->assertTrue($updater->updateMethodWebThumbnailer()); 698 $this->assertTrue($updater->updateMethodWebThumbnailer());
698 $this->assertFalse($this->conf->exists('thumbnail')); 699 $this->assertFalse($this->conf->exists('thumbnail'));
699 $this->assertTrue($this->conf->get('thumbnails.enabled')); 700 $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode'));
700 $this->assertEquals(125, $this->conf->get('thumbnails.width')); 701 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
701 $this->assertEquals(90, $this->conf->get('thumbnails.height')); 702 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
702 $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]); 703 $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]);
@@ -712,7 +713,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
712 $updater = new Updater([], [], $this->conf, true, $_SESSION); 713 $updater = new Updater([], [], $this->conf, true, $_SESSION);
713 $this->assertTrue($updater->updateMethodWebThumbnailer()); 714 $this->assertTrue($updater->updateMethodWebThumbnailer());
714 $this->assertFalse($this->conf->exists('thumbnail')); 715 $this->assertFalse($this->conf->exists('thumbnail'));
715 $this->assertFalse($this->conf->get('thumbnails.enabled')); 716 $this->assertEquals(Thumbnailer::MODE_NONE, $this->conf->get('thumbnails.mode'));
716 $this->assertEquals(125, $this->conf->get('thumbnails.width')); 717 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
717 $this->assertEquals(90, $this->conf->get('thumbnails.height')); 718 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
718 $this->assertTrue(empty($_SESSION['warnings'])); 719 $this->assertTrue(empty($_SESSION['warnings']));
@@ -726,7 +727,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
726 $updater = new Updater([], [], $this->conf, true, $_SESSION); 727 $updater = new Updater([], [], $this->conf, true, $_SESSION);
727 $this->assertTrue($updater->updateMethodWebThumbnailer()); 728 $this->assertTrue($updater->updateMethodWebThumbnailer());
728 $this->assertFalse($this->conf->exists('thumbnail')); 729 $this->assertFalse($this->conf->exists('thumbnail'));
729 $this->assertTrue($this->conf->get('thumbnails.enabled')); 730 $this->assertEquals(Thumbnailer::MODE_COMMON, $this->conf->get('thumbnails.mode'));
730 $this->assertEquals(90, $this->conf->get('thumbnails.width')); 731 $this->assertEquals(90, $this->conf->get('thumbnails.width'));
731 $this->assertEquals(53, $this->conf->get('thumbnails.height')); 732 $this->assertEquals(53, $this->conf->get('thumbnails.height'));
732 $this->assertTrue(empty($_SESSION['warnings'])); 733 $this->assertTrue(empty($_SESSION['warnings']));
diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php
index a656b67c..1549ddfc 100644
--- a/tests/utils/config/configJson.json.php
+++ b/tests/utils/config/configJson.json.php
@@ -76,7 +76,7 @@
76 "extensions": [] 76 "extensions": []
77 }, 77 },
78 "thumbnails": { 78 "thumbnails": {
79 "enabled": true, 79 "mode": "common",
80 "width": 90, 80 "width": 90,
81 "height": 53 81 "height": 53
82 } 82 }