aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ThumbnailerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ThumbnailerTest.php')
-rw-r--r--tests/ThumbnailerTest.php64
1 files changed, 49 insertions, 15 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}