]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/ThumbnailerTest.php
Use web-thumbnailer to retrieve thumbnails
[github/shaarli/Shaarli.git] / tests / ThumbnailerTest.php
1 <?php
2
3 require_once 'application/Thumbnailer.php';
4 require_once 'application/config/ConfigManager.php';
5
6 /**
7 * Class ThumbnailerTest
8 *
9 * We only make 1 thumb test because:
10 *
11 * 1. the thumbnailer library is itself tested
12 * 2. we don't want to make too many external requests during the tests
13 */
14 class ThumbnailerTest extends PHPUnit_Framework_TestCase
15 {
16 /**
17 * Test a thumbnail with a custom size.
18 */
19 public function testThumbnailValid()
20 {
21 $conf = new ConfigManager('tests/utils/config/configJson');
22 $width = 200;
23 $height = 200;
24 $conf->set('thumbnails.width', $width);
25 $conf->set('thumbnails.height', $height);
26
27 $thumbnailer = new Thumbnailer($conf);
28 $thumb = $thumbnailer->get('https://github.com/shaarli/Shaarli/');
29 $this->assertNotFalse($thumb);
30 $image = imagecreatefromstring(file_get_contents($thumb));
31 $this->assertEquals($width, imagesx($image));
32 $this->assertEquals($height, imagesy($image));
33 }
34
35 /**
36 * Test a thumbnail that can't be retrieved.
37 *
38 * @expectedException WebThumbnailer\Exception\ThumbnailNotFoundException
39 */
40 public function testThumbnailNotValid()
41 {
42 $oldlog = ini_get('error_log');
43 ini_set('error_log', '/dev/null');
44
45 $thumbnailer = new Thumbnailer(new ConfigManager());
46 $thumb = $thumbnailer->get('nope');
47 $this->assertFalse($thumb);
48
49 ini_set('error_log', $oldlog);
50 }
51 }