From bfef950752f8b6561caf4ee58535c71654d29a7c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 6 Jul 2026 19:27:08 +0200 Subject: [PATCH] test: fix HEIC tests Signed-off-by: Ferdinand Thiessen --- .github/workflows/phpunit-sqlite.yml | 16 ++++++++++++++- tests/lib/Preview/HEICTest.php | 29 ++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/phpunit-sqlite.yml b/.github/workflows/phpunit-sqlite.yml index ea8888690681b..b1876883b5efe 100644 --- a/.github/workflows/phpunit-sqlite.yml +++ b/.github/workflows/phpunit-sqlite.yml @@ -89,9 +89,23 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Set up dependencies + - name: Enable HEIC support in ImageMagick run: | + # The HEIC preview tests need ImageMagick to actually decode HEIC files. + # GitHub-hosted runners register the HEIC coder (so the tests are not + # skipped) but decoding fails because the libheif delegate is missing + # and/or the coder is blocked by ImageMagick's security policy. Install + # the delegate and allow the HEIC/HEIF/AVIF coders so decoding succeeds. sudo apt-get update + sudo apt-get install -y --no-install-recommends libheif1 libheif-dev + for policy in /etc/ImageMagick-{6,7}/policy.xml; do + if [ -f "$policy" ]; then + sudo sed -i -E 's/rights="none" pattern="(HEIC|HEIF|AVIF)"/rights="read|write" pattern="\1"/g' "$policy" + fi + done + + - name: Set up dependencies + run: | sudo apt-get install -y ghostscript composer i diff --git a/tests/lib/Preview/HEICTest.php b/tests/lib/Preview/HEICTest.php index bac8e1b816f93..b0cf187b8604f 100644 --- a/tests/lib/Preview/HEICTest.php +++ b/tests/lib/Preview/HEICTest.php @@ -20,14 +20,27 @@ class HEICTest extends Provider { protected function setUp(): void { if (!in_array('HEIC', \Imagick::queryFormats('HEI*'))) { $this->markTestSkipped('ImageMagick is not HEIC aware. Skipping tests'); - } else { - parent::setUp(); - - $fileName = 'testimage.heic'; - $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); - $this->width = 1680; - $this->height = 1050; - $this->provider = new HEIC; } + + $fileName = 'testimage.heic'; + $sourcePath = \OC::$SERVERROOT . '/tests/data/' . $fileName; + + // queryFormats() only reports that the HEIC coder is registered, not that + // ImageMagick can actually decode a HEIC file: the libheif delegate may be + // missing or the coder may be disabled by ImageMagick's policy.xml. In that + // case decoding throws, the provider returns null and the tests fail instead + // of being skipped. Verify a real decode before running the tests. + try { + (new \Imagick())->readImage($sourcePath . '[0]'); + } catch (\ImagickException $e) { + $this->markTestSkipped('ImageMagick cannot decode HEIC in this environment: ' . $e->getMessage() . '. Skipping tests'); + } + + parent::setUp(); + + $this->imgPath = $this->prepareTestFile($fileName, $sourcePath); + $this->width = 1680; + $this->height = 1050; + $this->provider = new HEIC; } }