|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Preview extends TestCase { |
|
|
class Preview extends TestCase { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
private $user; |
|
|
|
|
|
|
|
|
const TEST_PREVIEW_USER1 = "test-preview-user1"; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @var \OC\Files\View |
|
|
* @var \OC\Files\View |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a new user with his own filesystem view |
|
|
// create a new user with his own filesystem view |
|
|
// this gets called by each test in this test class |
|
|
// this gets called by each test in this test class |
|
|
$this->user = $this->getUniqueID(); |
|
|
|
|
|
\OC_User::setUserId($this->user); |
|
|
|
|
|
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); |
|
|
|
|
|
|
|
|
$backend = new \OC_User_Dummy(); |
|
|
|
|
|
\OC_User::useBackend($backend); |
|
|
|
|
|
$backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1); |
|
|
|
|
|
$user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1); |
|
|
|
|
|
\OC::$server->getUserSession()->setUser($user); |
|
|
|
|
|
\OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files'); |
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); |
|
|
\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); |
|
|
|
|
|
|
|
|
$this->rootView = new \OC\Files\View(''); |
|
|
$this->rootView = new \OC\Files\View(''); |
|
|
$this->rootView->mkdir('/'.$this->user); |
|
|
|
|
|
$this->rootView->mkdir('/'.$this->user.'/files'); |
|
|
|
|
|
|
|
|
$this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1); |
|
|
|
|
|
$this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1.'/files'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected function tearDown() { |
|
|
protected function tearDown() { |
|
|
|
|
|
|
|
|
\OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY); |
|
|
\OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY); |
|
|
|
|
|
|
|
|
// Sample is 1680x1050 JPEG |
|
|
// Sample is 1680x1050 JPEG |
|
|
$sampleFile = '/' . $this->user . '/files/testimage.jpg'; |
|
|
|
|
|
|
|
|
$sampleFile = '/' . self::TEST_PREVIEW_USER1 . '/files/testimage.jpg'; |
|
|
$this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); |
|
|
$this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); |
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileId = $fileInfo['fileid']; |
|
|
$fileId = $fileInfo['fileid']; |
|
|
|
|
|
|
|
|
$largeX = 1920; |
|
|
$largeX = 1920; |
|
|
$largeY = 1080; |
|
|
$largeY = 1080; |
|
|
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $largeX, $largeY); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $largeX, $largeY); |
|
|
|
|
|
|
|
|
$this->assertEquals($preview->isFileValid(), true); |
|
|
$this->assertEquals($preview->isFileValid(), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($image->height(), $maxY); |
|
|
$this->assertEquals($image->height(), $maxY); |
|
|
|
|
|
|
|
|
// The max thumbnail should be created |
|
|
// The max thumbnail should be created |
|
|
$maxThumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png'; |
|
|
|
|
|
|
|
|
$maxThumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png'; |
|
|
|
|
|
|
|
|
$this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true); |
|
|
$this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Smaller previews should be based on the cached max preview |
|
|
// Smaller previews should be based on the cached max preview |
|
|
$smallX = 50; |
|
|
$smallX = 50; |
|
|
$smallY = 50; |
|
|
$smallY = 50; |
|
|
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $smallX, $smallY); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $smallX, $smallY); |
|
|
$isCached = $preview->isCached($fileId); |
|
|
$isCached = $preview->isCached($fileId); |
|
|
|
|
|
|
|
|
$this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); |
|
|
$this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); |
|
|
|
|
|
|
|
|
$this->assertEquals($image->height(), $smallY); |
|
|
$this->assertEquals($image->height(), $smallY); |
|
|
|
|
|
|
|
|
// The cache should contain the small preview |
|
|
// The cache should contain the small preview |
|
|
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png'; |
|
|
|
|
|
|
|
|
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png'; |
|
|
|
|
|
|
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testIsPreviewDeleted() { |
|
|
public function testIsPreviewDeleted() { |
|
|
|
|
|
|
|
|
$sampleFile = '/'.$this->user.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
|
|
|
|
|
|
$x = 50; |
|
|
$x = 50; |
|
|
$y = 50; |
|
|
$y = 50; |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y); |
|
|
$preview->getPreview(); |
|
|
$preview->getPreview(); |
|
|
|
|
|
|
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileId = $fileInfo['fileid']; |
|
|
$fileId = $fileInfo['fileid']; |
|
|
|
|
|
|
|
|
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; |
|
|
|
|
|
|
|
|
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; |
|
|
|
|
|
|
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testAreAllPreviewsDeleted() { |
|
|
public function testAreAllPreviewsDeleted() { |
|
|
|
|
|
|
|
|
$sampleFile = '/'.$this->user.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
|
|
|
|
|
|
$x = 50; |
|
|
$x = 50; |
|
|
$y = 50; |
|
|
$y = 50; |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y); |
|
|
$preview->getPreview(); |
|
|
$preview->getPreview(); |
|
|
|
|
|
|
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileId = $fileInfo['fileid']; |
|
|
$fileId = $fileInfo['fileid']; |
|
|
|
|
|
|
|
|
$thumbCacheFolder = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/'; |
|
|
|
|
|
|
|
|
$thumbCacheFolder = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/'; |
|
|
|
|
|
|
|
|
$this->assertEquals($this->rootView->is_dir($thumbCacheFolder), true); |
|
|
$this->assertEquals($this->rootView->is_dir($thumbCacheFolder), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$x = 32; |
|
|
$x = 32; |
|
|
$y = 32; |
|
|
$y = 32; |
|
|
|
|
|
|
|
|
$sample = '/'.$this->user.'/files/test.'.$extension; |
|
|
|
|
|
|
|
|
$sample = '/'.self::TEST_PREVIEW_USER1.'/files/test.'.$extension; |
|
|
$this->rootView->file_put_contents($sample, $data); |
|
|
$this->rootView->file_put_contents($sample, $data); |
|
|
$preview = new \OC\Preview($this->user, 'files/', 'test.'.$extension, $x, $y); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.'.$extension, $x, $y); |
|
|
$image = $preview->getPreview(); |
|
|
$image = $preview->getPreview(); |
|
|
$resource = $image->resource(); |
|
|
$resource = $image->resource(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testCreationFromCached() { |
|
|
public function testCreationFromCached() { |
|
|
|
|
|
|
|
|
$sampleFile = '/'.$this->user.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt'; |
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$x = 150; |
|
|
$x = 150; |
|
|
$y = 150; |
|
|
$y = 150; |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y); |
|
|
$preview->getPreview(); |
|
|
$preview->getPreview(); |
|
|
|
|
|
|
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileInfo = $this->rootView->getFileInfo($sampleFile); |
|
|
$fileId = $fileInfo['fileid']; |
|
|
$fileId = $fileInfo['fileid']; |
|
|
|
|
|
|
|
|
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; |
|
|
|
|
|
|
|
|
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; |
|
|
|
|
|
|
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create smaller previews |
|
|
// create smaller previews |
|
|
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', 50, 50); |
|
|
|
|
|
|
|
|
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', 50, 50); |
|
|
$isCached = $preview->isCached($fileId); |
|
|
$isCached = $preview->isCached($fileId); |
|
|
|
|
|
|
|
|
$this->assertEquals($this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached); |
|
|
|
|
|
|
|
|
$this->assertEquals(self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |