preview.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Georg Ehrke <georg@ownCloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. class Preview extends \PHPUnit_Framework_TestCase {
  10. public function testIsPreviewDeleted() {
  11. $user = $this->initFS();
  12. $rootView = new \OC\Files\View('');
  13. $rootView->mkdir('/'.$user);
  14. $rootView->mkdir('/'.$user.'/files');
  15. $samplefile = '/'.$user.'/files/test.txt';
  16. $rootView->file_put_contents($samplefile, 'dummy file data');
  17. $x = 50;
  18. $y = 50;
  19. $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
  20. $preview->getPreview();
  21. $fileinfo = $rootView->getFileInfo($samplefile);
  22. $fileid = $fileinfo['fileid'];
  23. $thumbcachefile = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $x . '-' . $y . '.png';
  24. $this->assertEquals($rootView->file_exists($thumbcachefile), true);
  25. $preview->deletePreview();
  26. $this->assertEquals($rootView->file_exists($thumbcachefile), false);
  27. }
  28. public function testAreAllPreviewsDeleted() {
  29. $user = $this->initFS();
  30. $rootView = new \OC\Files\View('');
  31. $rootView->mkdir('/'.$user);
  32. $rootView->mkdir('/'.$user.'/files');
  33. $samplefile = '/'.$user.'/files/test.txt';
  34. $rootView->file_put_contents($samplefile, 'dummy file data');
  35. $x = 50;
  36. $y = 50;
  37. $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
  38. $preview->getPreview();
  39. $fileinfo = $rootView->getFileInfo($samplefile);
  40. $fileid = $fileinfo['fileid'];
  41. $thumbcachefolder = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/';
  42. $this->assertEquals($rootView->is_dir($thumbcachefolder), true);
  43. $preview->deleteAllPreviews();
  44. $this->assertEquals($rootView->is_dir($thumbcachefolder), false);
  45. }
  46. public function testIsMaxSizeWorking() {
  47. $user = $this->initFS();
  48. $maxX = 250;
  49. $maxY = 250;
  50. \OC_Config::setValue('preview_max_x', $maxX);
  51. \OC_Config::setValue('preview_max_y', $maxY);
  52. $rootView = new \OC\Files\View('');
  53. $rootView->mkdir('/'.$user);
  54. $rootView->mkdir('/'.$user.'/files');
  55. $samplefile = '/'.$user.'/files/test.txt';
  56. $rootView->file_put_contents($samplefile, 'dummy file data');
  57. $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000);
  58. $image = $preview->getPreview();
  59. $this->assertEquals($image->width(), $maxX);
  60. $this->assertEquals($image->height(), $maxY);
  61. }
  62. private function initFS() {
  63. if(\OC\Files\Filesystem::getView()){
  64. $user = \OC_User::getUser();
  65. }else{
  66. $user=uniqid();
  67. \OC_User::setUserId($user);
  68. \OC\Files\Filesystem::init($user, '/'.$user.'/files');
  69. }
  70. \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
  71. return $user;
  72. }
  73. }