From f41a38ba1510e65be675834aefe5b57368b119dd Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 25 Sep 2015 16:00:05 +0200 Subject: Cover both width and height for the sidebar preview --- tests/lib/preview.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/lib/preview.php') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 9e118014bac..a135ed40d0a 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -874,4 +874,45 @@ class Preview extends TestCase { return [(int)$askedWidth, (int)$askedHeight]; } + + public function testKeepAspectRatio() { + $originalWidth = 1680; + $originalHeight = 1050; + $originalAspectRation = $originalWidth / $originalHeight; + + $preview = new \OC\Preview( + self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', + 150, + 150 + ); + $preview->setKeepAspect(true); + $image = $preview->getPreview(); + + $aspectRatio = $image->width() / $image->height(); + $this->assertEquals(round($originalAspectRation, 2), round($aspectRatio, 2)); + + $this->assertLessThanOrEqual(150, $image->width()); + $this->assertLessThanOrEqual(150, $image->height()); + } + + public function testKeepAspectRatioCover() { + $originalWidth = 1680; + $originalHeight = 1050; + $originalAspectRation = $originalWidth / $originalHeight; + + $preview = new \OC\Preview( + self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', + 150, + 150 + ); + $preview->setKeepAspect(true); + $preview->setMode(\OC\Preview::MODE_COVER); + $image = $preview->getPreview(); + + $aspectRatio = $image->width() / $image->height(); + $this->assertEquals(round($originalAspectRation, 2), round($aspectRatio, 2)); + + $this->assertGreaterThanOrEqual(150, $image->width()); + $this->assertGreaterThanOrEqual(150, $image->height()); + } } -- cgit v1.2.3