diff options
author | Olivier Paroz <github@oparoz.com> | 2015-04-07 16:45:16 +0200 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-04-07 16:45:59 +0200 |
commit | 74bf9806b0fd17c82a5d3048d03a8dc735a2ce04 (patch) | |
tree | b3ac9346a0d6c3ec30edc5e99cccd9c6598be655 /tests/lib/preview.php | |
parent | 2182ae0d278f466e7f117b03bf4ebca0e6e9fe9b (diff) | |
download | nextcloud-server-74bf9806b0fd17c82a5d3048d03a8dc735a2ce04.tar.gz nextcloud-server-74bf9806b0fd17c82a5d3048d03a8dc735a2ce04.zip |
Introducing the maximum size preview
The first time we're asked to generate a preview we'll generate one of the maximum dimension indicated in the configuration and all future resizing requests will be done on that preview in order to not waste time converting the same file over and over.
One of the fixes required for #12465
Diffstat (limited to 'tests/lib/preview.php')
-rw-r--r-- | tests/lib/preview.php | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 2a6761403f4..003ecedb65a 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -48,6 +48,77 @@ class Preview extends TestCase { parent::tearDown(); } + public function testIsMaxSizeWorking() { + // Max size from config + $maxX = 1024; + $maxY = 1024; + + \OC::$server->getConfig()->setSystemValue('preview_max_x', $maxX); + \OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY); + + // Sample is 1680x1050 JPEG + $sampleFile = '/' . $this->user . '/files/testimage.jpg'; + $this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $fileInfo = $this->rootView->getFileInfo($sampleFile); + $fileId = $fileInfo['fileid']; + + $largeX = 1920; + $largeY = 1080; + $preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $largeX, $largeY); + + $this->assertEquals($preview->isFileValid(), true); + + // There should be no cached copy + $isCached = $preview->isCached($fileId); + + $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png', $isCached); + $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); + $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $largeX . '-' . $largeY . '.png', $isCached); + + // The returned preview should be of max size + $image = $preview->getPreview(); + + $this->assertEquals($image->width(), $maxX); + $this->assertEquals($image->height(), $maxY); + + // The max thumbnail should be created + $maxThumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png'; + + $this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true); + + // A preview of the asked size should not have been created + $thumbCacheFile = \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $largeX . '-' . $largeY . '.png'; + + $this->assertEquals($this->rootView->file_exists($thumbCacheFile), false); + + // 2nd request should indicate that we have a cached copy of max dimension + $isCached = $preview->isCached($fileId); + $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); + + // Smaller previews should be based on the cached max preview + $smallX = 50; + $smallY = 50; + $preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $smallX, $smallY); + $isCached = $preview->isCached($fileId); + + $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); + + // A small preview should be created + $image = $preview->getPreview(); + $this->assertEquals($image->width(), $smallX); + $this->assertEquals($image->height(), $smallY); + + // The cache should contain the small preview + $thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png'; + + $this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); + + // 2nd request should indicate that we have a cached copy of the exact dimension + $isCached = $preview->isCached($fileId); + + $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png', $isCached); + } + public function testIsPreviewDeleted() { $sampleFile = '/'.$this->user.'/files/test.txt'; @@ -96,25 +167,6 @@ class Preview extends TestCase { $this->assertEquals($this->rootView->is_dir($thumbCacheFolder), false); } - public function testIsMaxSizeWorking() { - - $maxX = 250; - $maxY = 250; - - \OC_Config::setValue('preview_max_x', $maxX); - \OC_Config::setValue('preview_max_y', $maxY); - - $sampleFile = '/'.$this->user.'/files/test.txt'; - - $this->rootView->file_put_contents($sampleFile, 'dummy file data'); - - $preview = new \OC\Preview($this->user, 'files/', 'test.txt', 1000, 1000); - $image = $preview->getPreview(); - - $this->assertEquals($image->width(), $maxX); - $this->assertEquals($image->height(), $maxY); - } - public function txtBlacklist() { $txt = 'random text file'; |