TYPO3 CMS  TYPO3_7-6
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 
25 
30 {
34  public function getCommandControllerActionFieldFetchesCorrectClassNames()
35  {
36 
38  $command1 = $this->getAccessibleMock(Command::class, [], [], '', false);
39  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false));
40  $command1->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
41  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
42  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
43  $command1->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
44 
46  $command2 = $this->getAccessibleMock(Command::class, [], [], '', false);
47  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false));
48  $command2->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
49  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
50  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
51  $command2->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
52 
54  $command3 = $this->getAccessibleMock(Command::class, [], [], '', false);
55  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false));
56  $command3->expects($this->once())->method('isCliOnly')->will($this->returnValue(false));
57  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
58  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
59  $command3->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
60 
62  $commandManager = $this->getMock(CommandManager::class, ['getAvailableCommands']);
63  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2, $command3]));
64 
66  $fieldProvider = $this->getAccessibleMock(
67  FieldProvider::class,
68  ['getActionLabel'],
69  [],
70  '',
71  false
72  );
73  $fieldProvider->_set('commandManager', $commandManager);
74  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
75  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
76  $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
77  $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
78  $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
79  }
80 
84  public function getCommandControllerActionFieldSkipsInternalCommands()
85  {
87  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
88  $command->method('isInternal')->will($this->returnValue(true));
89  $command->method('isCliOnly')->will($this->returnValue(false));
90  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
91  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
92  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
93 
95  $commandManager = $this->getMock(CommandManager::class, ['getAvailableCommands']);
96  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
97 
99  $fieldProvider = $this->getAccessibleMock(
100  FieldProvider::class,
101  ['getActionLabel'],
102  [],
103  '',
104  false
105  );
106  $fieldProvider->_set('commandManager', $commandManager);
107  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
108  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
109  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
110  }
111 
115  public function getCommandControllerActionFieldSkipsCliOnlyCommands()
116  {
118  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
119  $command->method('isInternal')->will($this->returnValue(false));
120  $command->method('isCliOnly')->will($this->returnValue(true));
121  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
122  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
123  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
124 
126  $commandManager = $this->getMock(CommandManager::class, ['getAvailableCommands']);
127  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
128 
130  $fieldProvider = $this->getAccessibleMock(
131  FieldProvider::class,
132  ['getActionLabel'],
133  [],
134  '',
135  false
136  );
137  $fieldProvider->_set('commandManager', $commandManager);
138  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
139  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
140  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
141  }
142 
147  {
148  $mockController = new DummyController();
149  $expectedResult = 'Extbase';
150  $actualResult = $mockController->getExtensionName();
151  $this->assertSame($expectedResult, $actualResult);
152  }
153 
157  public function validateAdditionalFieldsReturnsTrue()
158  {
160  $fieldProvider = $this->getAccessibleMock(
161  FieldProvider::class,
162  ['dummy'],
163  [],
164  '',
165  false
166  );
167  $submittedData = [];
169  $schedulerModule = $this->getMock(SchedulerModuleController::class, [], [], '', false);
170  $this->assertTrue($fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
171  }
172 
176  public function getAdditionalFieldsRendersRightHtml()
177  {
178  $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
179 
181  $command1 = $this->getAccessibleMock(Command::class, [], [], '', false);
182  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false));
183  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
184  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
185  $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
186  $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue([]));
187 
189  $command2 = $this->getAccessibleMock(Command::class, [], [], '', false);
190  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false));
191  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
192  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
193  $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
194 
196  $command3 = $this->getAccessibleMock(Command::class, [], [], '', false);
197  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false));
198  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
199  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
200  $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
201 
203  $commandManager = $this->getMock(CommandManager::class, ['getAvailableCommands']);
204  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2, $command3]));
205 
207  $fieldProvider = $this->getAccessibleMock(
208  FieldProvider::class,
209  ['getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'],
210  [],
211  '',
212  false
213  );
214  $fieldProvider->_set('commandManager', $commandManager);
215  $actionLabel = 'action label string';
216  $argumentLabel = 'argument label string';
217  $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
218  $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
219  $argArray['arg'] = [
220  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
221  'label' => $argumentLabel
222  ];
223  $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray));
224  $expectedAdditionalFields = [
225  'action' => [
226  'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
227  . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
228  . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
229  . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
230  . '</select>',
231  'label' => $actionLabel
232  ],
233  'description' => [
234  'code' => '',
235  'label' => '<strong></strong>'
236  ],
237  'arg' => [
238  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
239  'label' => $argumentLabel
240  ]
241  ];
242 
243  $taskInfo = [];
245  $task = new Task();
246  $task->setCommandIdentifier($command1->getCommandIdentifier());
248  $schedulerModule = $this->getMock(SchedulerModuleController::class, [], [], '', false);
249 
250  $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
251  }
252 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)