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