‪TYPO3CMS  10.4
FilePathSanitizerTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪FilePathSanitizerTest extends UnitTestCase
29 {
33  public function ‪sanitizeReturnsUrlCorrectly(): void
34  {
35  $subject = new ‪FilePathSanitizer();
36  self::assertSame('http://example.com', $subject->sanitize('http://example.com'));
37  self::assertSame('https://example.com', $subject->sanitize('https://example.com'));
38  }
39 
43  public function ‪sanitizeReturnsFileCorrectly(): void
44  {
45  $subject = new ‪FilePathSanitizer();
46  self::assertSame('typo3/index.php', $subject->sanitize('typo3/index.php'));
47  }
48 
52  public function ‪sanitizeFailsIfDirectoryGiven(): void
53  {
54  $this->expectException(FileDoesNotExistException::class);
55  $subject = new ‪FilePathSanitizer();
56  $subject->sanitize(__DIR__);
57  }
58 
63  {
64  $this->expectException(InvalidFileNameException::class);
65  self::assertNull((new ‪FilePathSanitizer())->sanitize(' '));
66  self::assertNull((new ‪FilePathSanitizer())->sanitize('something/../else'));
67  }
68 }
‪TYPO3\CMS\Frontend\Resource\FilePathSanitizer
Definition: FilePathSanitizer.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeFailsIfDirectoryGiven
‪sanitizeFailsIfDirectoryGiven()
Definition: FilePathSanitizerTest.php:52
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:22
‪TYPO3\CMS\Frontend\Tests\Unit\Resource
Definition: FilePathSanitizerTest.php:18
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeReturnsFileCorrectly
‪sanitizeReturnsFileCorrectly()
Definition: FilePathSanitizerTest.php:43
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeThrowsExceptionWithInvalidFileName
‪sanitizeThrowsExceptionWithInvalidFileName()
Definition: FilePathSanitizerTest.php:62
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeReturnsUrlCorrectly
‪sanitizeReturnsUrlCorrectly()
Definition: FilePathSanitizerTest.php:33
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest
Definition: FilePathSanitizerTest.php:29
‪TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
Definition: InvalidFileNameException.php:24