X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FThumbnailerTest.php;h=70519aca066892d04c6dee3c84a18db34ec536de;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=c04b8fb56021c5d18aa34528a24a60e15db51ea9;hpb=e85b7a05a177f803ae36ba5c12835313f31177bc;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index c04b8fb5..70519aca 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -2,7 +2,6 @@ namespace Shaarli; -use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use WebThumbnailer\Application\ConfigManager as WTConfigManager; @@ -25,27 +24,33 @@ class ThumbnailerTest extends TestCase */ protected $thumbnailer; - public function setUp() + /** + * @var ConfigManager + */ + protected $conf; + + protected function setUp(): void { - $conf = new ConfigManager('tests/utils/config/configJson'); - $conf->set('thumbnails.width', self::WIDTH); - $conf->set('thumbnails.height', self::HEIGHT); - $conf->set('dev.debug', true); + $this->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($conf); + $this->thumbnailer = new Thumbnailer($this->conf); // cache files in the sandbox WTConfigManager::addFile('tests/utils/config/wt.json'); } - public function tearDown() + protected function tearDown(): void { $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() { $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/'); $this->assertNotFalse($thumb); @@ -54,6 +59,29 @@ class ThumbnailerTest extends TestCase $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. */ @@ -69,15 +97,17 @@ class ThumbnailerTest extends TestCase ini_set('error_log', $oldlog); } - protected function rrmdirContent($dir) { + protected function rrmdirContent($dir) + { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { - if (is_dir($dir."/".$object)) + if (is_dir($dir."/".$object)) { $this->rrmdirContent($dir."/".$object); - else + } else { unlink($dir."/".$object); + } } } }