Skip to content

Commit 21592cf

Browse files
Merge pull request #62155 from nextcloud/backport/61858/stable31
[stable31] test: fix HEIC tests
2 parents 3636433 + a61b16f commit 21592cf

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

.github/workflows/phpunit-sqlite.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ jobs:
9090
env:
9191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9292

93+
- name: Enable HEIC support in ImageMagick
94+
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.
100+
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+
93108
- name: Set up dependencies
94109
run: composer i
95110

tests/lib/Preview/HEICTest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Test\Preview;
88

9+
use OC\Preview\HEIC;
10+
911
/**
1012
* Class BitmapTest
1113
*
@@ -17,14 +19,27 @@ class HEICTest extends Provider {
1719
protected function setUp(): void {
1820
if (!in_array('HEIC', \Imagick::queryFormats('HEI*'))) {
1921
$this->markTestSkipped('ImageMagick is not HEIC aware. Skipping tests');
20-
} else {
21-
parent::setUp();
22+
}
23+
24+
$fileName = 'testimage.heic';
25+
$sourcePath = \OC::$SERVERROOT . '/tests/data/' . $fileName;
2226

23-
$fileName = 'testimage.heic';
24-
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName);
25-
$this->width = 1680;
26-
$this->height = 1050;
27-
$this->provider = new \OC\Preview\HEIC;
27+
// queryFormats() only reports that the HEIC coder is registered, not that
28+
// ImageMagick can actually decode a HEIC file: the libheif delegate may be
29+
// missing or the coder may be disabled by ImageMagick's policy.xml. In that
30+
// case decoding throws, the provider returns null and the tests fail instead
31+
// of being skipped. Verify a real decode before running the tests.
32+
try {
33+
(new \Imagick())->readImage($sourcePath . '[0]');
34+
} catch (\ImagickException $e) {
35+
$this->markTestSkipped('ImageMagick cannot decode HEIC in this environment: ' . $e->getMessage() . '. Skipping tests');
2836
}
37+
38+
parent::setUp();
39+
40+
$this->imgPath = $this->prepareTestFile($fileName, $sourcePath);
41+
$this->width = 1680;
42+
$this->height = 1050;
43+
$this->provider = new HEIC;
2944
}
3045
}

0 commit comments

Comments
 (0)