[TASK] Removes eval() in array utility unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Scheduler / FieldProviderTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
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
17 use TYPO3\CMS\Extbase\Tests\Fixture\DummyController;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19 use TYPO3\CMS\Extbase\Mvc\Cli\Command;
20 use TYPO3\CMS\Extbase\Mvc\Cli\CommandManager;
21 use TYPO3\CMS\Extbase\Scheduler\FieldProvider;
22 use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
23 use TYPO3\CMS\Extbase\Tests\MockACommandController;
24 use TYPO3\CMS\Extbase\Scheduler\Task;
25
26 /**
27 * Test case
28 */
29 class FieldProviderTest extends UnitTestCase {
30
31 /**
32 * @test
33 */
34 public function getCommandControllerActionFieldFetchesCorrectClassNames() {
35
36 /** @var Command|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $command1 */
37 $command1 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
38 $command1->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
39 $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
40 $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
41 $command1->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
42
43 /** @var Command|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $command2 */
44 $command2 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
45 $command2->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
46 $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
47 $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
48 $command2->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
49
50 /** @var Command|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $command3 */
51 $command3 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
52 $command3->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
53 $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
54 $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
55 $command3->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
56
57 /** @var CommandManager|\PHPUnit_Framework_MockObject_MockObject $commandManager */
58 $commandManager = $this->getMock(CommandManager::class, array('getAvailableCommands'));
59 $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($command1, $command2, $command3)));
60
61 /** @var FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fieldProvider */
62 $fieldProvider = $this->getAccessibleMock(
63 FieldProvider::class,
64 array('getActionLabel'),
65 array(),
66 '',
67 FALSE
68 );
69 $fieldProvider->_set('commandManager', $commandManager);
70 $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
71 $actualResult = $fieldProvider->_call('getCommandControllerActionField', array());
72 $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
73 $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
74 $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
75 }
76
77 /**
78 * @test
79 * @author Stefan Neufeind <info@speedpartner.de>
80 */
81 public function constructResolvesExtensionNameFromNamespaced() {
82 $mockController = new DummyController();
83 $expectedResult = 'Extbase';
84 $actualResult = $mockController->getExtensionName();
85 $this->assertSame($expectedResult, $actualResult);
86 }
87
88 /**
89 * @test
90 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
91 */
92 public function validateAdditionalFieldsReturnsTrue() {
93 /** @var FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fieldProvider */
94 $fieldProvider = $this->getAccessibleMock(
95 FieldProvider::class,
96 array('dummy'),
97 array(),
98 '',
99 FALSE
100 );
101 $submittedData = array();
102 /** @var SchedulerModuleController $schedulerModule */
103 $schedulerModule = $this->getMock(SchedulerModuleController::class, array(), array(), '', FALSE);
104 $this->assertTrue($fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
105 }
106
107 /**
108 * @test
109 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
110 */
111 public function getAdditionalFieldsRendersRightHtml() {
112 $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
113
114 /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command1 */
115 $command1 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
116 $command1->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
117 $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class));
118 $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
119 $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
120 $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue(array()));
121
122 /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command2 */
123 $command2 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
124 $command2->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
125 $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
126 $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
127 $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
128
129 /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command3 */
130 $command3 = $this->getAccessibleMock(Command::class, array(), array(), '', FALSE);
131 $command3->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
132 $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
133 $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
134 $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
135
136 /** @var CommandManager|\PHPUnit_Framework_MockObject_MockObject $commandManager */
137 $commandManager = $this->getMock(CommandManager::class, array('getAvailableCommands'));
138 $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($command1, $command2, $command3)));
139
140 /** @var FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fieldProvider */
141 $fieldProvider = $this->getAccessibleMock(
142 FieldProvider::class,
143 array('getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'),
144 array(),
145 '',
146 FALSE
147 );
148 $fieldProvider->_set('commandManager', $commandManager);
149 $actionLabel = 'action label string';
150 $argumentLabel = 'argument label string';
151 $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
152 $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
153 $argArray['arg'] = array(
154 'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
155 'label' => $argumentLabel
156 );
157 $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray));
158 $expectedAdditionalFields = array(
159 'action' => array(
160 'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
161 . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
162 . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
163 . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
164 . '</select>',
165 'label' => $actionLabel
166 ),
167 'description' => array(
168 'code' => '',
169 'label' => '<strong></strong>'
170 ),
171 'arg' => array(
172 'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
173 'label' => $argumentLabel
174 )
175 );
176
177 $taskInfo = array();
178 /** @var Task $task */
179 $task = new Task();
180 $task->setCommandIdentifier($command1->getCommandIdentifier());
181 /** @var SchedulerModuleController $schedulerModule */
182 $schedulerModule = $this->getMock(SchedulerModuleController::class, array(), array(), '', FALSE);
183
184 $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
185 }
186
187 }