a023bc10e3569d3e28addcf9db337ea827b2894f
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Scheduler / FieldProviderTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
3
4 require_once __DIR__ . '/Fixtures/MockACommandController.php';
5 require_once __DIR__ . '/Fixtures/MockBCommandController.php';
6 require_once __DIR__ . '/Fixtures/MockCCommandController.php';
7
8 /***************************************************************
9 * Copyright notice
10 *
11 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
12 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
13 * All rights reserved
14 *
15 * This script is part of the TYPO3 project. The TYPO3 project is
16 * free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * The GNU General Public License can be found at
22 * http://www.gnu.org/copyleft/gpl.html.
23 * A copy is found in the textfile GPL.txt and important notices to the license
24 * from the author is found in LICENSE.txt distributed with these scripts.
25 *
26 *
27 * This script is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * This copyright notice MUST APPEAR in all copies of the script!
33 ***************************************************************/
34 /**
35 * FieldProvider Test Class
36 */
37 class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
38
39 /**
40 * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
41 */
42 protected $objectManager;
43
44 /**
45 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
46 */
47 protected $command1;
48
49 /**
50 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
51 */
52 protected $command2;
53
54 /**
55 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
56 */
57 protected $command3;
58
59 /**
60 * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager|\PHPUnit_Framework_MockObject_MockObject
61 */
62 protected $commandManager;
63
64 /**
65 * @var \TYPO3\CMS\Extbase\Scheduler\FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
66 */
67 protected $fieldProvider;
68
69 public function setUp() {
70 $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
71 $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('getAvailableCommands'));
72
73 $this->fieldProvider = $this->getAccessibleMock(
74 '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
75 array('dummy'),
76 array(),
77 '',
78 FALSE
79 );
80
81 $this->command1 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', 'FuncA'));
82 $this->command1->_set('objectManager', $this->objectManager);
83 $this->command1->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
84 $this->command1->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
85
86 $this->command2 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Acme\\Mypkg\\Command\\MockBCommandController', 'FuncB'));
87 $this->command2->_set('objectManager', $this->objectManager);
88 $this->command2->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
89 $this->command2->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
90
91 $this->command3 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Tx_Extbase_Command_MockCCommandController', 'FuncC'));
92 $this->command3->_set('objectManager', $this->objectManager);
93 $this->command3->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
94 $this->command3->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
95
96 $this->commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($this->command1, $this->command2, $this->command3)));
97
98 $this->fieldProvider->_set('objectManager', $this->objectManager);
99 $this->fieldProvider->_set('commandManager', $this->commandManager);
100 $this->fieldProvider->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
101 }
102
103 /**
104 * @test
105 * @author Stefan Neufeind <info@speedpartner.de>
106 */
107 public function getCommandControllerActionFieldFetchesCorrectClassNames() {
108 $actualResult = $this->fieldProvider->_call('getCommandControllerActionField', array());
109 $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
110 $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
111 $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
112 }
113
114 /**
115 * @test
116 * @author Stefan Neufeind <info@speedpartner.de>
117 */
118 public function constructResolvesExtensionnameFromNamespaced() {
119 $className = uniqid('DummyController');
120 eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
121 $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
122 $mockController = new $classNameNamespaced();
123 $expectedResult = 'Extbase';
124 $actualResult = $mockController->getExtensionName();
125 $this->assertSame($expectedResult, $actualResult);
126 }
127
128 /**
129 * @test
130 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
131 */
132 public function validateAdditionalFieldsReturnsTrue() {
133 $submittedData = array();
134 $this->assertTrue($this->fieldProvider->validateAdditionalFields($submittedData, new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController()));
135 }
136
137 /**
138 * @test
139 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
140 */
141 public function getAdditionalFieldsRendersRightHtml() {
142 $expectedAdditionalFields = array(
143 'action' => array(
144 'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
145 . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
146 . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
147 . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
148 . '</select>',
149 'label' => 'CommandController Command. <em>Save and reopen to define command arguments</em>'
150 ),
151 'description' => array(
152 'code' => '',
153 'label' => '<strong></strong>'
154 ),
155 'arg' => array(
156 'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
157 'label' => 'Argument: arg. <em>A not required argument</em>'
158 )
159 );
160
161 $taskInfo = array();
162 $task = new \TYPO3\CMS\Extbase\Scheduler\Task();
163 $task->setCommandIdentifier($this->command1->getCommandIdentifier());
164 $schedulerModule = new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController();
165
166 $this->assertEquals($expectedAdditionalFields, $this->fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
167 }
168 }
169
170 ?>