refactor: Thumbnail Generator logging and tests

Signed-off-by: nfebe <fenn25.fn@gmail.com>
pull/52299/head
nfebe 2025-04-22 12:05:30 +07:00
parent 9bfa1e7bd9
commit d980e69f74
3 changed files with 31 additions and 47 deletions

@ -119,7 +119,7 @@ class Generator {
$maxPreviewImage = null; // only load the image when we need it $maxPreviewImage = null; // only load the image when we need it
if ($maxPreview->getSize() === 0) { if ($maxPreview->getSize() === 0) {
$maxPreview->delete(); $maxPreview->delete();
$this->logger->error("Max preview generated for file {$file->getPath()} has size 0, deleting and throwing exception."); $this->logger->error('Max preview generated for file {path} has size 0, deleting and throwing exception.', ['path' => $file->getPath()]);
throw new NotFoundException('Max preview size 0, invalid!'); throw new NotFoundException('Max preview size 0, invalid!');
} }

@ -1,4 +1,5 @@
<?php <?php
/** /**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
@ -9,12 +10,15 @@ namespace Test\Preview;
use OC\Preview\BackgroundCleanupJob; use OC\Preview\BackgroundCleanupJob;
use OC\Preview\Storage\Root; use OC\Preview\Storage\Root;
use OC\PreviewManager; use OC\PreviewManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\IMimeTypeLoader; use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IPreview;
use OCP\Server;
use Test\Traits\MountProviderTrait; use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait; use Test\Traits\UserTrait;
@ -28,25 +32,12 @@ use Test\Traits\UserTrait;
class BackgroundCleanupJobTest extends \Test\TestCase { class BackgroundCleanupJobTest extends \Test\TestCase {
use MountProviderTrait; use MountProviderTrait;
use UserTrait; use UserTrait;
private string $userId;
/** @var string */ private bool $trashEnabled;
private $userId; private IDBConnection $connection;
private PreviewManager $previewManager;
/** @var bool */ private IRootFolder $rootFolder;
private $trashEnabled; private IMimeTypeLoader $mimeTypeLoader;
/** @var IDBConnection */
private $connection;
/** @var PreviewManager */
private $previewManager;
/** @var IRootFolder */
private $rootFolder;
/** @var IMimeTypeLoader */
private $mimeTypeLoader;
private ITimeFactory $timeFactory; private ITimeFactory $timeFactory;
protected function setUp(): void { protected function setUp(): void {
@ -62,20 +53,20 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
$this->logout(); $this->logout();
$this->loginAsUser($this->userId); $this->loginAsUser($this->userId);
$appManager = \OC::$server->getAppManager(); $appManager = Server::get(IAppManager::class);
$this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user);
$appManager->disableApp('files_trashbin'); $appManager->disableApp('files_trashbin');
$this->connection = \OC::$server->getDatabaseConnection(); $this->connection = Server::get(IDBConnection::class);
$this->previewManager = \OC::$server->getPreviewManager(); $this->previewManager = Server::get(IPreview::class);
$this->rootFolder = \OC::$server->get(IRootFolder::class); $this->rootFolder = Server::get(IRootFolder::class);
$this->mimeTypeLoader = \OC::$server->getMimeTypeLoader(); $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class);
$this->timeFactory = \OCP\Server::get(ITimeFactory::class); $this->timeFactory = Server::get(ITimeFactory::class);
} }
protected function tearDown(): void { protected function tearDown(): void {
if ($this->trashEnabled) { if ($this->trashEnabled) {
$appManager = \OC::$server->getAppManager(); $appManager = Server::get(IAppManager::class);
$appManager->enableApp('files_trashbin'); $appManager->enableApp('files_trashbin');
} }

@ -1,4 +1,5 @@
<?php <?php
/** /**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@ -9,33 +10,25 @@ namespace Test\Preview;
use OC\Files\Node\File; use OC\Files\Node\File;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IUserManager;
abstract class Provider extends \Test\TestCase { abstract class Provider extends \Test\TestCase {
/** @var string */ protected string $imgPath;
protected $imgPath; protected int $width;
/** @var int */ protected int $height;
protected $width; /** @var \OC\Preview\Provider|mixed $provider */
/** @var int */
protected $height;
/** @var \OC\Preview\Provider */
protected $provider; protected $provider;
/** @var int */ protected int $maxWidth = 1024;
protected $maxWidth = 1024; protected int $maxHeight = 1024;
/** @var int */ protected bool $scalingUp = false;
protected $maxHeight = 1024; protected string $userId;
/** @var bool */ protected \OC\Files\View $rootView;
protected $scalingUp = false; protected \OC\Files\Storage\Storage $storage;
/** @var int */
protected $userId;
/** @var \OC\Files\View */
protected $rootView;
/** @var \OC\Files\Storage\Storage */
protected $storage;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$userManager = \OC::$server->getUserManager(); $userManager = \OCP\Server::get(IUserManager::class);
$userManager->clearBackends(); $userManager->clearBackends();
$backend = new \Test\Util\User\Dummy(); $backend = new \Test\Util\User\Dummy();
$userManager->registerBackend($backend); $userManager->registerBackend($backend);