Skip to content

Commit 1479eba

Browse files
committed
test: fix HEIC tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent ed052e6 commit 1479eba

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

.github/workflows/phpunit-sqlite.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,23 @@ jobs:
9191
fail-fast: true
9292
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9393

94-
- name: Set up dependencies
94+
- name: Enable HEIC support in ImageMagick
9595
run: |
96+
# The HEIC preview tests need ImageMagick to actually decode HEIC files.
97+
# GitHub-hosted runners register the HEIC coder (so the tests are not
98+
# skipped) but decoding fails because the libheif delegate is missing
99+
# and/or the coder is blocked by ImageMagick's security policy. Install
100+
# the delegate and allow the HEIC/HEIF/AVIF coders so decoding succeeds.
96101
sudo apt-get update
102+
sudo apt-get install -y --no-install-recommends libheif1 libheif-dev
103+
for policy in /etc/ImageMagick-{6,7}/policy.xml; do
104+
if [ -f "$policy" ]; then
105+
sudo sed -i -E 's/rights="none" pattern="(HEIC|HEIF|AVIF)"/rights="read|write" pattern="\1"/g' "$policy"
106+
fi
107+
done
108+
109+
- name: Set up dependencies
110+
run: |
97111
sudo apt-get install -y ghostscript
98112
composer i
99113

tests/lib/Preview/HEICTest.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,27 @@ class HEICTest extends Provider {
2121
protected function setUp(): void {
2222
if (!in_array('HEIC', \Imagick::queryFormats('HEI*'))) {
2323
$this->markTestSkipped('ImageMagick is not HEIC aware. Skipping tests');
24-
} else {
25-
parent::setUp();
26-
27-
$fileName = 'testimage.heic';
28-
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName);
29-
$this->width = 1680;
30-
$this->height = 1050;
31-
$this->provider = new HEIC;
3224
}
25+
26+
$fileName = 'testimage.heic';
27+
$sourcePath = \OC::$SERVERROOT . '/tests/data/' . $fileName;
28+
29+
// queryFormats() only reports that the HEIC coder is registered, not that
30+
// ImageMagick can actually decode a HEIC file: the libheif delegate may be
31+
// missing or the coder may be disabled by ImageMagick's policy.xml. In that
32+
// case decoding throws, the provider returns null and the tests fail instead
33+
// of being skipped. Verify a real decode before running the tests.
34+
try {
35+
(new \Imagick())->readImage($sourcePath . '[0]');
36+
} catch (\ImagickException $e) {
37+
$this->markTestSkipped('ImageMagick cannot decode HEIC in this environment: ' . $e->getMessage() . '. Skipping tests');
38+
}
39+
40+
parent::setUp();
41+
42+
$this->imgPath = $this->prepareTestFile($fileName, $sourcePath);
43+
$this->width = 1680;
44+
$this->height = 1050;
45+
$this->provider = new HEIC;
3346
}
3447
}

0 commit comments

Comments
 (0)