TYPO3 CMS  TYPO3_8-7
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 
26 class CleanerFieldProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $subject = null;
32 
36  protected function setUp()
37  {
38  $languageServiceMock = $this->getMockBuilder(LanguageService::class)
39  ->setMethods(['sL'])
40  ->disableOriginalConstructor()
41  ->getMock();
42  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
43  $this->subject = $this->getMockBuilder(CleanerFieldProvider::class)
44  ->setMethods(['getLanguageService'])
45  ->getMock();
46  $this->subject->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
47  }
48 
53  protected function getScheduleModuleControllerMock($mockedMethods = [])
54  {
55  $languageServiceMock = $this->getMockBuilder(LanguageService::class)
56  ->setMethods(['sL'])
57  ->disableOriginalConstructor()
58  ->getMock();
59  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
60 
61  $mockedMethods = array_merge(['getLanguageService'], $mockedMethods);
62  $scheduleModuleMock = $this->getMockBuilder(SchedulerModuleController::class)
63  ->setMethods($mockedMethods)
64  ->disableOriginalConstructor()
65  ->getMock();
66  $scheduleModuleMock->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
67 
68  return $scheduleModuleMock;
69  }
70 
75  {
76  return [
77  ['abc'],
78  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
79  [null],
80  [''],
81  [0],
82  ['1234abc']
83  ];
84  }
85 
91  public function validateAdditionalFieldsLogsPeriodError($period)
92  {
93  $submittedData = [
94  'RecyclerCleanerPeriod' => $period,
95  'RecyclerCleanerTCA' => ['pages']
96  ];
97 
98  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock(['addMessage']);
99  $scheduleModuleControllerMock->expects($this->atLeastOnce())
100  ->method('addMessage')
101  ->with($this->equalTo('titleTest'), FlashMessage::ERROR);
102 
103  $this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock);
104  }
105 
110  {
111  return [
112  ['abc'],
113  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
114  [null],
115  [123]
116  ];
117  }
118 
125  {
126  $submittedData = [
127  'RecyclerCleanerPeriod' => 14,
128  'RecyclerCleanerTCA' => $table
129  ];
130 
131  $this->subject->validateAdditionalFields($submittedData, $this->getScheduleModuleControllerMock(['addMessage']));
132  }
133 
138  {
139  $submittedData = [
140  'RecyclerCleanerPeriod' => 14,
141  'RecyclerCleanerTCA' => ['pages']
142  ];
143 
144  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock();
145  $GLOBALS['TCA']['pages'] = ['foo' => 'bar'];
146  $this->assertTrue($this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock));
147  }
148 
153  {
154  $submittedData = [
155  'RecyclerCleanerPeriod' => 14,
156  'RecyclerCleanerTCA' => ['pages']
157  ];
158 
159  $taskMock = $this->getMockBuilder(CleanerTask::class)->getMock();
160 
161  $taskMock->expects($this->once())
162  ->method('setTcaTables')
163  ->with($this->equalTo(['pages']));
164 
165  $taskMock->expects($this->once())
166  ->method('setPeriod')
167  ->with($this->equalTo(14));
168 
169  $this->subject->saveAdditionalFields($submittedData, $taskMock);
170  }
171 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']