‪TYPO3CMS  ‪main
EnableFileServiceTest.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;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪EnableFileServiceTest extends FunctionalTestCase
26 {
27  protected bool ‪$initializeDatabase = false;
28 
29  public function ‪tearDown(): void
30  {
31  $publicPath = ‪Environment::getPublicPath();
32  @rmdir($publicPath . '/FIRST_INSTALL2Folder');
33  @unlink($publicPath . '/FIRST_INSTALL');
34  @unlink($publicPath . '/FIRST_INStall');
35  @unlink($publicPath . '/FIRST_INSTALL.txt');
36  @unlink($publicPath . '/foo');
37  @unlink($publicPath . '/bar');
38  @unlink($publicPath . '/ddd.txt');
39  @unlink($publicPath . '/somethingelse');
40  @unlink($publicPath . '/dadadaFIRST_INStall');
41  parent::tearDown();
42  }
43 
44  #[Test]
46  {
47  $publicPath = ‪Environment::getPublicPath();
48  mkdir($publicPath . '/FIRST_INSTALL2Folder');
49  file_put_contents($publicPath . '/FIRST_INSTALL', '');
50  file_put_contents($publicPath . '/FIRST_INStall', '');
51  file_put_contents($publicPath . '/FIRST_INSTALL.txt', 'with content');
52  file_put_contents($publicPath . '/somethingelse', '');
53  file_put_contents($publicPath . '/dadadaFIRST_INStall', '');
54  $expected = [
55  'FIRST_INSTALL',
56  'FIRST_INStall',
57  'FIRST_INSTALL.txt',
58  ];
59  $subject = $this->getAccessibleMock(EnableFileService::class, null);
60  self::assertEquals([], array_diff($expected, $subject->_call('getFirstInstallFilePaths')));
61  }
62 
63  #[Test]
65  {
66  $publicPath = ‪Environment::getPublicPath();
67  mkdir($publicPath . '/FIRST_INSTALL2Folder');
68  file_put_contents($publicPath . '/foo', '');
69  file_put_contents($publicPath . '/bar', '');
70  file_put_contents($publicPath . '/ddd.txt', 'with content');
71  file_put_contents($publicPath . '/somethingelse', '');
72  file_put_contents($publicPath . '/dadadaFIRST_INStall', '');
73  $subject = $this->getAccessibleMock(EnableFileService::class, null);
74  self::assertEquals([], array_diff([], $subject->_call('getFirstInstallFilePaths')));
75  }
76 
77  #[Test]
79  {
80  $publicPath = ‪Environment::getPublicPath();
81  mkdir($publicPath . '/FIRST_INSTALL2Folder');
82  file_put_contents($publicPath . '/FIRST_INSTALL', '');
83  file_put_contents($publicPath . '/FIRST_INStall', '');
84  file_put_contents($publicPath . '/FIRST_INSTALL.txt', 'with content');
85  file_put_contents($publicPath . '/somethingelse', '');
86  file_put_contents($publicPath . '/dadadaFIRST_INStall', '');
87  $expected = scandir($publicPath);
88  unset($expected[2], $expected[3], $expected[5]);
89  $subject = $this->getAccessibleMock(EnableFileService::class, null);
90  $subject->_call('removeFirstInstallFile');
91  self::assertEquals(array_values($expected), array_values(scandir($publicPath)));
92  }
93 
94  #[Test]
96  {
97  $publicPath = ‪Environment::getPublicPath();
98  mkdir($publicPath . '/FIRST_INSTALL2Folder');
99  file_put_contents($publicPath . '/foo', '');
100  file_put_contents($publicPath . '/bar', '');
101  file_put_contents($publicPath . '/ddd.txt', 'with content');
102  file_put_contents($publicPath . '/somethingelse', '');
103  file_put_contents($publicPath . '/dadadaFIRST_INStall', '');
104  $expected = scandir($publicPath);
105  $subject = $this->getAccessibleMock(EnableFileService::class, null);
106  $subject->_call('removeFirstInstallFile');
107  self::assertEquals(array_values($expected), array_values(scandir($publicPath)));
108  }
109 
110  #[Test]
112  {
116  @mkdir(dirname($defaultLocation));
117  @mkdir(dirname($permanentLocation));
118  @mkdir(dirname($legacyLocation));
119  file_put_contents($defaultLocation, 'abc');
120  file_put_contents($permanentLocation, 'abc');
121  file_put_contents($legacyLocation, 'abc');
122  $subject = new ‪EnableFileService();
123  $result = $subject::removeInstallToolEnableFile();
124  self::assertTrue($result);
125  self::assertFileDoesNotExist($defaultLocation);
126  self::assertFileDoesNotExist($permanentLocation);
127  self::assertFileDoesNotExist($legacyLocation);
128  }
129 }
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\removeFirstInstallFileRemovesNoFileIfThereAreNoValidFiles
‪removeFirstInstallFileRemovesNoFileIfThereAreNoValidFiles()
Definition: EnableFileServiceTest.php:95
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Service\EnableFileService\INSTALL_TOOL_ENABLE_FILE_PATH
‪const INSTALL_TOOL_ENABLE_FILE_PATH
Definition: EnableFileService.php:30
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\removeInstallToolEnableFileRemovesAllAvailableFiles
‪removeInstallToolEnableFileRemovesAllAvailableFiles()
Definition: EnableFileServiceTest.php:111
‪TYPO3\CMS\Install\Service\EnableFileService
Definition: EnableFileService.php:26
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static getLegacyConfigPath()
Definition: Environment.php:268
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\getFirstInstallFilePathsReturnsEmptyArrayWithOnlyInvalidFiles
‪getFirstInstallFilePathsReturnsEmptyArrayWithOnlyInvalidFiles()
Definition: EnableFileServiceTest.php:64
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\$initializeDatabase
‪bool $initializeDatabase
Definition: EnableFileServiceTest.php:27
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest
Definition: EnableFileServiceTest.php:26
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\tearDown
‪tearDown()
Definition: EnableFileServiceTest.php:29
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\getFirstInstallFilePathsFindsValidFiles
‪getFirstInstallFilePathsFindsValidFiles()
Definition: EnableFileServiceTest.php:45
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\Service\EnableFileServiceTest\removeFirstInstallFileRemovesValidFiles
‪removeFirstInstallFileRemovesValidFiles()
Definition: EnableFileServiceTest.php:78
‪TYPO3\CMS\Install\Tests\Functional\Service
Definition: EnableFileServiceTest.php:18