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
if ($maxPreview->getSize() === 0) {
$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!');
}

@ -1,4 +1,5 @@
<?php
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
@ -9,12 +10,15 @@ namespace Test\Preview;
use OC\Preview\BackgroundCleanupJob;
use OC\Preview\Storage\Root;
use OC\PreviewManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
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 +32,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 {
@ -62,20 +53,20 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
$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');
}

@ -1,4 +1,5 @@
<?php
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@ -9,33 +10,25 @@ namespace Test\Preview;
use OC\Files\Node\File;
use OCP\Files\IRootFolder;
use OCP\IUserManager;
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 \OC\Files\View $rootView;
protected \OC\Files\Storage\Storage $storage;
protected function setUp(): void {
parent::setUp();
$userManager = \OC::$server->getUserManager();
$userManager = \OCP\Server::get(IUserManager::class);
$userManager->clearBackends();
$backend = new \Test\Util\User\Dummy();
$userManager->registerBackend($backend);