|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Thomas Müller <thomas.mueller@tmit.eu> |
| 4 | + * |
| 5 | + * @copyright Copyright (c) 2026, ownCloud GmbH |
| 6 | + * @license AGPL-3.0 |
| 7 | + * |
| 8 | + * This code is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +namespace Test\Preview; |
| 23 | + |
| 24 | +use Generator; |
| 25 | +use OC\Preview\Bitmap; |
| 26 | +use OC\Preview\Font; |
| 27 | +use OC\Preview\PDF; |
| 28 | +use OCP\Files\File; |
| 29 | +use Test\TestCase; |
| 30 | + |
| 31 | +class SanitizeTest extends TestCase { |
| 32 | + /** |
| 33 | + * @dataProvider providesSVG |
| 34 | + */ |
| 35 | + public function test(string $svgContent, Bitmap $provider): void { |
| 36 | + if (\count(\Imagick::queryFormats('SVG')) === 0) { |
| 37 | + $this->markTestSkipped('No SVG provider present'); |
| 38 | + } |
| 39 | + # mock it all .... |
| 40 | + $stream = fopen('php://memory', 'rb+'); |
| 41 | + fwrite($stream, $svgContent); |
| 42 | + rewind($stream); |
| 43 | + $file = $this->createMock(File::class); |
| 44 | + $file->method('getContent')->willReturn($svgContent); |
| 45 | + $file->method('fopen')->willReturn($stream); |
| 46 | + |
| 47 | + # create the preview |
| 48 | + $return = $provider->getThumbnail($file, 32, 32, false); |
| 49 | + |
| 50 | + $this->assertImage(__DIR__ . '/white-32x32.png', $return); |
| 51 | + } |
| 52 | + |
| 53 | + public function providesSVG(): Generator { |
| 54 | + $embeddedImagePath = __DIR__ . '/../../data/testimage.jpg'; |
| 55 | + $svgContent0 = <<<SVG |
| 56 | +<svg xmlns="http://www.w3.org/2000/svg" width="800" height="800"> |
| 57 | + <image href="$embeddedImagePath" width="400" height="400"></image> |
| 58 | +</svg> |
| 59 | +SVG; |
| 60 | + |
| 61 | + # all Bitmap based providers use the same thumbnailing logic - two is enough .... |
| 62 | + yield 'PDF provider' => [$svgContent0, new PDF()]; |
| 63 | + yield 'Font Provider' => [$svgContent0, new Font()]; |
| 64 | + } |
| 65 | +} |
0 commit comments