|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Test\Preview; |
| 9 | + |
| 10 | +use OC\Preview\HEIC; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class HEICDisguisedSVGTest |
| 14 | + * |
| 15 | + * |
| 16 | + * @package Test\Preview |
| 17 | + */ |
| 18 | +#[\PHPUnit\Framework\Attributes\Group('DB')] |
| 19 | +class HEICDisguisedSVGTest extends Provider { |
| 20 | + protected function setUp(): void { |
| 21 | + if (!in_array('HEIC', \Imagick::queryFormats('HEI*'))) { |
| 22 | + $this->markTestSkipped('ImageMagick is not HEIC aware. Skipping tests'); |
| 23 | + } else { |
| 24 | + parent::setUp(); |
| 25 | + |
| 26 | + $this->width = 1680; |
| 27 | + $this->height = 1050; |
| 28 | + $this->provider = new HEIC; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Launches all the tests we have |
| 34 | + * |
| 35 | + * |
| 36 | + * @param int $widthAdjustment |
| 37 | + * @param int $heightAdjustment |
| 38 | + */ |
| 39 | + #[\PHPUnit\Framework\Attributes\DataProvider('dimensionsDataProvider')] |
| 40 | + #[\PHPUnit\Framework\Attributes\RequiresPhpExtension('imagick')] |
| 41 | + public function testGetThumbnail($widthAdjustment, $heightAdjustment): void { |
| 42 | + # HEIC->getThumbnail will always return null if there is an exception, be we want to check why getResizedPreview fails |
| 43 | + $reflection = new \ReflectionClass($this->provider); |
| 44 | + $method = $reflection->getMethod('getResizedPreview'); |
| 45 | + $method->setAccessible(true); |
| 46 | + |
| 47 | + $absolutePath = \OC::$SERVERROOT . '/tests/data/' . 'testimage-disguised-svg.heic'; |
| 48 | + |
| 49 | + try { |
| 50 | + $method->invoke( |
| 51 | + $this->provider, |
| 52 | + $absolutePath, |
| 53 | + $this->width, |
| 54 | + $this->height |
| 55 | + ); |
| 56 | + $this->fail('Expected ImagickException was not thrown.'); |
| 57 | + } catch (\ImagickException $e) { |
| 58 | + $this->assertStringStartsWith('ImageTypeNotSupported', $e->getMessage()); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments