TYPO3 CMS  TYPO3_8-7
FieldProviderTest.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 
24 
28 class FieldProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
33  public function getCommandControllerActionFieldFetchesCorrectClassNames()
34  {
35 
37  $command1 = $this->getAccessibleMock(Command::class, [], [], '', false);
38  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false));
39  $command1->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
40  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
41  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
42  $command1->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
43 
45  $command2 = $this->getAccessibleMock(Command::class, [], [], '', false);
46  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false));
47  $command2->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
48  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
49  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
50  $command2->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
51 
53  $command3 = $this->getAccessibleMock(Command::class, [], [], '', false);
54  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false));
55  $command3->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
56  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
57  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
58  $command3->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
59 
61  $commandManager = $this->getMockBuilder(CommandManager::class)
62  ->setMethods(['getAvailableCommands'])
63  ->getMock();
64  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2, $command3]));
65 
67  $fieldProvider = $this->getAccessibleMock(
68  FieldProvider::class,
69  ['getActionLabel'],
70  [],
71  '',
72  false
73  );
74  $fieldProvider->_set('commandManager', $commandManager);
75  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
76  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
77  $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
78  $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
79  $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
80  }
81 
85  public function getCommandControllerActionFieldSkipsInternalCommands()
86  {
88  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
89  $command->method('isInternal')->will($this->returnValue(true));
90  $command->method('isCliOnly')->will($this->returnValue(false));
91  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
92  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
93  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
94 
96  $commandManager = $this->getMockBuilder(CommandManager::class)
97  ->setMethods(['getAvailableCommands'])
98  ->getMock();
99  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
100 
102  $fieldProvider = $this->getAccessibleMock(
103  FieldProvider::class,
104  ['getActionLabel'],
105  [],
106  '',
107  false
108  );
109  $fieldProvider->_set('commandManager', $commandManager);
110  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
111  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
112  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
113  }
114 
118  public function getCommandControllerActionFieldSkipsCliOnlyCommands()
119  {
121  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
122  $command->method('isInternal')->will($this->returnValue(false));
123  $command->method('isCliOnly')->will($this->returnValue(true));
124  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
125  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
126  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
127 
129  $commandManager = $this->getMockBuilder(CommandManager::class)
130  ->setMethods(['getAvailableCommands'])
131  ->getMock();
132  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
133 
135  $fieldProvider = $this->getAccessibleMock(
136  FieldProvider::class,
137  ['getActionLabel'],
138  [],
139  '',
140  false
141  );
142  $fieldProvider->_set('commandManager', $commandManager);
143  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
144  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
145  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
146  }
147 
152  {
153  $mockController = new DummyController();
154  $expectedResult = 'Extbase';
155  $actualResult = $mockController->getExtensionName();
156  $this->assertSame($expectedResult, $actualResult);
157  }
158 
162  public function validateAdditionalFieldsReturnsTrue()
163  {
165  $fieldProvider = $this->getAccessibleMock(
166  FieldProvider::class,
167  ['dummy'],
168  [],
169  '',
170  false
171  );
172  $submittedData = [];
174  $schedulerModule = $this->createMock(SchedulerModuleController::class);
175  $this->assertTrue($fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
176  }
177 
181  public function getAdditionalFieldsRendersRightHtml()
182  {
183  $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
184 
186  $command1 = $this->getAccessibleMock(Command::class, [], [], '', false);
187  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false));
188  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
189  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
190  $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
191  $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue([]));
192 
194  $command2 = $this->getAccessibleMock(Command::class, [], [], '', false);
195  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false));
196  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
197  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
198  $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
199 
201  $command3 = $this->getAccessibleMock(Command::class, [], [], '', false);
202  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false));
203  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
204  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
205  $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
206 
208  $commandManager = $this->getMockBuilder(CommandManager::class)
209  ->setMethods(['getAvailableCommands'])
210  ->getMock();
211  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2, $command3]));
212 
214  $fieldProvider = $this->getAccessibleMock(
215  FieldProvider::class,
216  ['getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'],
217  [],
218  '',
219  false
220  );
221  $fieldProvider->_set('commandManager', $commandManager);
222  $actionLabel = 'action label string';
223  $argumentLabel = 'argument label string';
224  $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
225  $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
226  $argArray['arg'] = [
227  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
228  'label' => $argumentLabel
229  ];
230  $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray));
231  $expectedAdditionalFields = [
232  'action' => [
233  'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
234  . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
235  . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
236  . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
237  . '</select>',
238  'label' => $actionLabel
239  ],
240  'description' => [
241  'code' => '',
242  'label' => '<strong></strong>'
243  ],
244  'arg' => [
245  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
246  'label' => $argumentLabel
247  ]
248  ];
249 
250  $taskInfo = [];
252  $task = new Task();
253  $task->setCommandIdentifier($command1->getCommandIdentifier());
255  $schedulerModule = $this->createMock(SchedulerModuleController::class);
256 
257  $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
258  }
259 }