Skip to content

Commit 202ff52

Browse files
feat(setup-check): add ImagickSetupCheck
Adds ImagickSetupCheck to verify imagick PHP extension (optional). Related issue: #6590 Type: Feature Checklist: - [x] Implement ISetupCheck interface - [x] Check if imagick extension is loaded - [x] Return info severity when not loaded (optional check) - [x] Return success when loaded - [x] Add unit tests covering both states
1 parent 78b98a0 commit 202ff52

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Libresign\SetupCheck;
10+
11+
use OCP\IL10N;
12+
use OCP\SetupCheck\ISetupCheck;
13+
use OCP\SetupCheck\SetupResult;
14+
15+
class ImagickSetupCheck implements ISetupCheck {
16+
private IL10N $l10n;
17+
18+
public function __construct(IL10N $l10n) {
19+
$this->l10n = $l10n;
20+
}
21+
22+
public function getName(): string {
23+
return $this->l10n->t('Imagick PHP extension');
24+
}
25+
26+
public function getCategory(): string {
27+
return 'system';
28+
}
29+
30+
public function run(): SetupResult {
31+
if (!extension_loaded('imagick')) {
32+
return SetupResult::info(
33+
$this->l10n->t('Imagick extension is not loaded'),
34+
$this->l10n->t('Install php-imagick to enable visible signatures, background images, and signature element rendering.')
35+
);
36+
}
37+
return SetupResult::success($this->l10n->t('Imagick extension is loaded'));
38+
}
39+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
/**
10+
* Mock extension_loaded in the target namespace to control its behavior in tests.
11+
*/
12+
13+
namespace OCA\Libresign\SetupCheck {
14+
function extension_loaded(string $name): bool
15+
{
16+
return \OCA\Libresign\Tests\Unit\SetupCheck\ImagickSetupCheckTest::$mockExtensionLoaded[$name] ?? \extension_loaded($name);
17+
}
18+
}
19+
20+
namespace OCA\Libresign\Tests\Unit\SetupCheck {
21+
22+
use OCA\Libresign\SetupCheck\ImagickSetupCheck;
23+
use OCP\IL10N;
24+
use OCP\SetupCheck\SetupResult;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
27+
28+
29+
class ImagickSetupCheckTest extends TestCase
30+
{
31+
/** @var array<string, bool> */
32+
public static array $mockExtensionLoaded = [];
33+
34+
/** @var IL10N&MockObject */
35+
private $l10n;
36+
37+
/** @var ImagickSetupCheck */
38+
private $check;
39+
40+
protected function setUp(): void
41+
{
42+
parent::setUp();
43+
self::$mockExtensionLoaded = [];
44+
45+
$this->l10n = $this->createMock(IL10N::class);
46+
$this->l10n->method('t')
47+
->willReturnCallback(fn(string $text, array $parameters = []) => vsprintf($text, $parameters));
48+
49+
$this->check = new ImagickSetupCheck(
50+
$this->l10n
51+
);
52+
}
53+
54+
public function testExtensionNotLoaded(): void
55+
{
56+
self::$mockExtensionLoaded['imagick'] = false;
57+
$check = new ImagickSetupCheck($this->l10n);
58+
59+
$result = $check->run();
60+
61+
$this->assertInstanceOf(SetupResult::class, $result);
62+
$this->assertEquals('info', $result->getSeverity());
63+
$this->assertStringContainsString('Imagick extension is not loaded', $result->getDescription());
64+
$this->assertNotNull($result->getDescription());
65+
}
66+
67+
public function testExtensionLoaded(): void
68+
{
69+
self::$mockExtensionLoaded['imagick'] = true;
70+
$check = new ImagickSetupCheck($this->l10n);
71+
72+
$result = $check->run();
73+
74+
$this->assertInstanceOf(SetupResult::class, $result);
75+
$this->assertEquals('success', $result->getSeverity());
76+
$this->assertStringContainsString('Imagick extension is loaded', $result->getDescription());
77+
}
78+
79+
public function testGetName(): void
80+
{
81+
$this->l10n->expects($this->once())
82+
->method('t')
83+
->with('Imagick PHP extension')
84+
->willReturn('Imagick PHP extension');
85+
$this->assertEquals('Imagick PHP extension', $this->check->getName());
86+
}
87+
88+
public function testGetCategory(): void
89+
{
90+
$this->assertEquals('system', $this->check->getCategory());
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)