Skip to content

Commit fd26baf

Browse files
committed
refactor: Thumbnail Generator logging and tests
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 0c17724 commit fd26baf

File tree

3 files changed

+31
-48
lines changed

3 files changed

+31
-48
lines changed

lib/private/Preview/Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
119119
$maxPreviewImage = null; // only load the image when we need it
120120
if ($maxPreview->getSize() === 0) {
121121
$maxPreview->delete();
122-
$this->logger->error("Max preview generated for file {$file->getPath()} has size 0, deleting and throwing exception.");
122+
$this->logger->error('Max preview generated for file {path} has size 0, deleting and throwing exception.', ['path' => $file->getPath()]);
123123
throw new NotFoundException('Max preview size 0, invalid!');
124124
}
125125

tests/lib/Preview/BackgroundCleanupJobTest.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-License-Identifier: AGPL-3.0-only
@@ -9,12 +10,15 @@
910
use OC\Preview\BackgroundCleanupJob;
1011
use OC\Preview\Storage\Root;
1112
use OC\PreviewManager;
13+
use OCP\App\IAppManager;
1214
use OCP\AppFramework\Utility\ITimeFactory;
1315
use OCP\Files\File;
1416
use OCP\Files\IMimeTypeLoader;
1517
use OCP\Files\IRootFolder;
1618
use OCP\Files\NotFoundException;
1719
use OCP\IDBConnection;
20+
use OCP\IPreview;
21+
use OCP\Server;
1822
use Test\Traits\MountProviderTrait;
1923
use Test\Traits\UserTrait;
2024

@@ -28,25 +32,12 @@
2832
class BackgroundCleanupJobTest extends \Test\TestCase {
2933
use MountProviderTrait;
3034
use UserTrait;
31-
32-
/** @var string */
33-
private $userId;
34-
35-
/** @var bool */
36-
private $trashEnabled;
37-
38-
/** @var IDBConnection */
39-
private $connection;
40-
41-
/** @var PreviewManager */
42-
private $previewManager;
43-
44-
/** @var IRootFolder */
45-
private $rootFolder;
46-
47-
/** @var IMimeTypeLoader */
48-
private $mimeTypeLoader;
49-
35+
private string $userId;
36+
private bool $trashEnabled;
37+
private IDBConnection $connection;
38+
private PreviewManager $previewManager;
39+
private IRootFolder $rootFolder;
40+
private IMimeTypeLoader $mimeTypeLoader;
5041
private ITimeFactory $timeFactory;
5142

5243
protected function setUp(): void {
@@ -62,20 +53,20 @@ protected function setUp(): void {
6253
$this->logout();
6354
$this->loginAsUser($this->userId);
6455

65-
$appManager = \OC::$server->getAppManager();
56+
$appManager = Server::get(IAppManager::class);
6657
$this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user);
6758
$appManager->disableApp('files_trashbin');
6859

69-
$this->connection = \OC::$server->getDatabaseConnection();
70-
$this->previewManager = \OC::$server->getPreviewManager();
71-
$this->rootFolder = \OC::$server->get(IRootFolder::class);
72-
$this->mimeTypeLoader = \OC::$server->getMimeTypeLoader();
73-
$this->timeFactory = \OCP\Server::get(ITimeFactory::class);
60+
$this->connection = Server::get(IDBConnection::class);
61+
$this->previewManager = Server::get(IPreview::class);
62+
$this->rootFolder = Server::get(IRootFolder::class);
63+
$this->mimeTypeLoader = Server::get(IMimeTypeLoader::class);
64+
$this->timeFactory = Server::get(ITimeFactory::class);
7465
}
7566

7667
protected function tearDown(): void {
7768
if ($this->trashEnabled) {
78-
$appManager = \OC::$server->getAppManager();
69+
$appManager = Server::get(IAppManager::class);
7970
$appManager->enableApp('files_trashbin');
8071
}
8172

tests/lib/Preview/Provider.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,33 +10,24 @@
910

1011
use OC\Files\Node\File;
1112
use OCP\Files\IRootFolder;
13+
use OCP\IUserManager;
1214

1315
abstract class Provider extends \Test\TestCase {
14-
/** @var string */
15-
protected $imgPath;
16-
/** @var int */
17-
protected $width;
18-
/** @var int */
19-
protected $height;
20-
/** @var \OC\Preview\Provider */
21-
protected $provider;
22-
/** @var int */
23-
protected $maxWidth = 1024;
24-
/** @var int */
25-
protected $maxHeight = 1024;
26-
/** @var bool */
27-
protected $scalingUp = false;
28-
/** @var int */
29-
protected $userId;
30-
/** @var \OC\Files\View */
31-
protected $rootView;
32-
/** @var \OC\Files\Storage\Storage */
33-
protected $storage;
16+
protected string $imgPath;
17+
protected int $width;
18+
protected int $height;
19+
protected Provider $provider;
20+
protected int $maxWidth = 1024;
21+
protected int $maxHeight = 1024;
22+
protected bool $scalingUp = false;
23+
protected string $userId;
24+
protected \OC\Files\View $rootView;
25+
protected \OC\Files\Storage\Storage $storage;
3426

3527
protected function setUp(): void {
3628
parent::setUp();
3729

38-
$userManager = \OC::$server->getUserManager();
30+
$userManager = \OCP\Server::get(IUserManager::class);
3931
$userManager->clearBackends();
4032
$backend = new \Test\Util\User\Dummy();
4133
$userManager->registerBackend($backend);

0 commit comments

Comments
 (0)