‪TYPO3CMS  ‪main
CleanUpLocalProcessedFilesTest.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 Symfony\Component\Console\Helper\HelperSet;
21 use Symfony\Component\Console\Helper\QuestionHelper;
22 use Symfony\Component\Console\Output\OutputInterface;
23 use Symfony\Component\Console\Tester\CommandTester;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 use TYPO3\TestingFramework\Core\Testbase;
29 
30 final class ‪CleanUpLocalProcessedFilesTest extends FunctionalTestCase
31 {
33 
34  protected ?CommandTester ‪$commandTester = null;
35 
36  protected array ‪$coreExtensionsToLoad = ['lowlevel'];
37 
39  'typo3/sysext/lowlevel/Tests/Functional/Fixtures/DataSet/image.png' => 'fileadmin/image.png',
40  'typo3/sysext/lowlevel/Tests/Functional/Fixtures/DataSet/NotReferencedImage.png' => 'fileadmin/_processed_/0/a/NotReferencedImage.png',
41  'typo3/sysext/lowlevel/Tests/Functional/Fixtures/DataSet/FileWithoutProcessedFileRecord.png' => 'fileadmin/_processed_/1/b/FileWithoutProcessedFileRecord.png',
42  'typo3/sysext/lowlevel/Tests/Functional/Fixtures/DataSet/NotReferencedImage2.png' => 'local-storage/_processed_/0/a/NotReferencedImage2.png',
43  'typo3/sysext/lowlevel/Tests/Functional/Fixtures/DataSet/FileWithoutProcessedFileRecord2.png' => 'local-storage/_processed_/1/b/FileWithoutProcessedFileRecord2.png',
44  ];
45 
46  protected function ‪setUp(): void
47  {
48  parent::setUp();
49 
50  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
51  $this->setUpBackendUser(1);
52 
53  $this->importCSVDataSet(__DIR__ . '/../Fixtures/DataSet/sys_file_processedfile.csv');
54  $this->subject = GeneralUtility::makeInstance(CleanUpLocalProcessedFilesCommand::class);
55 
56  $helperSet = new HelperSet();
57  $helperSet->set(new QuestionHelper(), 'question');
58 
59  $this->subject->setHelperSet($helperSet);
60  $this->commandTester = new CommandTester($this->subject);
61  $this->setUpBackendUser(1);
62 
63  // create fileadmin (1) and an additional absolute local storage (2)
64  ‪$subject = GeneralUtility::makeInstance(StorageRepository::class);
65  ‪$subject->createLocalStorage(
66  'fileadmin',
67  'fileadmin/',
68  'relative'
69  );
70  ‪$subject->createLocalStorage(
71  'another-storage',
72  $this->instancePath . '/local-storage/',
73  'absolute'
74  );
75 
76  // check for existing files to ensure setup is complete for this test
77  foreach ($this->pathsToProvideInTestInstance as $instanceFilePath) {
78  self::assertFileExists(GeneralUtility::getFileAbsFileName($instanceFilePath), $instanceFilePath . ' must exists in testcase instance.');
79  }
80  }
81 
82  protected function ‪tearDown(): void
83  {
84  // Some tests in this testcase deletes provided files. To avoid false-positive with changed orders we need to
85  // ensure that they are re-provided. We are doing this on a test case basis, to avoid unneded disk io if not
86  // really needed.
87  $testbase = new Testbase();
88  $testbase->providePathsInTestInstance($this->instancePath, $this->pathsToProvideInTestInstance);
89 
90  parent::tearDown();
91  }
92 
97  {
98  $this->commandTester->execute(['--force' => true]);
99 
100  $this->assertCSVDataSet(__DIR__ . '/../Fixtures/Modify/oneDeleted.csv');
101  }
102 
106  public function ‪fileForMissingReferenceIsDeleted(): void
107  {
108  $this->commandTester->execute(['--force' => true]);
109 
110  self::assertFileDoesNotExist(GeneralUtility::getFileAbsFileName('fileadmin/_processed_/0/a/NotReferencedImage.png'));
111  self::assertFileDoesNotExist(GeneralUtility::getFileAbsFileName('fileadmin/_processed_/1/b/FileWithoutProcessedFileRecord.png'));
112  self::assertFileDoesNotExist(GeneralUtility::getFileAbsFileName('local-storage/_processed_/0/a/NotReferencedImage2.png'));
113  self::assertFileDoesNotExist(GeneralUtility::getFileAbsFileName('local-storage/_processed_/1/b/FileWithoutProcessedFileRecord2.png'));
114  self::assertFileExists(GeneralUtility::getFileAbsFileName('fileadmin/image.png'));
115  }
116 
120  public function ‪dryRunReallyDoesNothing(): void
121  {
122  $this->commandTester->execute(
123  [
124  '--dry-run' => true,
125  ]
126  );
127  $this->assertCSVDataSet(__DIR__ . '/../Fixtures/DataSet/sys_file_processedfile.csv');
128 
129  // `dry-run` should not remove files, therefore we need to test if `_processed_`file still exists.
130  self::assertFileExists(GeneralUtility::getFileAbsFileName('fileadmin/_processed_/0/a/NotReferencedImage.png'));
131  self::assertFileExists(GeneralUtility::getFileAbsFileName('fileadmin/_processed_/1/b/FileWithoutProcessedFileRecord.png'));
132  self::assertFileExists(GeneralUtility::getFileAbsFileName('local-storage/_processed_/0/a/NotReferencedImage2.png'));
133  self::assertFileExists(GeneralUtility::getFileAbsFileName('local-storage/_processed_/1/b/FileWithoutProcessedFileRecord2.png'));
134  self::assertFileExists(GeneralUtility::getFileAbsFileName('fileadmin/image.png'));
135  }
136 
140  public function ‪confirmDeleteYes(): void
141  {
142  $this->commandTester->setInputs(['yes']);
143  // Set -v option, because the command does not need provide this option due to the use of isVerbose().
144  $this->commandTester->execute([], [
145  'verbosity' => OutputInterface::VERBOSITY_VERBOSE,
146  ]);
147 
148  ‪$output = $this->commandTester->getDisplay();
149 
150  self::assertStringContainsString('[RECORD] Would delete /_processed_/a/SomeMissingFile.png', ‪$output);
151  self::assertStringContainsString('Are you sure you want to delete these processed files and records', ‪$output);
152  self::assertStringContainsString('Deleted 1 processed records', ‪$output);
153  self::assertStringContainsString('Deleted 4 processed files', ‪$output);
154  }
155 
159  public function ‪confirmDeleteNo(): void
160  {
161  $this->commandTester->setInputs(['no']);
162  $this->commandTester->execute([]);
163  ‪$output = $this->commandTester->getDisplay();
164 
165  self::assertStringContainsString('Are you sure you want to delete these processed files and records', ‪$output);
166  self::assertStringNotContainsString('Deleted', ‪$output);
167  }
168 }
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean
Definition: CleanUpLocalProcessedFilesTest.php:18
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\databaseRecordForMissingFileIsDeleted
‪databaseRecordForMissingFileIsDeleted()
Definition: CleanUpLocalProcessedFilesTest.php:96
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\$commandTester
‪CommandTester $commandTester
Definition: CleanUpLocalProcessedFilesTest.php:34
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\$subject
‪CleanUpLocalProcessedFilesCommand $subject
Definition: CleanUpLocalProcessedFilesTest.php:32
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\dryRunReallyDoesNothing
‪dryRunReallyDoesNothing()
Definition: CleanUpLocalProcessedFilesTest.php:120
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\tearDown
‪tearDown()
Definition: CleanUpLocalProcessedFilesTest.php:82
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\setUp
‪setUp()
Definition: CleanUpLocalProcessedFilesTest.php:46
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: CleanUpLocalProcessedFilesTest.php:36
‪TYPO3\CMS\Lowlevel\Command\CleanUpLocalProcessedFilesCommand
Definition: CleanUpLocalProcessedFilesCommand.php:31
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest
Definition: CleanUpLocalProcessedFilesTest.php:31
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\$pathsToProvideInTestInstance
‪array $pathsToProvideInTestInstance
Definition: CleanUpLocalProcessedFilesTest.php:38
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\confirmDeleteYes
‪confirmDeleteYes()
Definition: CleanUpLocalProcessedFilesTest.php:140
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\confirmDeleteNo
‪confirmDeleteNo()
Definition: CleanUpLocalProcessedFilesTest.php:159
‪TYPO3\CMS\Lowlevel\Tests\Functional\Clean\CleanUpLocalProcessedFilesTest\fileForMissingReferenceIsDeleted
‪fileForMissingReferenceIsDeleted()
Definition: CleanUpLocalProcessedFilesTest.php:106