‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪Typo3tempFileServiceTest extends FunctionalTestCase
29 {
30  protected bool ‪$initializeDatabase = false;
31  private string ‪$directoryName;
32  private string ‪$directoryPath;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->directoryName = ‪StringUtility::getUniqueId('test');
38  $this->directoryPath = $this->instancePath . '/typo3temp/assets/' . ‪$this->directoryName;
39  }
40 
41  protected function ‪tearDown(): void
42  {
43  parent::tearDown();
44  ‪GeneralUtility::rmdir($this->directoryPath, true);
45  unset($this->directoryName, $this->directoryPath);
46  }
47 
48  #[Test]
50  {
51  $this->expectException(\RuntimeException::class);
52  $this->expectExceptionCode(1501781454);
53 
54  $processedFileRepository = $this->getMockBuilder(ProcessedFileRepository::class)->disableOriginalConstructor()->getMock();
55  $storageRepository = $this->getMockBuilder(StorageRepository::class)->disableOriginalConstructor()->getMock();
56  $subject = new ‪Typo3tempFileService($processedFileRepository, $storageRepository);
57  $subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
58  }
59 
60  #[Test]
61  public function ‪clearAssetsFolderClearsFolder(): void
62  {
63  ‪GeneralUtility::mkdir_deep($this->directoryPath . '/a/b');
64  file_put_contents($this->directoryPath . '/c.css', '/* test */');
65  file_put_contents($this->directoryPath . '/a/b/c.css', '/* test */');
66  file_put_contents($this->directoryPath . '/a/b/d.css', '/* test */');
67 
68  $processedFileRepository = $this->getMockBuilder(ProcessedFileRepository::class)->disableOriginalConstructor()->getMock();
69  $storageRepository = $this->getMockBuilder(StorageRepository::class)->disableOriginalConstructor()->getMock();
70  $subject = new ‪Typo3tempFileService($processedFileRepository, $storageRepository);
71  $subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
72 
73  self::assertDirectoryDoesNotExist($this->directoryPath . '/a');
74  self::assertDirectoryExists($this->directoryPath);
75  self::assertFileDoesNotExist($this->directoryPath . '/c.css');
76  }
77 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:39
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\setUp
‪setUp()
Definition: Typo3tempFileServiceTest.php:34
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest
Definition: Typo3tempFileServiceTest.php:29
‪TYPO3\CMS\Install\Service\Typo3tempFileService
Definition: Typo3tempFileService.php:32
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\$initializeDatabase
‪bool $initializeDatabase
Definition: Typo3tempFileServiceTest.php:30
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\$directoryPath
‪string $directoryPath
Definition: Typo3tempFileServiceTest.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep(string $directory)
Definition: GeneralUtility.php:1654
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\clearAssetsFolderDetectsNonExistingFolder
‪clearAssetsFolderDetectsNonExistingFolder()
Definition: Typo3tempFileServiceTest.php:49
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\$directoryName
‪string $directoryName
Definition: Typo3tempFileServiceTest.php:31
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\tearDown
‪tearDown()
Definition: Typo3tempFileServiceTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir(string $path, bool $removeNonEmpty=false)
Definition: GeneralUtility.php:1702
‪TYPO3\CMS\Install\Tests\Functional\Service\Typo3tempFileServiceTest\clearAssetsFolderClearsFolder
‪clearAssetsFolderClearsFolder()
Definition: Typo3tempFileServiceTest.php:61
‪TYPO3\CMS\Install\Tests\Functional\Service
Definition: EnableFileServiceTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57