Skip to content

Commit

Permalink
Merge pull request #31862 from owncloud/stable10-c03444334abe32829e75…
Browse files Browse the repository at this point in the history
…59ea454819164ddc698e

[stable10] Adjust IProvider2::isAvailable to match IProvider::isAvail…
  • Loading branch information
Vincent Petry authored Jun 21, 2018
2 parents 1a3bfc2 + 3dd7c0a commit 0889cef
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
3 changes: 2 additions & 1 deletion lib/private/Preview/Bitmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use Imagick;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;
use OCP\Util;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
/**
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Preview/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

abstract class Image implements IProvider2 {
Expand Down Expand Up @@ -59,7 +60,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
/**
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}
}
9 changes: 3 additions & 6 deletions lib/private/Preview/MP3.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use ID3Parser\ID3Parser;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

class MP3 implements IProvider2 {
Expand Down Expand Up @@ -93,13 +94,9 @@ private function getNoCoverThumbnail() {
}

/**
* Check if a preview can be generated for $path
*
* @param File $file
* @return bool
* @since 10.1.0
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}
}
9 changes: 3 additions & 6 deletions lib/private/Preview/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OC\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

class Movie implements IProvider2 {
Expand Down Expand Up @@ -178,13 +179,9 @@ private function generateThumbNail($maxX, $maxY, $absPath, $second) {
}

/**
* Check if a preview can be generated for $path
*
* @param File $file
* @return bool
* @since 10.1.0
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}
}
3 changes: 2 additions & 1 deletion lib/private/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace OC\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

abstract class Office implements IProvider2 {
Expand Down Expand Up @@ -91,7 +92,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
/**
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Preview/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OC\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

class SVG implements IProvider2 {
Expand Down Expand Up @@ -76,7 +77,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
/**
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return true;
}
}
9 changes: 3 additions & 6 deletions lib/private/Preview/TXT.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OC\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Preview\IProvider2;

class TXT implements IProvider2 {
Expand Down Expand Up @@ -88,13 +89,9 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
}

/**
* Check if a preview can be generated for $path
*
* @param File $file
* @return bool
* @since 10.1.0
* @inheritdoc
*/
public function isAvailable(File $file) {
public function isAvailable(FileInfo $file) {
return $file->getSize() > 0;
}
}
5 changes: 3 additions & 2 deletions lib/public/Preview/IProvider2.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCP\Preview;

use OCP\Files\File;
use OCP\Files\FileInfo;

/**
* Interface IProvider2
Expand All @@ -39,11 +40,11 @@ public function getMimeType();
/**
* Check if a preview can be generated for $path
*
* @param File $file
* @param FileInfo $file
* @return bool
* @since 10.0.9
*/
public function isAvailable(File $file);
public function isAvailable(FileInfo $file);

/**
* get thumbnail for file at path $path
Expand Down
14 changes: 8 additions & 6 deletions tests/lib/PreviewManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\PreviewManager;
use OCP\Files\IRootFolder;
use OCP\Files\FileInfo;
use OCP\IConfig;
use OCP\IImage;
use OCP\IUser;
use OCP\IUserSession;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
use OCP\IPreview;
use OCP\Files\File;
use OCP\Files\Mount\IMountPoint;

/**
Expand All @@ -53,7 +52,7 @@ class PreviewManagerTest extends TestCase {
private $user;
/** @var View */
private $rootView;
/** @var IConfig */
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var IPreview */
private $previewManager;
Expand Down Expand Up @@ -95,7 +94,8 @@ public function testIsAvailable() {
// return defaults
$this->config->method('getSystemValue')->will($this->returnArgument(1));

$file = $this->createMock(File::class);
/** @var FileInfo | \PHPUnit_Framework_MockObject_MockObject $file */
$file = $this->createMock(FileInfo::class);
$file->expects($this->atLeastOnce())
->method('getMimetype')
->willReturn('image/jpeg');
Expand All @@ -107,7 +107,8 @@ public function testIsAvailableGloballyDisabled() {
// return defaults
$this->config->method('getSystemValue')->with('enable_previews', true)->willReturn(false);

$file = $this->createMock(File::class);
/** @var FileInfo | \PHPUnit_Framework_MockObject_MockObject $file */
$file = $this->createMock(FileInfo::class);
$file->expects($this->never())->method('getMimetype');

$this->assertFalse($this->previewManager->isAvailable($file));
Expand All @@ -117,7 +118,8 @@ public function testIsAvailableDisabledOnMountPoint() {
// return defaults
$this->config->method('getSystemValue')->will($this->returnArgument(1));

$file = $this->createMock(File::class);
/** @var FileInfo | \PHPUnit_Framework_MockObject_MockObject $file */
$file = $this->createMock(FileInfo::class);
$file->expects($this->atLeastOnce())
->method('getMimetype')
->willReturn('image/jpeg');
Expand Down

0 comments on commit 0889cef

Please sign in to comment.