Skip to content

Commit f198cd6

Browse files
committed
test(theming): Add unit test to check database query in theming backgroundjob
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 6ef91f0 commit f198cd6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Theming\Tests\Jobs;
11+
12+
use OCA\Theming\Jobs\RestoreBackgroundImageColor;
13+
use OCA\Theming\Service\BackgroundService;
14+
use OCP\AppFramework\Utility\ITimeFactory;
15+
use OCP\BackgroundJob\IJobList;
16+
use OCP\Files\IAppData;
17+
use OCP\IConfig;
18+
use OCP\IDBConnection;
19+
use OCP\Server;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
use Psr\Log\LoggerInterface;
22+
use Test\TestCase;
23+
24+
/**
25+
* @group DB
26+
*/
27+
class RestoreBackgroundImageColorTest extends TestCase {
28+
29+
protected ITimeFactory&MockObject $time;
30+
protected IConfig&MockObject $config;
31+
protected IAppData&MockObject $appData;
32+
protected IJobList&MockObject $jobList;
33+
protected IDBConnection $dbc;
34+
protected LoggerInterface&MockObject $logger;
35+
protected BackgroundService&MockObject $service;
36+
protected RestoreBackgroundImageColor $job;
37+
38+
protected function setUp(): void {
39+
parent::setUp();
40+
41+
$this->time = $this->createMock(ITimeFactory::class);
42+
$this->config = $this->createMock(IConfig::class);
43+
$this->appData = $this->createMock(IAppData::class);
44+
$this->jobList = $this->createMock(IJobList::class);
45+
$this->dbc = Server::get(IDBConnection::class);
46+
$this->logger = $this->createMock(LoggerInterface::class);
47+
$this->service = $this->createMock(BackgroundService::class);
48+
$this->job = new RestoreBackgroundImageColor(
49+
$this->time,
50+
$this->config,
51+
$this->appData,
52+
$this->jobList,
53+
$this->dbc,
54+
$this->logger,
55+
$this->service,
56+
);
57+
}
58+
59+
public function testRunPreparation(): void {
60+
$this->jobList->expects($this->once())
61+
->method('add')
62+
->with(RestoreBackgroundImageColor::class, ['stage' => RestoreBackgroundImageColor::STAGE_EXECUTE]);
63+
self::invokePrivate($this->job, 'runPreparation');
64+
}
65+
}

0 commit comments

Comments
 (0)