]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/ThumbnailerTest.php
Thumbnails: add a common mode to only retrieve thumbs from popular media websites
[github/shaarli/Shaarli.git] / tests / ThumbnailerTest.php
index c04b8fb56021c5d18aa34528a24a60e15db51ea9..08311545ef3b597f19d124aa7e6dc7286b69ae1d 100644 (file)
@@ -25,14 +25,20 @@ class ThumbnailerTest extends TestCase
      */
     protected $thumbnailer;
 
+    /**
+     * @var ConfigManager
+     */
+    protected $conf;
+
     public function setUp()
     {
-        $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');
     }
@@ -43,9 +49,9 @@ class ThumbnailerTest extends TestCase
     }
 
     /**
-     * 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 +60,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.
      */