diff --git a/.github/workflows/phpunit-sqlite.yml b/.github/workflows/phpunit-sqlite.yml index 8fa7ff770e099..d7610ff075d10 100644 --- a/.github/workflows/phpunit-sqlite.yml +++ b/.github/workflows/phpunit-sqlite.yml @@ -90,6 +90,21 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - 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: composer i diff --git a/tests/lib/Preview/HEICTest.php b/tests/lib/Preview/HEICTest.php index 4853ac9b87963..b21ad6f66c2ec 100644 --- a/tests/lib/Preview/HEICTest.php +++ b/tests/lib/Preview/HEICTest.php @@ -27,5 +27,26 @@ protected function setUp(): void { $this->height = 1050; $this->provider = new \OC\Preview\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; } }