-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathSignatureBackgroundServiceTest.php
More file actions
75 lines (67 loc) · 2.22 KB
/
SignatureBackgroundServiceTest.php
File metadata and controls
75 lines (67 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use OCA\Libresign\Service\SignatureBackgroundService;
use OCP\Files\IAppData;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\ITempManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
final class SignatureBackgroundServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private SignatureBackgroundService $service;
private IAppConfig $appConfig;
private IAppData&MockObject $appData;
private IConfig&MockObject $config;
private ITempManager&MockObject $tempManager;
public function setUp(): void {
$this->appData = $this->createMock(IAppData::class);
$this->appConfig = $this->getMockAppConfigWithReset();
$this->config = $this->createMock(IConfig::class);
$this->tempManager = $this->createMock(ITempManager::class);
}
private function getClass(): SignatureBackgroundService {
$this->service = new SignatureBackgroundService(
$this->appData,
$this->appConfig,
$this->config,
$this->tempManager,
);
return $this->service;
}
#[DataProvider('providerScaleDimensions')]
public function testScaleDimensions(
int $inputWidth,
int $inputHeight,
float $configWidth,
float $configHeight,
int $expectedWidth,
int $expectedHeight,
): void {
$this->appConfig->setValueFloat('libresign', 'signature_width', $configWidth);
$this->appConfig->setValueFloat('libresign', 'signature_height', $configHeight);
$class = $this->getClass();
$result = self::invokePrivate($class, 'scaleDimensions', [$inputWidth, $inputHeight]);
$this->assertSame(
['width' => $expectedWidth, 'height' => $expectedHeight],
$result
);
}
public static function providerScaleDimensions(): array {
return [
'under limit => return equals'
=> [100, 50, 200, 100, 100, 50],
'between upscale limit => return equals'
=> [500, 200, 200, 100, 500, 200],
'height over upscale limit => reduce to scale limit'
=> [800, 600, 200, 100, 400, 300],
'width and height over upscale limit => reduce to scale limit'
=> [2000, 1600, 200, 100, 375, 300],
'every return integer'
=> [2000, 1600, 200.7, 100.5, 376, 301],
];
}
}