Skip to content

Commit 8dc3a88

Browse files
authored
Merge pull request #61927 from nextcloud/backport/61858/stable32
[stable32] test: fix HEIC tests
2 parents 85042c6 + e6c2a2d commit 8dc3a88

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
env:
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
@@ -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)