Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Adjust IProvider2::isAvailable to match IProvider::isAvail… #31862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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