[TASK] Decouple TemplateService->getFileName
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / UnitDeprecated / TypoScript / TemplateServiceTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript;
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
19 use TYPO3\CMS\Core\Context\Context;
20 use TYPO3\CMS\Core\TypoScript\TemplateService;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class TemplateServiceTest extends UnitTestCase
27 {
28 /**
29 * @var TemplateService
30 */
31 protected $templateService;
32
33 /**
34 * Set up
35 */
36 protected function setUp(): void
37 {
38 $this->templateService = new TemplateService(new Context());
39 $this->templateService->tt_track = false;
40 }
41
42 /**
43 * @test
44 */
45 public function getFileNameReturnsUrlCorrectly(): void
46 {
47 $this->assertSame('http://example.com', $this->templateService->getFileName('http://example.com'));
48 $this->assertSame('https://example.com', $this->templateService->getFileName('https://example.com'));
49 }
50
51 /**
52 * @test
53 */
54 public function getFileNameReturnsFileCorrectly(): void
55 {
56 $this->assertSame('typo3/index.php', $this->templateService->getFileName('typo3/index.php'));
57 }
58
59 /**
60 * @test
61 */
62 public function getFileNameReturnsNullIfDirectory(): void
63 {
64 $this->assertNull($this->templateService->getFileName(__DIR__));
65 }
66
67 /**
68 * @test
69 */
70 public function getFileNameReturnsNullWithInvalidFileName(): void
71 {
72 $this->assertNull($this->templateService->getFileName(' '));
73 $this->assertNull($this->templateService->getFileName('something/../else'));
74 }
75 }