‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FieldProviderTest extends UnitTestCase
30 {
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  $commandManager = $this->getMockBuilder(CommandManager::class)
55  ->setMethods(['getAvailableCommands'])
56  ->getMock();
57  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2]));
58 
60  $fieldProvider = $this->getAccessibleMock(
61  FieldProvider::class,
62  ['getActionLabel'],
63  [],
64  '',
65  false
66  );
67  $fieldProvider->_set('commandManager', $commandManager);
68  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
69  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
70  $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
71  $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
72  }
73 
78  {
80  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
81  $command->method('isInternal')->will($this->returnValue(true));
82  $command->method('isCliOnly')->will($this->returnValue(false));
83  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
84  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
85  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
86 
88  $commandManager = $this->getMockBuilder(CommandManager::class)
89  ->setMethods(['getAvailableCommands'])
90  ->getMock();
91  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
92 
94  $fieldProvider = $this->getAccessibleMock(
95  FieldProvider::class,
96  ['getActionLabel'],
97  [],
98  '',
99  false
100  );
101  $fieldProvider->_set('commandManager', $commandManager);
102  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
103  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
104  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
105  }
106 
111  {
113  $command = $this->getAccessibleMock(Command::class, [], [], '', false);
114  $command->method('isInternal')->will($this->returnValue(false));
115  $command->method('isCliOnly')->will($this->returnValue(true));
116  $command->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
117  $command->method('getControllerCommandName')->will($this->returnValue('FuncA'));
118  $command->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
119 
121  $commandManager = $this->getMockBuilder(CommandManager::class)
122  ->setMethods(['getAvailableCommands'])
123  ->getMock();
124  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command]));
125 
127  $fieldProvider = $this->getAccessibleMock(
128  FieldProvider::class,
129  ['getActionLabel'],
130  [],
131  '',
132  false
133  );
134  $fieldProvider->_set('commandManager', $commandManager);
135  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
136  $actualResult = $fieldProvider->_call('getCommandControllerActionField', []);
137  $this->assertNotContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
138  }
139 
144  {
145  $mockController = new ‪DummyController();
146  $expectedResult = 'Extbase';
147  $actualResult = $mockController->getExtensionName();
148  $this->assertSame($expectedResult, $actualResult);
149  }
150 
155  {
157  $fieldProvider = $this->getAccessibleMock(
158  FieldProvider::class,
159  ['dummy'],
160  [],
161  '',
162  false
163  );
164  $submittedData = [];
166  $schedulerModule = $this->createMock(SchedulerModuleController::class);
167  $this->assertTrue($fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
168  }
169 
174  {
175  $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
176 
178  $command1 = $this->getAccessibleMock(Command::class, [], [], '', false);
179  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false));
180  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
181  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
182  $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
183  $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue([]));
184 
186  $command2 = $this->getAccessibleMock(Command::class, [], [], '', false);
187  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false));
188  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
189  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
190  $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
191 
193  $command3 = $this->getAccessibleMock(Command::class, [], [], '', false);
194  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false));
195  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
196  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
197  $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
198 
200  $commandManager = $this->getMockBuilder(CommandManager::class)
201  ->setMethods(['getAvailableCommands'])
202  ->getMock();
203  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue([$command1, $command2, $command3]));
204 
206  $fieldProvider = $this->getAccessibleMock(
207  FieldProvider::class,
208  ['getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'],
209  [],
210  '',
211  false
212  );
213  $fieldProvider->_set('commandManager', $commandManager);
214  $actionLabel = 'action label string';
215  $argumentLabel = 'argument label string';
216  $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
217  $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
218  $argArray['arg'] = [
219  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
220  'label' => $argumentLabel
221  ];
222  $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray));
223  $expectedAdditionalFields = [
224  'action' => [
225  'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
226  . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
227  . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
228  . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
229  . '</select>',
230  'label' => $actionLabel
231  ],
232  'description' => [
233  'code' => '',
234  'label' => '<strong></strong>'
235  ],
236  'arg' => [
237  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
238  'label' => $argumentLabel
239  ]
240  ];
241 
242  $taskInfo = [];
244  $task = new ‪Task();
245  $task->setCommandIdentifier($command1->getCommandIdentifier());
247  $schedulerModule = $this->createMock(SchedulerModuleController::class);
248 
249  $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
250  }
251 }
‪TYPO3\CMS\Extbase\Tests\Fixture\DummyController
Definition: DummyController.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\constructResolvesExtensionNameFromNamespaced
‪constructResolvesExtensionNameFromNamespaced()
Definition: FieldProviderTest.php:143
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\getAdditionalFieldsRendersRightHtml
‪getAdditionalFieldsRendersRightHtml()
Definition: FieldProviderTest.php:173
‪TYPO3\CMS\Extbase\Scheduler\Task
Definition: Task.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\validateAdditionalFieldsReturnsTrue
‪validateAdditionalFieldsReturnsTrue()
Definition: FieldProviderTest.php:154
‪TYPO3\CMS\Extbase\Tests\MockACommandController
Definition: MockACommandController.php:21
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\getCommandControllerActionFieldFetchesCorrectClassNames
‪getCommandControllerActionFieldFetchesCorrectClassNames()
Definition: FieldProviderTest.php:34
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:53
‪TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
Definition: CommandManager.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\getCommandControllerActionFieldSkipsInternalCommands
‪getCommandControllerActionFieldSkipsInternalCommands()
Definition: FieldProviderTest.php:77
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest
Definition: FieldProviderTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler
Definition: FieldProviderTest.php:2
‪TYPO3\CMS\Extbase\Mvc\Cli\Command
Definition: Command.php:25
‪TYPO3\CMS\Extbase\Scheduler\FieldProvider
Definition: FieldProvider.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\FieldProviderTest\getCommandControllerActionFieldSkipsCliOnlyCommands
‪getCommandControllerActionFieldSkipsCliOnlyCommands()
Definition: FieldProviderTest.php:110