From 1b93137e16694f52952c930848e1a7928e8a00a6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Wed, 9 Nov 2016 18:57:02 +0100 Subject: Use web-thumbnailer to retrieve thumbnails * requires PHP 5.6 * use blazy on linklist since a lot more thumbs are retrieved * thumbnails can be disabled * thumbs size is now 120x120 * thumbs are now cropped to fit the expected size Fixes #345 #425 #487 #543 #588 #590 --- tests/ThumbnailerTest.php | 51 ++++++++++++++++++++++++++++++++++ tests/utils/config/configJson.json.php | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 tests/ThumbnailerTest.php (limited to 'tests') diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php new file mode 100644 index 00000000..db109321 --- /dev/null +++ b/tests/ThumbnailerTest.php @@ -0,0 +1,51 @@ +<?php + +require_once 'application/Thumbnailer.php'; +require_once 'application/config/ConfigManager.php'; + +/** + * Class ThumbnailerTest + * + * We only make 1 thumb test because: + * + * 1. the thumbnailer library is itself tested + * 2. we don't want to make too many external requests during the tests + */ +class ThumbnailerTest extends PHPUnit_Framework_TestCase +{ + /** + * Test a thumbnail with a custom size. + */ + public function testThumbnailValid() + { + $conf = new ConfigManager('tests/utils/config/configJson'); + $width = 200; + $height = 200; + $conf->set('thumbnails.width', $width); + $conf->set('thumbnails.height', $height); + + $thumbnailer = new Thumbnailer($conf); + $thumb = $thumbnailer->get('https://github.com/shaarli/Shaarli/'); + $this->assertNotFalse($thumb); + $image = imagecreatefromstring(file_get_contents($thumb)); + $this->assertEquals($width, imagesx($image)); + $this->assertEquals($height, imagesy($image)); + } + + /** + * Test a thumbnail that can't be retrieved. + * + * @expectedException WebThumbnailer\Exception\ThumbnailNotFoundException + */ + public function testThumbnailNotValid() + { + $oldlog = ini_get('error_log'); + ini_set('error_log', '/dev/null'); + + $thumbnailer = new Thumbnailer(new ConfigManager()); + $thumb = $thumbnailer->get('nope'); + $this->assertFalse($thumb); + + ini_set('error_log', $oldlog); + } +} diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 9c9288f3..3101b225 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -29,6 +29,9 @@ }, "plugins": { "WALLABAG_VERSION": 1 + }, + "dev": { + "debug": true } } */ ?> -- cgit v1.2.3 From a3724717ec37d4bd54dc117ef439c8a182157882 Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Sat, 11 Nov 2017 14:00:18 +0100 Subject: ConfigManager: add a method to remove an entry --- tests/config/ConfigManagerTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 1ec447b2..4a4e94ac 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -81,6 +81,18 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); } + public function testSetDeleteNested() + { + $this->conf->set('foo.bar.key.stuff', 'testSetDeleteNested'); + $this->assertTrue($this->conf->exists('foo.bar')); + $this->assertTrue($this->conf->exists('foo.bar.key.stuff')); + $this->assertEquals('testSetDeleteNested', $this->conf->get('foo.bar.key.stuff')); + + $this->conf->remove('foo.bar'); + $this->assertFalse($this->conf->exists('foo.bar.key.stuff')); + $this->assertFalse($this->conf->exists('foo.bar')); + } + /** * Set with an empty key. * @@ -103,6 +115,17 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase $this->conf->set(array('foo' => 'bar'), 'stuff'); } + /** + * Remove with an empty key. + * + * @expectedException \Exception + * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# + */ + public function testRmoveEmptyKey() + { + $this->conf->remove(''); + } + /** * Try to write the config without mandatory parameter (e.g. 'login'). * -- cgit v1.2.3 From e85b7a05a177f803ae36ba5c12835313f31177bc Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Sat, 11 Nov 2017 14:01:21 +0100 Subject: Update thumbnail integration after rebasing the branch --- tests/ThumbnailerTest.php | 64 +++++++++++++++++++++++-------- tests/Updater/UpdaterTest.php | 15 ++++++++ tests/utils/config/configJson.json.php | 70 ++++++++++++++++++++++++++++------ tests/utils/config/wt.json | 12 ++++++ 4 files changed, 134 insertions(+), 27 deletions(-) create mode 100644 tests/utils/config/wt.json (limited to 'tests') diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index db109321..c04b8fb5 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -1,7 +1,10 @@ <?php -require_once 'application/Thumbnailer.php'; -require_once 'application/config/ConfigManager.php'; +namespace Shaarli; + +use PHPUnit\Framework\TestCase; +use Shaarli\Config\ConfigManager; +use WebThumbnailer\Application\ConfigManager as WTConfigManager; /** * Class ThumbnailerTest @@ -11,31 +14,48 @@ require_once 'application/config/ConfigManager.php'; * 1. the thumbnailer library is itself tested * 2. we don't want to make too many external requests during the tests */ -class ThumbnailerTest extends PHPUnit_Framework_TestCase +class ThumbnailerTest extends TestCase { + const WIDTH = 190; + + const HEIGHT = 210; + /** - * Test a thumbnail with a custom size. + * @var Thumbnailer; */ - public function testThumbnailValid() + protected $thumbnailer; + + public function setUp() { $conf = new ConfigManager('tests/utils/config/configJson'); - $width = 200; - $height = 200; - $conf->set('thumbnails.width', $width); - $conf->set('thumbnails.height', $height); + $conf->set('thumbnails.width', self::WIDTH); + $conf->set('thumbnails.height', self::HEIGHT); + $conf->set('dev.debug', true); + + $this->thumbnailer = new Thumbnailer($conf); + // cache files in the sandbox + WTConfigManager::addFile('tests/utils/config/wt.json'); + } + + public function tearDown() + { + $this->rrmdirContent('sandbox/'); + } - $thumbnailer = new Thumbnailer($conf); - $thumb = $thumbnailer->get('https://github.com/shaarli/Shaarli/'); + /** + * Test a thumbnail with a custom size. + */ + public function testThumbnailValid() + { + $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); $this->assertNotFalse($thumb); $image = imagecreatefromstring(file_get_contents($thumb)); - $this->assertEquals($width, imagesx($image)); - $this->assertEquals($height, imagesy($image)); + $this->assertEquals(self::WIDTH, imagesx($image)); + $this->assertEquals(self::HEIGHT, imagesy($image)); } /** * Test a thumbnail that can't be retrieved. - * - * @expectedException WebThumbnailer\Exception\ThumbnailNotFoundException */ public function testThumbnailNotValid() { @@ -48,4 +68,18 @@ class ThumbnailerTest extends PHPUnit_Framework_TestCase ini_set('error_log', $oldlog); } + + protected function rrmdirContent($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (is_dir($dir."/".$object)) + $this->rrmdirContent($dir."/".$object); + else + unlink($dir."/".$object); + } + } + } + } } diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 94e3c7d3..8b90fd5e 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -684,4 +684,19 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); $this->assertEquals(3, $this->conf->get('general.download_timeout')); } + + /** + * Test updateMethodAtomDefault with show_atom set to true. + * => nothing to do + */ + public function testUpdateMethodWebThumbnailerEnabled() + { + $this->conf->set('thumbnail.enable_thumbnails', true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodWebThumbnailer()); + $this->assertFalse($this->conf->exists('thumbnail')); + $this->assertTrue($this->conf->get('thumbnails.enabled')); + $this->assertEquals(125, $this->conf->get('thumbnails.width')); + $this->assertEquals(90, $this->conf->get('thumbnails.height')); + } } diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 3101b225..061d4c28 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -1,38 +1,84 @@ <?php /* { "credentials": { - "login":"root", - "hash":"hash", - "salt":"salt" + "login": "root", + "hash": "hash", + "salt": "salt" }, "security": { - "session_protection_disabled":false + "session_protection_disabled": false, + "ban_after": 4, + "ban_duration": 1800, + "open_shaarli": false, + "allowed_protocols": [ + "ftp", + "ftps", + "magnet" + ] }, "general": { - "timezone":"Europe\/Paris", + "timezone": "Europe\/Paris", "title": "Shaarli", - "header_link": "?" + "header_link": "?", + "links_per_page": 20, + "enabled_plugins": [ + "qrcode" + ], + "default_note_title": "Note: " }, "privacy": { - "default_private_links":true + "default_private_links": true, + "hide_public_links": false, + "force_login": false, + "hide_timestamps": false, + "remember_user_default": true }, "redirector": { - "url":"lala" + "url": "lala", + "encode_url": true }, "config": { "foo": "bar" }, "resource": { "datastore": "tests\/utils\/config\/datastore.php", - "data_dir": "sandbox/", - "raintpl_tpl": "tpl/" + "data_dir": "sandbox\/", + "raintpl_tpl": "tpl\/", + "config": "data\/config.php", + "ban_file": "data\/ipbans.php", + "updates": "data\/updates.txt", + "log": "data\/log.txt", + "update_check": "data\/lastupdatecheck.txt", + "history": "data\/history.php", + "theme": "default", + "raintpl_tmp": "tmp\/", + "thumbnails_cache": "cache", + "page_cache": "pagecache" }, "plugins": { "WALLABAG_VERSION": 1 }, "dev": { "debug": true + }, + "thumbnails": { + "enabled": true, + "width": 125, + "height": 90 + }, + "updates": { + "check_updates": false, + "check_updates_branch": "stable", + "check_updates_interval": 86400 + }, + "feed": { + "rss_permalinks": true, + "show_atom": true + }, + "translation": { + "language": "auto", + "mode": "php", + "extensions": [] } } -*/ ?> - +*/ ?> \ No newline at end of file diff --git a/tests/utils/config/wt.json b/tests/utils/config/wt.json new file mode 100644 index 00000000..69ce49a6 --- /dev/null +++ b/tests/utils/config/wt.json @@ -0,0 +1,12 @@ +{ + "settings": { + "default": { + "_comment": "infinite cache", + "cache_duration": -1, + "timeout": 10 + }, + "path": { + "cache": "sandbox/" + } + } +} \ No newline at end of file -- cgit v1.2.3 From 28f26524609338316cc6e51c743058e6e8c7b12b Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Fri, 8 Jun 2018 12:50:49 +0200 Subject: Add a page to update all thumbnails through AJAX requests in both templates --- tests/Updater/UpdaterTest.php | 40 ++++++++++++++++++++++++++++++---- tests/utils/config/configJson.json.php | 12 +++++----- 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 8b90fd5e..92ff5690 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -20,7 +20,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase /** * @var string Config file path (without extension). */ - protected static $configFile = 'tests/utils/config/configJson'; + protected static $configFile = 'sandbox/config'; /** * @var ConfigManager @@ -32,6 +32,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase */ public function setUp() { + copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); $this->conf = new ConfigManager(self::$configFile); } @@ -686,17 +687,48 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; } /** - * Test updateMethodAtomDefault with show_atom set to true. - * => nothing to do + * Test updateMethodWebThumbnailer with thumbnails enabled. */ public function testUpdateMethodWebThumbnailerEnabled() { + $this->conf->remove('thumbnails'); $this->conf->set('thumbnail.enable_thumbnails', true); - $updater = new Updater([], [], $this->conf, true); + $updater = new Updater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); $this->assertTrue($this->conf->get('thumbnails.enabled')); $this->assertEquals(125, $this->conf->get('thumbnails.width')); $this->assertEquals(90, $this->conf->get('thumbnails.height')); + $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]); + } + + /** + * Test updateMethodWebThumbnailer with thumbnails disabled. + */ + public function testUpdateMethodWebThumbnailerDisabled() + { + $this->conf->remove('thumbnails'); + $this->conf->set('thumbnail.enable_thumbnails', false); + $updater = new Updater([], [], $this->conf, true, $_SESSION); + $this->assertTrue($updater->updateMethodWebThumbnailer()); + $this->assertFalse($this->conf->exists('thumbnail')); + $this->assertFalse($this->conf->get('thumbnails.enabled')); + $this->assertEquals(125, $this->conf->get('thumbnails.width')); + $this->assertEquals(90, $this->conf->get('thumbnails.height')); + $this->assertTrue(empty($_SESSION['warnings'])); + } + + /** + * Test updateMethodWebThumbnailer with thumbnails disabled. + */ + public function testUpdateMethodWebThumbnailerNothingToDo() + { + $updater = new Updater([], [], $this->conf, true, $_SESSION); + $this->assertTrue($updater->updateMethodWebThumbnailer()); + $this->assertFalse($this->conf->exists('thumbnail')); + $this->assertTrue($this->conf->get('thumbnails.enabled')); + $this->assertEquals(90, $this->conf->get('thumbnails.width')); + $this->assertEquals(53, $this->conf->get('thumbnails.height')); + $this->assertTrue(empty($_SESSION['warnings'])); } } diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 061d4c28..a656b67c 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -61,11 +61,6 @@ "dev": { "debug": true }, - "thumbnails": { - "enabled": true, - "width": 125, - "height": 90 - }, "updates": { "check_updates": false, "check_updates_branch": "stable", @@ -79,6 +74,11 @@ "language": "auto", "mode": "php", "extensions": [] + }, + "thumbnails": { + "enabled": true, + "width": 90, + "height": 53 } } -*/ ?> \ No newline at end of file +*/ ?> -- cgit v1.2.3 From b302b3c584b84f22f0e6f187b072180ecbacdfab Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Thu, 5 Jul 2018 20:29:55 +0200 Subject: Thumbnails: add a common mode to only retrieve thumbs from popular media websites --- tests/ThumbnailerTest.php | 43 ++++++++++++++++++++++++++++------ tests/Updater/UpdaterTest.php | 7 +++--- tests/utils/config/configJson.json.php | 2 +- 3 files changed, 41 insertions(+), 11 deletions(-) (limited to 'tests') 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 */ protected $thumbnailer; + /** + * @var ConfigManager + */ + protected $conf; + public function setUp() { - $conf = new ConfigManager('tests/utils/config/configJson'); - $conf->set('thumbnails.width', self::WIDTH); - $conf->set('thumbnails.height', self::HEIGHT); - $conf->set('dev.debug', true); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL); + $this->conf->set('thumbnails.width', self::WIDTH); + $this->conf->set('thumbnails.height', self::HEIGHT); + $this->conf->set('dev.debug', true); - $this->thumbnailer = new Thumbnailer($conf); + $this->thumbnailer = new Thumbnailer($this->conf); // cache files in the sandbox WTConfigManager::addFile('tests/utils/config/wt.json'); } @@ -43,9 +49,9 @@ class ThumbnailerTest extends TestCase } /** - * Test a thumbnail with a custom size. + * Test a thumbnail with a custom size in 'all' mode. */ - public function testThumbnailValid() + public function testThumbnailAllValid() { $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); $this->assertNotFalse($thumb); @@ -54,6 +60,29 @@ class ThumbnailerTest extends TestCase $this->assertEquals(self::HEIGHT, imagesy($image)); } + /** + * Test a thumbnail with a custom size in 'common' mode. + */ + public function testThumbnailCommonValid() + { + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON); + $thumb = $this->thumbnailer->get('https://imgur.com/jlFgGpe'); + $this->assertNotFalse($thumb); + $image = imagecreatefromstring(file_get_contents($thumb)); + $this->assertEquals(self::WIDTH, imagesx($image)); + $this->assertEquals(self::HEIGHT, imagesy($image)); + } + + /** + * Test a thumbnail in 'common' mode which isn't include in common websites. + */ + public function testThumbnailCommonInvalid() + { + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON); + $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); + $this->assertFalse($thumb); + } + /** * Test a thumbnail that can't be retrieved. */ 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 @@ use Shaarli\Config\ConfigJson; use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigPhp; +use Shaarli\Thumbnailer; require_once 'tests/Updater/DummyUpdater.php'; require_once 'inc/rain.tpl.class.php'; @@ -696,7 +697,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $updater = new Updater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); - $this->assertTrue($this->conf->get('thumbnails.enabled')); + $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode')); $this->assertEquals(125, $this->conf->get('thumbnails.width')); $this->assertEquals(90, $this->conf->get('thumbnails.height')); $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]); @@ -712,7 +713,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $updater = new Updater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); - $this->assertFalse($this->conf->get('thumbnails.enabled')); + $this->assertEquals(Thumbnailer::MODE_NONE, $this->conf->get('thumbnails.mode')); $this->assertEquals(125, $this->conf->get('thumbnails.width')); $this->assertEquals(90, $this->conf->get('thumbnails.height')); $this->assertTrue(empty($_SESSION['warnings'])); @@ -726,7 +727,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $updater = new Updater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); - $this->assertTrue($this->conf->get('thumbnails.enabled')); + $this->assertEquals(Thumbnailer::MODE_COMMON, $this->conf->get('thumbnails.mode')); $this->assertEquals(90, $this->conf->get('thumbnails.width')); $this->assertEquals(53, $this->conf->get('thumbnails.height')); $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 @@ "extensions": [] }, "thumbnails": { - "enabled": true, + "mode": "common", "width": 90, "height": 53 } -- cgit v1.2.3 From 7b4fea0e39be9e74e9aef13e73af9bbd2b1a6397 Mon Sep 17 00:00:00 2001 From: ArthurHoaro <arthur@hoa.ro> Date: Tue, 17 Jul 2018 13:13:26 +0200 Subject: Bunch of improvement for thumbnails integration: - add a default thumb size value (125x90px) - improve private vertical bar visual, especially with thumbnails - translations - add a sync thumbs button in tool and empty picwall page - fixes WT download mode in JSON config --- tests/Updater/UpdaterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 05f4b8e1..cacee2d2 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -700,7 +700,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode')); $this->assertEquals(125, $this->conf->get('thumbnails.width')); $this->assertEquals(90, $this->conf->get('thumbnails.height')); - $this->assertContains('You have enabled thumbnails', $_SESSION['warnings'][0]); + $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]); } /** -- cgit v1.2.3