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