X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FThumbnailerTest.php;h=c01849f7f089e45e1ca17af6dcb0ee0a3c2e5daf;hb=1004742f09b55ff781c13745781b9a7e90986faa;hp=db10932114a6f9f078ed99407a2b8273f3dee047;hpb=1b93137e16694f52952c930848e1a7928e8a00a6;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index db109321..c01849f7 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -1,7 +1,10 @@ conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL); + $this->conf->set('thumbnails.width', self::WIDTH); + $this->conf->set('thumbnails.height', self::HEIGHT); + $this->conf->set('dev.debug', true); + + $this->thumbnailer = new Thumbnailer($this->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. + * Test a thumbnail with a custom size in 'all' mode. */ - public function testThumbnailValid() + public function testThumbnailAllValid() { - $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 with a custom size in 'common' mode. + */ + public function testThumbnailCommonValid() + { + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON); + $thumb = $this->thumbnailer->get('https://imgur.com/jlFgGpe'); + $this->assertNotFalse($thumb); + $image = imagecreatefromstring(file_get_contents($thumb)); + $this->assertEquals(self::WIDTH, imagesx($image)); + $this->assertEquals(self::HEIGHT, imagesy($image)); + } + + /** + * Test a thumbnail in 'common' mode which isn't include in common websites. + */ + public function testThumbnailCommonInvalid() + { + $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON); + $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); + $this->assertFalse($thumb); } /** * Test a thumbnail that can't be retrieved. - * - * @expectedException WebThumbnailer\Exception\ThumbnailNotFoundException */ public function testThumbnailNotValid() { @@ -48,4 +97,20 @@ 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); + } + } + } + } + } }