Skip to content

Commit eefefe5

Browse files
Merge pull request #61873 from nextcloud/backport/61858/stable34
[stable34] test: fix HEIC tests
2 parents 221c88f + 3609734 commit eefefe5

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
@@ -90,9 +90,23 @@ jobs:
9090
env:
9191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9292

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

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)