-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathFileStatusServiceTest.php
More file actions
91 lines (78 loc) · 2.61 KB
/
FileStatusServiceTest.php
File metadata and controls
91 lines (78 loc) · 2.61 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Service;
use OCA\Libresign\Db\File as FileEntity;
use OCA\Libresign\Db\FileMapper;
use OCA\Libresign\Service\FileStatusService;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class FileStatusServiceTest extends TestCase {
private FileMapper $fileMapper;
private FileStatusService $service;
protected function setUp(): void {
parent::setUp();
$this->fileMapper = $this->createMock(FileMapper::class);
$this->service = new FileStatusService($this->fileMapper);
}
#[DataProvider('fileStatusUpgradeScenarios')]
public function testUpdateFileStatusIfUpgrade(int $currentStatus, int $newStatus, bool $shouldUpdate): void {
$file = new FileEntity();
$file->setStatus($currentStatus);
if ($shouldUpdate) {
$this->fileMapper->expects($this->once())
->method('update')
->with($file)
->willReturn($file);
} else {
$this->fileMapper->expects($this->never())->method('update');
}
$result = $this->service->updateFileStatusIfUpgrade($file, $newStatus);
$expectedStatus = $shouldUpdate ? $newStatus : $currentStatus;
$this->assertEquals($expectedStatus, $result->getStatus());
}
public static function fileStatusUpgradeScenarios(): array {
$draft = FileEntity::STATUS_DRAFT;
$able = FileEntity::STATUS_ABLE_TO_SIGN;
$partial = FileEntity::STATUS_PARTIAL_SIGNED;
$signed = FileEntity::STATUS_SIGNED;
$deleted = FileEntity::STATUS_DELETED;
return [
[$draft, $able, true],
[$draft, $partial, true],
[$draft, $signed, true],
[$draft, $deleted, true],
[$able, $partial, true],
[$able, $signed, true],
[$able, $deleted, true],
[$partial, $signed, true],
[$partial, $deleted, true],
[$signed, $deleted, true],
[$able, $draft, false],
[$partial, $draft, false],
[$partial, $able, false],
[$signed, $draft, false],
[$signed, $able, false],
[$signed, $partial, false],
[$deleted, $draft, false],
];
}
#[DataProvider('fileStatusNotificationScenarios')]
public function testCanNotifySigners(?int $fileStatus, bool $expected): void {
$result = $this->service->canNotifySigners($fileStatus);
$this->assertEquals($expected, $result);
}
public static function fileStatusNotificationScenarios(): array {
return [
[FileEntity::STATUS_DRAFT, false],
[FileEntity::STATUS_ABLE_TO_SIGN, true],
[FileEntity::STATUS_PARTIAL_SIGNED, false],
[FileEntity::STATUS_SIGNED, false],
[FileEntity::STATUS_DELETED, false],
[null, false],
];
}
}