diff options
Diffstat (limited to 'tests/lib/Preview')
-rw-r--r-- | tests/lib/Preview/BackgroundCleanupJobTest.php | 89 | ||||
-rw-r--r-- | tests/lib/Preview/BitmapTest.php | 5 | ||||
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 42 | ||||
-rw-r--r-- | tests/lib/Preview/HEICTest.php | 5 | ||||
-rw-r--r-- | tests/lib/Preview/ImageTest.php | 5 | ||||
-rw-r--r-- | tests/lib/Preview/MP3Test.php | 5 | ||||
-rw-r--r-- | tests/lib/Preview/MovieBrokenStuckFfmpegTest.php | 20 | ||||
-rw-r--r-- | tests/lib/Preview/MovieTest.php | 28 | ||||
-rw-r--r-- | tests/lib/Preview/OfficeTest.php | 14 | ||||
-rw-r--r-- | tests/lib/Preview/Provider.php | 58 | ||||
-rw-r--r-- | tests/lib/Preview/SVGTest.php | 12 | ||||
-rw-r--r-- | tests/lib/Preview/TXTTest.php | 5 |
12 files changed, 179 insertions, 109 deletions
diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php index 9c521376af5..ab904f2b499 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only @@ -6,15 +7,21 @@ namespace Test\Preview; +use OC\Files\Storage\Temporary; use OC\Preview\BackgroundCleanupJob; use OC\Preview\Storage\Root; use OC\PreviewManager; +use OC\SystemConfig; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Files\AppData\IAppDataFactory; use OCP\Files\File; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IDBConnection; +use OCP\IPreview; +use OCP\Server; use Test\Traits\MountProviderTrait; use Test\Traits\UserTrait; @@ -28,25 +35,12 @@ use Test\Traits\UserTrait; class BackgroundCleanupJobTest extends \Test\TestCase { use MountProviderTrait; use UserTrait; - - /** @var string */ - private $userId; - - /** @var bool */ - private $trashEnabled; - - /** @var IDBConnection */ - private $connection; - - /** @var PreviewManager */ - private $previewManager; - - /** @var IRootFolder */ - private $rootFolder; - - /** @var IMimeTypeLoader */ - private $mimeTypeLoader; - + private string $userId; + private bool $trashEnabled; + private IDBConnection $connection; + private PreviewManager $previewManager; + private IRootFolder $rootFolder; + private IMimeTypeLoader $mimeTypeLoader; private ITimeFactory $timeFactory; protected function setUp(): void { @@ -55,27 +49,27 @@ class BackgroundCleanupJobTest extends \Test\TestCase { $this->userId = $this->getUniqueID(); $user = $this->createUser($this->userId, $this->userId); - $storage = new \OC\Files\Storage\Temporary([]); + $storage = new Temporary([]); $this->registerMount($this->userId, $storage, ''); $this->loginAsUser($this->userId); $this->logout(); $this->loginAsUser($this->userId); - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); $appManager->disableApp('files_trashbin'); - $this->connection = \OC::$server->getDatabaseConnection(); - $this->previewManager = \OC::$server->getPreviewManager(); - $this->rootFolder = \OC::$server->get(IRootFolder::class); - $this->mimeTypeLoader = \OC::$server->getMimeTypeLoader(); - $this->timeFactory = \OCP\Server::get(ITimeFactory::class); + $this->connection = Server::get(IDBConnection::class); + $this->previewManager = Server::get(IPreview::class); + $this->rootFolder = Server::get(IRootFolder::class); + $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); + $this->timeFactory = Server::get(ITimeFactory::class); } protected function tearDown(): void { if ($this->trashEnabled) { - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); $appManager->enableApp('files_trashbin'); } @@ -86,8 +80,8 @@ class BackgroundCleanupJobTest extends \Test\TestCase { private function getRoot(): Root { return new Root( - \OC::$server->get(IRootFolder::class), - \OC::$server->getSystemConfig() + Server::get(IRootFolder::class), + Server::get(SystemConfig::class) ); } @@ -182,7 +176,7 @@ class BackgroundCleanupJobTest extends \Test\TestCase { $this->markTestSkipped('old previews are not supported for sharded setups'); return; } - $appdata = \OC::$server->getAppDataDir('preview'); + $appdata = Server::get(IAppDataFactory::class)->get('preview'); $f1 = $appdata->newFolder('123456781'); $f1->newFile('foo.jpg', 'foo'); @@ -191,13 +185,44 @@ class BackgroundCleanupJobTest extends \Test\TestCase { $f2 = $appdata->newFolder((string)PHP_INT_MAX - 1); $f2->newFile('foo.jpg', 'foo'); - $appdata = \OC::$server->getAppDataDir('preview'); + /* + * Cleanup of OldPreviewLocations should only remove numeric folders on AppData level, + * therefore these files should stay untouched. + */ + $appdata->getFolder('/')->newFile('not-a-directory', 'foo'); + $appdata->getFolder('/')->newFile('133742', 'bar'); + + $appdata = Server::get(IAppDataFactory::class)->get('preview'); + // AppData::getDirectoryListing filters all non-folders $this->assertSame(3, count($appdata->getDirectoryListing())); + try { + $appdata->getFolder('/')->getFile('not-a-directory'); + } catch (NotFoundException) { + $this->fail('Could not find file \'not-a-directory\''); + } + try { + $appdata->getFolder('/')->getFile('133742'); + } catch (NotFoundException) { + $this->fail('Could not find file \'133742\''); + } $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->getRoot(), $this->mimeTypeLoader, true); $job->run([]); - $appdata = \OC::$server->getAppDataDir('preview'); + $appdata = Server::get(IAppDataFactory::class)->get('preview'); + + // Check if the files created above are still present + // Remember: AppData::getDirectoryListing filters all non-folders $this->assertSame(0, count($appdata->getDirectoryListing())); + try { + $appdata->getFolder('/')->getFile('not-a-directory'); + } catch (NotFoundException) { + $this->fail('Could not find file \'not-a-directory\''); + } + try { + $appdata->getFolder('/')->getFile('133742'); + } catch (NotFoundException) { + $this->fail('Could not find file \'133742\''); + } } } diff --git a/tests/lib/Preview/BitmapTest.php b/tests/lib/Preview/BitmapTest.php index c4f3f8d3cf5..36e768010a9 100644 --- a/tests/lib/Preview/BitmapTest.php +++ b/tests/lib/Preview/BitmapTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Preview; +use OC\Preview\Postscript; + /** * Class BitmapTest * @@ -22,6 +25,6 @@ class BitmapTest extends Provider { $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 2400; $this->height = 1707; - $this->provider = new \OC\Preview\Postscript; + $this->provider = new Postscript; } } diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 7bd121250fb..edf5418da6e 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -19,26 +20,29 @@ use OCP\IImage; use OCP\IPreview; use OCP\Preview\BeforePreviewFetchedEvent; use OCP\Preview\IProviderV2; +use Psr\Log\LoggerInterface; class GeneratorTest extends \Test\TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig&\PHPUnit\Framework\MockObject\MockObject */ private $config; - /** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IPreview&\PHPUnit\Framework\MockObject\MockObject */ private $previewManager; - /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IAppData&\PHPUnit\Framework\MockObject\MockObject */ private $appData; - /** @var GeneratorHelper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var GeneratorHelper&\PHPUnit\Framework\MockObject\MockObject */ private $helper; - /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IEventDispatcher&\PHPUnit\Framework\MockObject\MockObject */ private $eventDispatcher; /** @var Generator */ private $generator; + private LoggerInterface&\PHPUnit\Framework\MockObject\MockObject $logger; + protected function setUp(): void { parent::setUp(); @@ -47,13 +51,15 @@ class GeneratorTest extends \Test\TestCase { $this->appData = $this->createMock(IAppData::class); $this->helper = $this->createMock(GeneratorHelper::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->generator = new Generator( $this->config, $this->previewManager, $this->appData, $this->helper, - $this->eventDispatcher + $this->eventDispatcher, + $this->logger, ); } @@ -191,18 +197,10 @@ class GeneratorTest extends \Test\TestCase { $previewFolder->method('getDirectoryListing') ->willReturn([]); $previewFolder->method('newFile') - ->willReturnCallback(function ($filename) use ($maxPreview, $previewFile) { - if ($filename === '2048-2048-max.png') { - return $maxPreview; - } elseif ($filename === '256-256.png') { - return $previewFile; - } - $this->fail('Unexpected file'); - }); - - $maxPreview->expects($this->once()) - ->method('putContent') - ->with($this->equalTo('my data')); + ->willReturnMap([ + ['2048-2048-max.png', 'my data', $maxPreview], + ['256-256.png', 'my resized data', $previewFile], + ]); $previewFolder->method('getFile') ->with($this->equalTo('256-256.png')) @@ -213,10 +211,6 @@ class GeneratorTest extends \Test\TestCase { ->with($this->equalTo($maxPreview)) ->willReturn($image); - $previewFile->expects($this->once()) - ->method('putContent') - ->with('my resized data'); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); @@ -350,7 +344,7 @@ class GeneratorTest extends \Test\TestCase { return $image; } - public function dataSize() { + public static function dataSize(): array { return [ [1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512], [1024, 2048, 512, 512, false, IPreview::MODE_COVER, 512, 1024], @@ -387,7 +381,6 @@ class GeneratorTest extends \Test\TestCase { } /** - * @dataProvider dataSize * * @param int $maxX * @param int $maxY @@ -398,6 +391,7 @@ class GeneratorTest extends \Test\TestCase { * @param int $expectedX * @param int $expectedY */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSize')] public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expectedX, $expectedY): void { $file = $this->createMock(File::class); $file->method('isReadable') diff --git a/tests/lib/Preview/HEICTest.php b/tests/lib/Preview/HEICTest.php index 5df7b63dd03..def113fbf08 100644 --- a/tests/lib/Preview/HEICTest.php +++ b/tests/lib/Preview/HEICTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -6,6 +7,8 @@ namespace Test\Preview; +use OC\Preview\HEIC; + /** * Class BitmapTest * @@ -24,7 +27,7 @@ class HEICTest extends Provider { $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 1680; $this->height = 1050; - $this->provider = new \OC\Preview\HEIC; + $this->provider = new HEIC; } } } diff --git a/tests/lib/Preview/ImageTest.php b/tests/lib/Preview/ImageTest.php index f4b8e7e1dd4..88c3090557f 100644 --- a/tests/lib/Preview/ImageTest.php +++ b/tests/lib/Preview/ImageTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Preview; +use OC\Preview\JPEG; + /** * Class ImageTest * @@ -22,6 +25,6 @@ class ImageTest extends Provider { $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 1680; $this->height = 1050; - $this->provider = new \OC\Preview\JPEG(); + $this->provider = new JPEG(); } } diff --git a/tests/lib/Preview/MP3Test.php b/tests/lib/Preview/MP3Test.php index 6f40b862b7b..faa06fe42a1 100644 --- a/tests/lib/Preview/MP3Test.php +++ b/tests/lib/Preview/MP3Test.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Preview; +use OC\Preview\MP3; + /** * Class MP3Test * @@ -22,6 +25,6 @@ class MP3Test extends Provider { $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 200; $this->height = 200; - $this->provider = new \OC\Preview\MP3; + $this->provider = new MP3; } } diff --git a/tests/lib/Preview/MovieBrokenStuckFfmpegTest.php b/tests/lib/Preview/MovieBrokenStuckFfmpegTest.php new file mode 100644 index 00000000000..e66d5e64649 --- /dev/null +++ b/tests/lib/Preview/MovieBrokenStuckFfmpegTest.php @@ -0,0 +1,20 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace Test\Preview; + +/** + * Class MovieTest + * + * @group DB + * + * @package Test\Preview + */ +class MovieBrokenStuckFfmpegTest extends MovieTest { + protected string $fileName = 'broken-video.webm'; +} diff --git a/tests/lib/Preview/MovieTest.php b/tests/lib/Preview/MovieTest.php index d41b242945b..c85a9f99748 100644 --- a/tests/lib/Preview/MovieTest.php +++ b/tests/lib/Preview/MovieTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,10 @@ namespace Test\Preview; +use OC\Preview\Movie; +use OCP\IBinaryFinder; +use OCP\Server; + /** * Class MovieTest * @@ -15,21 +20,22 @@ namespace Test\Preview; * @package Test\Preview */ class MovieTest extends Provider { + protected string $fileName = 'testimage.mp4'; + protected int $width = 560; + protected int $height = 320; + protected function setUp(): void { - $avconvBinary = \OC_Helper::findBinaryPath('avconv'); - $ffmpegBinary = ($avconvBinary) ? null : \OC_Helper::findBinaryPath('ffmpeg'); + $binaryFinder = Server::get(IBinaryFinder::class); + $movieBinary = $binaryFinder->findBinaryPath('avconv'); + if (!is_string($movieBinary)) { + $movieBinary = $binaryFinder->findBinaryPath('ffmpeg'); + } - if ($avconvBinary || $ffmpegBinary) { + if (is_string($movieBinary)) { parent::setUp(); - \OC\Preview\Movie::$avconvBinary = $avconvBinary; - \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; - - $fileName = 'testimage.mp4'; - $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); - $this->width = 560; - $this->height = 320; - $this->provider = new \OC\Preview\Movie; + $this->imgPath = $this->prepareTestFile($this->fileName, \OC::$SERVERROOT . '/tests/data/' . $this->fileName); + $this->provider = new Movie(['movieBinary' => $movieBinary]); } else { $this->markTestSkipped('No Movie provider present'); } diff --git a/tests/lib/Preview/OfficeTest.php b/tests/lib/Preview/OfficeTest.php index c9019d017a3..62a4767fd2e 100644 --- a/tests/lib/Preview/OfficeTest.php +++ b/tests/lib/Preview/OfficeTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,10 @@ namespace Test\Preview; +use OC\Preview\OpenDocument; +use OCP\IBinaryFinder; +use OCP\Server; + /** * Class OfficeTest * @@ -16,17 +21,18 @@ namespace Test\Preview; */ class OfficeTest extends Provider { protected function setUp(): void { - $libreofficeBinary = \OC_Helper::findBinaryPath('libreoffice'); - $openofficeBinary = ($libreofficeBinary) ? null : \OC_Helper::findBinaryPath('openoffice'); + $binaryFinder = Server::get(IBinaryFinder::class); + $libreofficeBinary = $binaryFinder->findBinaryPath('libreoffice'); + $openofficeBinary = $libreofficeBinary === false ? $binaryFinder->findBinaryPath('openoffice') : false; - if ($libreofficeBinary || $openofficeBinary) { + if ($libreofficeBinary !== false || $openofficeBinary !== false) { parent::setUp(); $fileName = 'testimage.odt'; $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 595; $this->height = 842; - $this->provider = new \OC\Preview\OpenDocument; + $this->provider = new OpenDocument; } else { $this->markTestSkipped('No Office provider present'); } diff --git a/tests/lib/Preview/Provider.php b/tests/lib/Preview/Provider.php index 41a2a4ca3c4..d8f10c430e4 100644 --- a/tests/lib/Preview/Provider.php +++ b/tests/lib/Preview/Provider.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,35 +8,34 @@ namespace Test\Preview; +use OC\Files\Filesystem; use OC\Files\Node\File; +use OC\Files\Storage\Storage; +use OC\Files\Storage\Temporary; +use OC\Files\View; +use OC\Preview\TXT; use OCP\Files\IRootFolder; +use OCP\IImage; +use OCP\IUserManager; +use OCP\Server; abstract class Provider extends \Test\TestCase { - /** @var string */ - protected $imgPath; - /** @var int */ - protected $width; - /** @var int */ - protected $height; - /** @var \OC\Preview\Provider */ + protected string $imgPath; + protected int $width; + protected int $height; + /** @var \OC\Preview\Provider|mixed $provider */ protected $provider; - /** @var int */ - protected $maxWidth = 1024; - /** @var int */ - protected $maxHeight = 1024; - /** @var bool */ - protected $scalingUp = false; - /** @var int */ - protected $userId; - /** @var \OC\Files\View */ - protected $rootView; - /** @var \OC\Files\Storage\Storage */ - protected $storage; + protected int $maxWidth = 1024; + protected int $maxHeight = 1024; + protected bool $scalingUp = false; + protected string $userId; + protected View $rootView; + protected Storage $storage; protected function setUp(): void { parent::setUp(); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(IUserManager::class); $userManager->clearBackends(); $backend = new \Test\Util\User\Dummy(); $userManager->registerBackend($backend); @@ -44,10 +44,10 @@ abstract class Provider extends \Test\TestCase { $backend->createUser($userId, $userId); $this->loginAsUser($userId); - $this->storage = new \OC\Files\Storage\Temporary([]); - \OC\Files\Filesystem::mount($this->storage, [], '/' . $userId . '/'); + $this->storage = new Temporary([]); + Filesystem::mount($this->storage, [], '/' . $userId . '/'); - $this->rootView = new \OC\Files\View(''); + $this->rootView = new View(''); $this->rootView->mkdir('/' . $userId); $this->rootView->mkdir('/' . $userId . '/files'); @@ -72,12 +72,12 @@ abstract class Provider extends \Test\TestCase { /** * Launches all the tests we have * - * @dataProvider dimensionsDataProvider * @requires extension imagick * * @param int $widthAdjustment * @param int $heightAdjustment */ + #[\PHPUnit\Framework\Attributes\DataProvider('dimensionsDataProvider')] public function testGetThumbnail($widthAdjustment, $heightAdjustment): void { $ratio = round($this->width / $this->height, 2); $this->maxWidth = $this->width - $widthAdjustment; @@ -91,7 +91,7 @@ abstract class Provider extends \Test\TestCase { $preview = $this->getPreview($this->provider); // The TXT provider uses the max dimensions to create its canvas, // so the ratio will always be the one of the max dimension canvas - if (!$this->provider instanceof \OC\Preview\TXT) { + if (!$this->provider instanceof TXT) { $this->doesRatioMatch($preview, $ratio); } $this->doesPreviewFit($preview); @@ -121,10 +121,10 @@ abstract class Provider extends \Test\TestCase { * * @param \OC\Preview\Provider $provider * - * @return bool|\OCP\IImage + * @return bool|IImage */ private function getPreview($provider) { - $file = new File(\OC::$server->get(IRootFolder::class), $this->rootView, $this->imgPath); + $file = new File(Server::get(IRootFolder::class), $this->rootView, $this->imgPath); $preview = $provider->getThumbnail($file, $this->maxWidth, $this->maxHeight, $this->scalingUp); if (get_class($this) === BitmapTest::class && $preview === null) { @@ -140,7 +140,7 @@ abstract class Provider extends \Test\TestCase { /** * Checks if the preview ratio matches the original ratio * - * @param \OCP\IImage $preview + * @param IImage $preview * @param int $ratio */ private function doesRatioMatch($preview, $ratio) { @@ -151,7 +151,7 @@ abstract class Provider extends \Test\TestCase { /** * Tests if a max size preview of smaller dimensions can be created * - * @param \OCP\IImage $preview + * @param IImage $preview */ private function doesPreviewFit($preview) { $maxDimRatio = round($this->maxWidth / $this->maxHeight, 2); diff --git a/tests/lib/Preview/SVGTest.php b/tests/lib/Preview/SVGTest.php index 6a0e93e5f79..8c6d9bb6691 100644 --- a/tests/lib/Preview/SVGTest.php +++ b/tests/lib/Preview/SVGTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,9 @@ namespace Test\Preview; +use OC\Preview\SVG; +use OCP\Files\File; + /** * Class SVGTest * @@ -24,13 +28,13 @@ class SVGTest extends Provider { $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); $this->width = 3000; $this->height = 2000; - $this->provider = new \OC\Preview\SVG; + $this->provider = new SVG; } else { $this->markTestSkipped('No SVG provider present'); } } - public function dataGetThumbnailSVGHref(): array { + public static function dataGetThumbnailSVGHref(): array { return [ ['href'], [' href'], @@ -42,9 +46,9 @@ class SVGTest extends Provider { } /** - * @dataProvider dataGetThumbnailSVGHref * @requires extension imagick */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetThumbnailSVGHref')] public function testGetThumbnailSVGHref(string $content): void { $handle = fopen('php://temp', 'w+'); fwrite($handle, '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> @@ -52,7 +56,7 @@ class SVGTest extends Provider { </svg>'); rewind($handle); - $file = $this->createMock(\OCP\Files\File::class); + $file = $this->createMock(File::class); $file->method('fopen') ->willReturn($handle); diff --git a/tests/lib/Preview/TXTTest.php b/tests/lib/Preview/TXTTest.php index 7f5510eb60f..d722495136c 100644 --- a/tests/lib/Preview/TXTTest.php +++ b/tests/lib/Preview/TXTTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Preview; +use OC\Preview\TXT; + /** * Class TXTTest * @@ -23,6 +26,6 @@ class TXTTest extends Provider { // Arbitrary width and length which won't be used to calculate the ratio $this->width = 500; $this->height = 200; - $this->provider = new \OC\Preview\TXT; + $this->provider = new TXT; } } |