‪TYPO3CMS  ‪main
CleanerTaskTest.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;
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 final class ‪CleanerTaskTest extends FunctionalTestCase
25 {
26  protected array ‪$coreExtensionsToLoad = ['recycler', 'scheduler'];
27 
28  #[Test]
29  public function ‪taskRemovesDeletedPages(): void
30  {
31  $this->importCSVDataSet(__DIR__ . '/DataSet/Fixtures/pages.csv');
32  $subject = new ‪CleanerTask();
33  $subject->setTcaTables(['pages']);
34  $result = $subject->execute();
35  $this->assertCSVDataSet(__DIR__ . '/DataSet/Assertion/pages_deleted.csv');
36  self::assertTrue($result);
37  }
38 
39  #[Test]
41  {
42  $this->importCSVDataSet(__DIR__ . '/DataSet/Fixtures/pages.csv');
43  $subject = new ‪CleanerTask();
44  $subject->setTcaTables(['pages']);
45  $utcTimeZone = new \DateTimeZone('UTC');
46 
47  // this is when the test was created. One of the fixtures (uid 4) has this date
48  $creationDate = date_create_immutable_from_format('Y-m-d H:i:s', '2020-09-28 00:00:00', $utcTimeZone);
49  // we want to set the period in a way that older records get deleted, but not the one created today
50  $difference = $creationDate->diff(new \DateTime('today', $utcTimeZone), true);
51  // let's set the amount of days one higher than the reference date
52  $period = (int)$difference->format('%a') + 1;
53  $subject->setPeriod($period);
54  $result = $subject->execute();
55  $this->assertCSVDataSet(__DIR__ . '/DataSet/Assertion/pages_deleted_with_period.csv');
56  self::assertTrue($result);
57  }
58 
59  #[Test]
60  public function ‪taskFailsOnError(): void
61  {
62  $subject = new ‪CleanerTask();
63  ‪$GLOBALS['TCA']['not_existing_table']['ctrl']['delete'] = 'deleted';
64  $subject->setTcaTables(['not_existing_table']);
65  $result = $subject->execute();
66  self::assertFalse($result);
67  }
68 }
‪TYPO3\CMS\Recycler\Tests\Functional\Task\CleanerTaskTest
Definition: CleanerTaskTest.php:25
‪TYPO3\CMS\Recycler\Tests\Functional\Task\CleanerTaskTest\taskRemovesOnlyPagesLongerDeletedThanPeriod
‪taskRemovesOnlyPagesLongerDeletedThanPeriod()
Definition: CleanerTaskTest.php:40
‪TYPO3\CMS\Recycler\Tests\Functional\Task\CleanerTaskTest\taskRemovesDeletedPages
‪taskRemovesDeletedPages()
Definition: CleanerTaskTest.php:29
‪TYPO3\CMS\Recycler\Task\CleanerTask
Definition: CleanerTask.php:30
‪TYPO3\CMS\Recycler\Tests\Functional\Task
Definition: CleanerFieldProviderTest.php:18
‪TYPO3\CMS\Recycler\Tests\Functional\Task\CleanerTaskTest\taskFailsOnError
‪taskFailsOnError()
Definition: CleanerTaskTest.php:60
‪TYPO3\CMS\Recycler\Tests\Functional\Task\CleanerTaskTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: CleanerTaskTest.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25