‪TYPO3CMS  10.4
Typo3tempFileServiceTest.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 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
30 class ‪Typo3tempFileServiceTest extends FunctionalTestCase
31 {
35  private ‪$directoryName;
36 
41 
42  protected function ‪setUp(): void
43  {
44  parent::setUp();
45  $this->directoryName = ‪StringUtility::getUniqueId('test');
46  $this->directoryPath = $this->instancePath . '/typo3temp/assets/' . ‪$this->directoryName;
47  }
48 
49  protected function ‪tearDown(): void
50  {
51  parent::tearDown();
52  ‪GeneralUtility::rmdir($this->directoryPath, true);
53  unset($this->directoryName, $this->directoryPath);
54  }
55 
60  {
61  $this->expectException(\RuntimeException::class);
62  $this->expectExceptionCode(1501781454);
63 
64  $processedFileRepository = $this->prophesize(ProcessedFileRepository::class);
65  $storageRepository = $this->prophesize(StorageRepository::class);
66  $subject = new Typo3tempFileService($processedFileRepository->reveal(), $storageRepository->reveal());
67  $subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
68  }
69 
73  public function ‪clearAssetsFolderClearsFolder()
74  {
75  ‪GeneralUtility::mkdir_deep($this->directoryPath . '/a/b');
76  file_put_contents($this->directoryPath . '/c.css', '/* test */');
77  file_put_contents($this->directoryPath . '/a/b/c.css', '/* test */');
78  file_put_contents($this->directoryPath . '/a/b/d.css', '/* test */');
79 
80  $processedFileRepository = $this->prophesize(ProcessedFileRepository::class);
81  $storageRepository = $this->prophesize(StorageRepository::class);
82  $subject = new Typo3tempFileService($processedFileRepository->reveal(), $storageRepository->reveal());
83  $subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
84 
85  self::assertDirectoryNotExists($this->directoryPath . '/a');
86  self::assertDirectoryExists($this->directoryPath);
87  self::assertFileNotExists($this->directoryPath . '/c.css');
88  }
89 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:30
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\setUp
‪setUp()
Definition: Typo3tempFileServiceTest.php:40
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest
Definition: Typo3tempFileServiceTest.php:31
‪TYPO3\CMS\Install\Service\Typo3tempFileService
Definition: Typo3tempFileService.php:32
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\$directoryPath
‪string $directoryPath
Definition: Typo3tempFileServiceTest.php:38
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\clearAssetsFolderDetectsNonExistingFolder
‪clearAssetsFolderDetectsNonExistingFolder()
Definition: Typo3tempFileServiceTest.php:57
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\$directoryName
‪string $directoryName
Definition: Typo3tempFileServiceTest.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:2022
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:31
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\tearDown
‪tearDown()
Definition: Typo3tempFileServiceTest.php:47
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\clearAssetsFolderClearsFolder
‪clearAssetsFolderClearsFolder()
Definition: Typo3tempFileServiceTest.php:71
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:2075
‪TYPO3\CMS\Install\Tests\Functional\Service
Definition: Typo3tempFileServiceTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22