aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-11-11 14:01:21 +0100
committerArthurHoaro <arthur@hoa.ro>2018-07-05 20:31:35 +0200
commite85b7a05a177f803ae36ba5c12835313f31177bc (patch)
tree99216fbcb3343b74eac2589d14bf75c0a6d5fb01 /tests
parenta3724717ec37d4bd54dc117ef439c8a182157882 (diff)
downloadShaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.tar.gz
Shaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.tar.zst
Shaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.zip
Update thumbnail integration after rebasing the branch
Diffstat (limited to 'tests')
-rw-r--r--tests/ThumbnailerTest.php64
-rw-r--r--tests/Updater/UpdaterTest.php15
-rw-r--r--tests/utils/config/configJson.json.php70
-rw-r--r--tests/utils/config/wt.json12
4 files changed, 134 insertions, 27 deletions
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 @@
1<?php 1<?php
2 2
3require_once 'application/Thumbnailer.php'; 3namespace Shaarli;
4require_once 'application/config/ConfigManager.php'; 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager;
7use WebThumbnailer\Application\ConfigManager as WTConfigManager;
5 8
6/** 9/**
7 * Class ThumbnailerTest 10 * Class ThumbnailerTest
@@ -11,31 +14,48 @@ require_once 'application/config/ConfigManager.php';
11 * 1. the thumbnailer library is itself tested 14 * 1. the thumbnailer library is itself tested
12 * 2. we don't want to make too many external requests during the tests 15 * 2. we don't want to make too many external requests during the tests
13 */ 16 */
14class ThumbnailerTest extends PHPUnit_Framework_TestCase 17class ThumbnailerTest extends TestCase
15{ 18{
19 const WIDTH = 190;
20
21 const HEIGHT = 210;
22
16 /** 23 /**
17 * Test a thumbnail with a custom size. 24 * @var Thumbnailer;
18 */ 25 */
19 public function testThumbnailValid() 26 protected $thumbnailer;
27
28 public function setUp()
20 { 29 {
21 $conf = new ConfigManager('tests/utils/config/configJson'); 30 $conf = new ConfigManager('tests/utils/config/configJson');
22 $width = 200; 31 $conf->set('thumbnails.width', self::WIDTH);
23 $height = 200; 32 $conf->set('thumbnails.height', self::HEIGHT);
24 $conf->set('thumbnails.width', $width); 33 $conf->set('dev.debug', true);
25 $conf->set('thumbnails.height', $height); 34
35 $this->thumbnailer = new Thumbnailer($conf);
36 // cache files in the sandbox
37 WTConfigManager::addFile('tests/utils/config/wt.json');
38 }
39
40 public function tearDown()
41 {
42 $this->rrmdirContent('sandbox/');
43 }
26 44
27 $thumbnailer = new Thumbnailer($conf); 45 /**
28 $thumb = $thumbnailer->get('https://github.com/shaarli/Shaarli/'); 46 * Test a thumbnail with a custom size.
47 */
48 public function testThumbnailValid()
49 {
50 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/');
29 $this->assertNotFalse($thumb); 51 $this->assertNotFalse($thumb);
30 $image = imagecreatefromstring(file_get_contents($thumb)); 52 $image = imagecreatefromstring(file_get_contents($thumb));
31 $this->assertEquals($width, imagesx($image)); 53 $this->assertEquals(self::WIDTH, imagesx($image));
32 $this->assertEquals($height, imagesy($image)); 54 $this->assertEquals(self::HEIGHT, imagesy($image));
33 } 55 }
34 56
35 /** 57 /**
36 * Test a thumbnail that can't be retrieved. 58 * Test a thumbnail that can't be retrieved.
37 *
38 * @expectedException WebThumbnailer\Exception\ThumbnailNotFoundException
39 */ 59 */
40 public function testThumbnailNotValid() 60 public function testThumbnailNotValid()
41 { 61 {
@@ -48,4 +68,18 @@ class ThumbnailerTest extends PHPUnit_Framework_TestCase
48 68
49 ini_set('error_log', $oldlog); 69 ini_set('error_log', $oldlog);
50 } 70 }
71
72 protected function rrmdirContent($dir) {
73 if (is_dir($dir)) {
74 $objects = scandir($dir);
75 foreach ($objects as $object) {
76 if ($object != "." && $object != "..") {
77 if (is_dir($dir."/".$object))
78 $this->rrmdirContent($dir."/".$object);
79 else
80 unlink($dir."/".$object);
81 }
82 }
83 }
84 }
51} 85}
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;';
684 $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); 684 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
685 $this->assertEquals(3, $this->conf->get('general.download_timeout')); 685 $this->assertEquals(3, $this->conf->get('general.download_timeout'));
686 } 686 }
687
688 /**
689 * Test updateMethodAtomDefault with show_atom set to true.
690 * => nothing to do
691 */
692 public function testUpdateMethodWebThumbnailerEnabled()
693 {
694 $this->conf->set('thumbnail.enable_thumbnails', true);
695 $updater = new Updater([], [], $this->conf, true);
696 $this->assertTrue($updater->updateMethodWebThumbnailer());
697 $this->assertFalse($this->conf->exists('thumbnail'));
698 $this->assertTrue($this->conf->get('thumbnails.enabled'));
699 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
700 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
701 }
687} 702}
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 @@
1<?php /* 1<?php /*
2{ 2{
3 "credentials": { 3 "credentials": {
4 "login":"root", 4 "login": "root",
5 "hash":"hash", 5 "hash": "hash",
6 "salt":"salt" 6 "salt": "salt"
7 }, 7 },
8 "security": { 8 "security": {
9 "session_protection_disabled":false 9 "session_protection_disabled": false,
10 "ban_after": 4,
11 "ban_duration": 1800,
12 "open_shaarli": false,
13 "allowed_protocols": [
14 "ftp",
15 "ftps",
16 "magnet"
17 ]
10 }, 18 },
11 "general": { 19 "general": {
12 "timezone":"Europe\/Paris", 20 "timezone": "Europe\/Paris",
13 "title": "Shaarli", 21 "title": "Shaarli",
14 "header_link": "?" 22 "header_link": "?",
23 "links_per_page": 20,
24 "enabled_plugins": [
25 "qrcode"
26 ],
27 "default_note_title": "Note: "
15 }, 28 },
16 "privacy": { 29 "privacy": {
17 "default_private_links":true 30 "default_private_links": true,
31 "hide_public_links": false,
32 "force_login": false,
33 "hide_timestamps": false,
34 "remember_user_default": true
18 }, 35 },
19 "redirector": { 36 "redirector": {
20 "url":"lala" 37 "url": "lala",
38 "encode_url": true
21 }, 39 },
22 "config": { 40 "config": {
23 "foo": "bar" 41 "foo": "bar"
24 }, 42 },
25 "resource": { 43 "resource": {
26 "datastore": "tests\/utils\/config\/datastore.php", 44 "datastore": "tests\/utils\/config\/datastore.php",
27 "data_dir": "sandbox/", 45 "data_dir": "sandbox\/",
28 "raintpl_tpl": "tpl/" 46 "raintpl_tpl": "tpl\/",
47 "config": "data\/config.php",
48 "ban_file": "data\/ipbans.php",
49 "updates": "data\/updates.txt",
50 "log": "data\/log.txt",
51 "update_check": "data\/lastupdatecheck.txt",
52 "history": "data\/history.php",
53 "theme": "default",
54 "raintpl_tmp": "tmp\/",
55 "thumbnails_cache": "cache",
56 "page_cache": "pagecache"
29 }, 57 },
30 "plugins": { 58 "plugins": {
31 "WALLABAG_VERSION": 1 59 "WALLABAG_VERSION": 1
32 }, 60 },
33 "dev": { 61 "dev": {
34 "debug": true 62 "debug": true
63 },
64 "thumbnails": {
65 "enabled": true,
66 "width": 125,
67 "height": 90
68 },
69 "updates": {
70 "check_updates": false,
71 "check_updates_branch": "stable",
72 "check_updates_interval": 86400
73 },
74 "feed": {
75 "rss_permalinks": true,
76 "show_atom": true
77 },
78 "translation": {
79 "language": "auto",
80 "mode": "php",
81 "extensions": []
35 } 82 }
36} 83}
37*/ ?> 84*/ ?> \ No newline at end of file
38
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 @@
1{
2 "settings": {
3 "default": {
4 "_comment": "infinite cache",
5 "cache_duration": -1,
6 "timeout": 10
7 },
8 "path": {
9 "cache": "sandbox/"
10 }
11 }
12} \ No newline at end of file