TYPO3 CMS  TYPO3_7-6
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 
27 {
31  protected $subject = null;
32 
36  protected function setUp()
37  {
38  $languageServiceMock = $this->getMock(LanguageService::class, ['sL'], [], '', false);
39  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
40  $this->subject = $this->getMock(CleanerFieldProvider::class, ['getLanguageService']);
41  $this->subject->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
42  }
43 
48  protected function getScheduleModuleControllerMock($mockedMethods = [])
49  {
50  $languageServiceMock = $this->getMock(LanguageService::class, ['sL'], [], '', false);
51  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
52 
53  $mockedMethods = array_merge(['getLanguageService'], $mockedMethods);
54  $scheduleModuleMock = $this->getMock(SchedulerModuleController::class, $mockedMethods, [], '', false);
55  $scheduleModuleMock->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
56 
57  return $scheduleModuleMock;
58  }
59 
64  {
65  return [
66  ['abc'],
67  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
68  [null],
69  [''],
70  [0],
71  ['1234abc']
72  ];
73  }
74 
80  public function validateAdditionalFieldsLogsPeriodError($period)
81  {
82  $submittedData = [
83  'RecyclerCleanerPeriod' => $period,
84  'RecyclerCleanerTCA' => ['pages']
85  ];
86 
87  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock(['addMessage']);
88  $scheduleModuleControllerMock->expects($this->atLeastOnce())
89  ->method('addMessage')
90  ->with($this->equalTo('titleTest'), FlashMessage::ERROR);
91 
92  $this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock);
93  }
94 
99  {
100  return [
101  ['abc'],
102  [$this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()],
103  [null],
104  [123]
105  ];
106  }
107 
114  {
115  $submittedData = [
116  'RecyclerCleanerPeriod' => 14,
117  'RecyclerCleanerTCA' => $table
118  ];
119 
120  $this->subject->validateAdditionalFields($submittedData, $this->getScheduleModuleControllerMock(['addMessage']));
121  }
122 
127  {
128  $submittedData = [
129  'RecyclerCleanerPeriod' => 14,
130  'RecyclerCleanerTCA' => ['pages']
131  ];
132 
133  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock();
134  $GLOBALS['TCA']['pages'] = ['foo' => 'bar'];
135  $this->assertTrue($this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock));
136  }
137 
142  {
143  $submittedData = [
144  'RecyclerCleanerPeriod' => 14,
145  'RecyclerCleanerTCA' => ['pages']
146  ];
147 
148  $taskMock = $this->getMock(CleanerTask::class);
149 
150  $taskMock->expects($this->once())
151  ->method('setTcaTables')
152  ->with($this->equalTo(['pages']));
153 
154  $taskMock->expects($this->once())
155  ->method('setPeriod')
156  ->with($this->equalTo(14));
157 
158  $this->subject->saveAdditionalFields($submittedData, $taskMock);
159  }
160 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']