Update thumbnail integration after rebasing the branch

This commit is contained in:
ArthurHoaro 2017-11-11 14:01:21 +01:00
parent a3724717ec
commit e85b7a05a1
21 changed files with 453 additions and 210 deletions

View file

@ -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;
/**
* @var Thumbnailer;
*/
protected $thumbnailer;
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->thumbnailer = new Thumbnailer($conf);
// cache files in the sandbox
WTConfigManager::addFile('tests/utils/config/wt.json');
}
public function tearDown()
{
$this->rrmdirContent('sandbox/');
}
/**
* 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/');
$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);
}
}
}
}
}

View file

@ -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'));
}
}

View file

@ -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": []
}
}
*/ ?>
*/ ?>

View file

@ -0,0 +1,12 @@
{
"settings": {
"default": {
"_comment": "infinite cache",
"cache_duration": -1,
"timeout": 10
},
"path": {
"cache": "sandbox/"
}
}
}