5 use PHPUnit\Framework\TestCase
;
6 use Shaarli\Config\ConfigManager
;
7 use WebThumbnailer\Application\ConfigManager
as WTConfigManager
;
10 * Class ThumbnailerTest
12 * We only make 1 thumb test because:
14 * 1. the thumbnailer library is itself tested
15 * 2. we don't want to make too many external requests during the tests
17 class ThumbnailerTest
extends TestCase
26 protected $thumbnailer;
28 public function setUp()
30 $conf = new ConfigManager('tests/utils/config/configJson');
31 $conf->set('thumbnails.width', self
::WIDTH
);
32 $conf->set('thumbnails.height', self
::HEIGHT
);
33 $conf->set('dev.debug', true);
35 $this->thumbnailer
= new Thumbnailer($conf);
36 // cache files in the sandbox
37 WTConfigManager
::addFile('tests/utils/config/wt.json');
40 public function tearDown()
42 $this->rrmdirContent('sandbox/');
46 * Test a thumbnail with a custom size.
48 public function testThumbnailValid()
50 $thumb = $this->thumbnailer
->get('https://github.com/shaarli/Shaarli/');
51 $this->assertNotFalse($thumb);
52 $image = imagecreatefromstring(file_get_contents($thumb));
53 $this->assertEquals(self
::WIDTH
, imagesx($image));
54 $this->assertEquals(self
::HEIGHT
, imagesy($image));
58 * Test a thumbnail that can't be retrieved.
60 public function testThumbnailNotValid()
62 $oldlog = ini_get('error_log');
63 ini_set('error_log', '/dev/null');
65 $thumbnailer = new Thumbnailer(new ConfigManager());
66 $thumb = $thumbnailer->get('nope');
67 $this->assertFalse($thumb);
69 ini_set('error_log', $oldlog);
72 protected function rrmdirContent($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);
80 unlink($dir."/".$object);