5 use Shaarli\Config\ConfigManager
;
6 use WebThumbnailer\Application\ConfigManager
as WTConfigManager
;
9 * Class ThumbnailerTest
11 * We only make 1 thumb test because:
13 * 1. the thumbnailer library is itself tested
14 * 2. we don't want to make too many external requests during the tests
16 class ThumbnailerTest
extends TestCase
25 protected $thumbnailer;
32 protected function setUp(): void
34 $this->conf
= new ConfigManager('tests/utils/config/configJson');
35 $this->conf
->set('thumbnails.mode', Thumbnailer
::MODE_ALL
);
36 $this->conf
->set('thumbnails.width', self
::WIDTH
);
37 $this->conf
->set('thumbnails.height', self
::HEIGHT
);
38 $this->conf
->set('dev.debug', true);
40 $this->thumbnailer
= new Thumbnailer($this->conf
);
41 // cache files in the sandbox
42 WTConfigManager
::addFile('tests/utils/config/wt.json');
45 protected function tearDown(): void
47 $this->rrmdirContent('sandbox/');
51 * Test a thumbnail with a custom size in 'all' mode.
53 public function testThumbnailAllValid()
55 $thumb = $this->thumbnailer
->get('https://github.com/shaarli/Shaarli/');
56 $this->assertNotFalse($thumb);
57 $image = imagecreatefromstring(file_get_contents($thumb));
58 $this->assertEquals(self
::WIDTH
, imagesx($image));
59 $this->assertEquals(self
::HEIGHT
, imagesy($image));
63 * Test a thumbnail with a custom size in 'common' mode.
65 public function testThumbnailCommonValid()
67 $this->conf
->set('thumbnails.mode', Thumbnailer
::MODE_COMMON
);
68 $thumb = $this->thumbnailer
->get('https://imgur.com/jlFgGpe');
69 $this->assertNotFalse($thumb);
70 $image = imagecreatefromstring(file_get_contents($thumb));
71 $this->assertEquals(self
::WIDTH
, imagesx($image));
72 $this->assertEquals(self
::HEIGHT
, imagesy($image));
76 * Test a thumbnail in 'common' mode which isn't include in common websites.
78 public function testThumbnailCommonInvalid()
80 $this->conf
->set('thumbnails.mode', Thumbnailer
::MODE_COMMON
);
81 $thumb = $this->thumbnailer
->get('https://github.com/shaarli/Shaarli/');
82 $this->assertFalse($thumb);
86 * Test a thumbnail that can't be retrieved.
88 public function testThumbnailNotValid()
90 $oldlog = ini_get('error_log');
91 ini_set('error_log', '/dev/null');
93 $thumbnailer = new Thumbnailer(new ConfigManager());
94 $thumb = $thumbnailer->get('nope');
95 $this->assertFalse($thumb);
97 ini_set('error_log', $oldlog);
100 protected function rrmdirContent($dir)
103 $objects = scandir($dir);
104 foreach ($objects as $object) {
105 if ($object != "." && $object != "..") {
106 if (is_dir($dir."/".$object)) {
107 $this->rrmdirContent($dir."/".$object);
109 unlink($dir."/".$object);