TYPO3  7.6
CleanerFieldProviderTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recycler\Tests\Unit\Task;
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\CMS\Core\Tests\UnitTestCase
27 {
31  protected $subject = null;
32 
36  protected function setUp()
37  {
38  $languageServiceMock = $this->getMock(LanguageService::class, array('sL'), array(), '', false);
39  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
40  $this->subject = $this->getMock(CleanerFieldProvider::class, array('getLanguageService'));
41  $this->subject->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
42  }
43 
48  protected function getScheduleModuleControllerMock($mockedMethods = array())
49  {
50  $languageServiceMock = $this->getMock(LanguageService::class, array('sL'), array(), '', false);
51  $languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
52 
53  $mockedMethods = array_merge(array('getLanguageService'), $mockedMethods);
54  $scheduleModuleMock = $this->getMock(SchedulerModuleController::class, $mockedMethods, array(), '', false);
55  $scheduleModuleMock->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
56 
57  return $scheduleModuleMock;
58  }
59 
64  {
65  return array(
66  array('abc'),
67  array($this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()),
68  array(null),
69  array(''),
70  array(0),
71  array('1234abc')
72  );
73  }
74 
80  public function validateAdditionalFieldsLogsPeriodError($period)
81  {
82  $submittedData = array(
83  'RecyclerCleanerPeriod' => $period,
84  'RecyclerCleanerTCA' => array('pages')
85  );
86 
87  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock(array('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 array(
101  array('abc'),
102  array($this->getMockBuilder(CleanerTask::class)->disableOriginalConstructor()->getMock()),
103  array(null),
104  array(123)
105  );
106  }
107 
114  {
115  $submittedData = array(
116  'RecyclerCleanerPeriod' => 14,
117  'RecyclerCleanerTCA' => $table
118  );
119 
120  $this->subject->validateAdditionalFields($submittedData, $this->getScheduleModuleControllerMock(['addMessage']));
121  }
122 
127  {
128  $submittedData = array(
129  'RecyclerCleanerPeriod' => 14,
130  'RecyclerCleanerTCA' => array('pages')
131  );
132 
133  $scheduleModuleControllerMock = $this->getScheduleModuleControllerMock();
134  $GLOBALS['TCA']['pages'] = array('foo' => 'bar');
135  $this->assertTrue($this->subject->validateAdditionalFields($submittedData, $scheduleModuleControllerMock));
136  }
137 
142  {
143  $submittedData = array(
144  'RecyclerCleanerPeriod' => 14,
145  'RecyclerCleanerTCA' => array('pages')
146  );
147 
148  $taskMock = $this->getMock(CleanerTask::class);
149 
150  $taskMock->expects($this->once())
151  ->method('setTcaTables')
152  ->with($this->equalTo(array('pages')));
153 
154  $taskMock->expects($this->once())
155  ->method('setPeriod')
156  ->with($this->equalTo(14));
157 
158  $this->subject->saveAdditionalFields($submittedData, $taskMock);
159  }
160 }