Skip to content

Commit 9cd251a

Browse files
Merge pull request #61893 from nextcloud/backport/61858/stable33
[stable33] test: fix HEIC tests
2 parents bd0dbff + bfef950 commit 9cd251a

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

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

tests/lib/Preview/HEICTest.php

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

0 commit comments

Comments
 (0)