‪TYPO3CMS  10.4
CleanerFieldProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪CleanerFieldProviderTest extends UnitTestCase
29 {
33  protected ‪$subject;
34 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $languageServiceMock = $this->getMockBuilder(LanguageService::class)
42  ->setMethods(['sL'])
43  ->disableOriginalConstructor()
44  ->getMock();
45  $languageServiceMock->expects(self::any())->method('sL')->willReturn('titleTest');
46  $this->subject = $this->getMockBuilder(CleanerFieldProvider::class)
47  ->setMethods(['getLanguageService', 'addMessage'])
48  ->getMock();
49  $this->subject->expects(self::any())->method('getLanguageService')->willReturn($languageServiceMock);
50  }
51 
56  protected function ‪getScheduleModuleControllerMock($mockedMethods = [])
57  {
58  $languageServiceMock = $this->getMockBuilder(LanguageService::class)
59  ->setMethods(['sL'])
60  ->disableOriginalConstructor()
61  ->getMock();
62  $languageServiceMock->expects(self::any())->method('sL')->willReturn('titleTest');
63 
64  $mockedMethods = array_merge(['getLanguageService'], $mockedMethods);
65  $scheduleModuleMock = $this->getMockBuilder(SchedulerModuleController::class)
66  ->setMethods($mockedMethods)
67  ->disableOriginalConstructor()
68  ->getMock();
69  $scheduleModuleMock->expects(self::any())->method('getLanguageService')->willReturn($languageServiceMock);
70 
71  return $scheduleModuleMock;
72  }
73 
78  {
79  return [
80  ['abc'],
81  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
82  [null],
83  [''],
84  [0],
85  ['1234abc']
86  ];
87  }
88 
94  public function ‪validateAdditionalFieldsLogsPeriodError($period)
95  {
96  $submittedData = [
97  'RecyclerCleanerPeriod' => $period,
98  'RecyclerCleanerTCA' => ['pages']
99  ];
100 
101  $scheduleModuleControllerMock = $this->‪getScheduleModuleControllerMock();
102  $this->subject->expects(self::atLeastOnce())
103  ->method('addMessage')
104  ->with(self::equalTo('titleTest'), ‪FlashMessage::ERROR);
105 
106  $this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock);
107  }
108 
113  {
114  return [
115  ['abc'],
116  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
117  [null],
118  [123]
119  ];
120  }
121 
127  public function ‪validateAdditionalFieldsLogsTableError($table)
128  {
129  $submittedData = [
130  'RecyclerCleanerPeriod' => 14,
131  'RecyclerCleanerTCA' => $table
132  ];
133 
134  $this->subject->validateAdditionalFields($submittedData, $this->‪getScheduleModuleControllerMock());
135  }
136 
141  {
142  $submittedData = [
143  'RecyclerCleanerPeriod' => 14,
144  'RecyclerCleanerTCA' => ['pages']
145  ];
146 
147  $scheduleModuleControllerMock = $this->‪getScheduleModuleControllerMock();
148  ‪$GLOBALS['TCA']['pages'] = ['foo' => 'bar'];
149  self::assertTrue($this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock));
150  }
151 
155  public function ‪saveAdditionalFieldsSavesFields()
156  {
157  $submittedData = [
158  'RecyclerCleanerPeriod' => 14,
159  'RecyclerCleanerTCA' => ['pages']
160  ];
161 
162  $taskMock = $this->getMockBuilder(CleanerTask::class)
163  ->disableOriginalConstructor()
164  ->getMock();
165 
166  $taskMock->expects(self::once())
167  ->method('setTcaTables')
168  ->with(self::equalTo(['pages']));
169 
170  $taskMock->expects(self::once())
171  ->method('setPeriod')
172  ->with(self::equalTo(14));
173 
174  $this->subject->saveAdditionalFields($submittedData, $taskMock);
175  }
176 }
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest
Definition: CleanerFieldProviderTest.php:29
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider
Definition: CleanerFieldProvider.php:30
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\saveAdditionalFieldsSavesFields
‪saveAdditionalFieldsSavesFields()
Definition: CleanerFieldProviderTest.php:154
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\validateAdditionalFieldsIsTrueIfValid
‪validateAdditionalFieldsIsTrueIfValid()
Definition: CleanerFieldProviderTest.php:139
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\getScheduleModuleControllerMock
‪PHPUnit Framework MockObject MockObject SchedulerModuleController getScheduleModuleControllerMock($mockedMethods=[])
Definition: CleanerFieldProviderTest.php:55
‪TYPO3\CMS\Recycler\Tests\Unit\Task
Definition: CleanerFieldProviderTest.php:16
‪TYPO3\CMS\Recycler\Task\CleanerTask
Definition: CleanerTask.php:29
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\validateAdditionalFieldsLogsTableError
‪validateAdditionalFieldsLogsTableError($table)
Definition: CleanerFieldProviderTest.php:126
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\$subject
‪CleanerFieldProvider $subject
Definition: CleanerFieldProviderTest.php:32
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\validateAdditionalFieldsLogsPeriodError
‪validateAdditionalFieldsLogsPeriodError($period)
Definition: CleanerFieldProviderTest.php:93
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\setUp
‪setUp()
Definition: CleanerFieldProviderTest.php:37
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\validateAdditionalFieldsLogsPeriodErrorDataProvider
‪array validateAdditionalFieldsLogsPeriodErrorDataProvider()
Definition: CleanerFieldProviderTest.php:76
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Recycler\Tests\Unit\Task\CleanerFieldProviderTest\validateAdditionalFieldsDataProvider
‪array validateAdditionalFieldsDataProvider()
Definition: CleanerFieldProviderTest.php:111