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