SVGTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Preview;
  8. /**
  9. * Class SVGTest
  10. *
  11. * @group DB
  12. *
  13. * @package Test\Preview
  14. */
  15. class SVGTest extends Provider {
  16. protected function setUp(): void {
  17. $checkImagick = new \Imagick();
  18. if (count($checkImagick->queryFormats('SVG')) === 1) {
  19. parent::setUp();
  20. $fileName = 'testimagelarge.svg';
  21. $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName);
  22. $this->width = 3000;
  23. $this->height = 2000;
  24. $this->provider = new \OC\Preview\SVG;
  25. } else {
  26. $this->markTestSkipped('No SVG provider present');
  27. }
  28. }
  29. public function dataGetThumbnailSVGHref(): array {
  30. return [
  31. ['href'],
  32. [' href'],
  33. ["\nhref"],
  34. ['xlink:href'],
  35. [' xlink:href'],
  36. ["\nxlink:href"],
  37. ];
  38. }
  39. /**
  40. * @dataProvider dataGetThumbnailSVGHref
  41. * @requires extension imagick
  42. */
  43. public function testGetThumbnailSVGHref(string $content): void {
  44. $handle = fopen('php://temp', 'w+');
  45. fwrite($handle, '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  46. <image x="0" y="0"' . $content . '="fxlogo.png" height="100" width="100" />
  47. </svg>');
  48. rewind($handle);
  49. $file = $this->createMock(\OCP\Files\File::class);
  50. $file->method('fopen')
  51. ->willReturn($handle);
  52. self::assertNull($this->provider->getThumbnail($file, 512, 512));
  53. }
  54. }