‪TYPO3CMS  ‪main
SvgSanitizerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use Symfony\Component\Finder\Finder;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪SvgSanitizerTest extends FunctionalTestCase
27 {
28  protected bool ‪$initializeDatabase = false;
29 
33  public static function svgContentIsSanitizedDataProvider(): array
34  {
35  $basePath = dirname(__FILE__, 2) . '/Fixtures/';
36  ‪$finder = new Finder();
38  ->files()
39  ->in($basePath . 'DirtySVG/')
40  ->name('*.svg');
41  ‪$data = [];
42  foreach (‪$finder as $file) {
43  $fileName = $file->getFilename();
44  ‪$data[$fileName] = [
45  $basePath . 'DirtySVG/' . $fileName,
46  $basePath . 'CleanSVG/' . $fileName,
47  ];
48  }
49  return ‪$data;
50  }
51 
52  #[DataProvider('svgContentIsSanitizedDataProvider')]
53  #[Test]
54  public function ‪svgContentIsSanitized(string $filePath, string $sanitizedFilePath): void
55  {
56  $sanitizer = new ‪SvgSanitizer();
57  self::assertStringEqualsFile(
58  $sanitizedFilePath,
59  $sanitizer->sanitizeContent(file_get_contents($filePath))
60  );
61  }
62 }
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security\SvgSanitizerTest\$data
‪foreach($finder as $file) return $data
Definition: SvgSanitizerTest.php:42
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security
Definition: SvgSanitizerTest.php:18
‪$finder
‪if(PHP_SAPI !=='cli') $finder
Definition: header-comment.php:22
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security\SvgSanitizerTest\svgContentIsSanitized
‪svgContentIsSanitized(string $filePath, string $sanitizedFilePath)
Definition: SvgSanitizerTest.php:54
‪TYPO3\CMS\Core\Resource\Security\SvgSanitizer
Definition: SvgSanitizer.php:23
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security\SvgSanitizerTest\$initializeDatabase
‪bool $initializeDatabase
Definition: SvgSanitizerTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security\SvgSanitizerTest\$data
‪$data
Definition: SvgSanitizerTest.php:41
‪TYPO3\CMS\Core\Tests\Functional\Resource\Security\SvgSanitizerTest
Definition: SvgSanitizerTest.php:27