‪TYPO3CMS  9.5
FilePathSanitizerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪FilePathSanitizerTest extends UnitTestCase
28 {
32  public function ‪sanitizeReturnsUrlCorrectly(): void
33  {
34  $subject = new ‪FilePathSanitizer();
35  $this->assertSame('http://example.com', $subject->sanitize('http://example.com'));
36  $this->assertSame('https://example.com', $subject->sanitize('https://example.com'));
37  }
38 
42  public function ‪sanitizeReturnsFileCorrectly(): void
43  {
44  $subject = new ‪FilePathSanitizer();
45  $this->assertSame('typo3/index.php', $subject->sanitize('typo3/index.php'));
46  }
47 
51  public function ‪sanitizeFailsIfDirectoryGiven(): void
52  {
53  $this->expectException(FileDoesNotExistException::class);
54  $subject = new ‪FilePathSanitizer();
55  $subject->sanitize(__DIR__);
56  }
57 
62  {
63  $this->expectException(InvalidFileNameException::class);
64  $this->assertNull((new ‪FilePathSanitizer())->sanitize(' '));
65  $this->assertNull((new ‪FilePathSanitizer())->sanitize('something/../else'));
66  }
67 }
‪TYPO3\CMS\Frontend\Resource\FilePathSanitizer
Definition: FilePathSanitizer.php:37
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeFailsIfDirectoryGiven
‪sanitizeFailsIfDirectoryGiven()
Definition: FilePathSanitizerTest.php:51
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:21
‪TYPO3\CMS\Frontend\Tests\Unit\Resource
Definition: FilePathSanitizerTest.php:4
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeReturnsFileCorrectly
‪sanitizeReturnsFileCorrectly()
Definition: FilePathSanitizerTest.php:42
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeThrowsExceptionWithInvalidFileName
‪sanitizeThrowsExceptionWithInvalidFileName()
Definition: FilePathSanitizerTest.php:61
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest\sanitizeReturnsUrlCorrectly
‪sanitizeReturnsUrlCorrectly()
Definition: FilePathSanitizerTest.php:32
‪TYPO3\CMS\Frontend\Tests\Unit\Resource\FilePathSanitizerTest
Definition: FilePathSanitizerTest.php:28
‪TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
Definition: InvalidFileNameException.php:21