[TASK] Disable scheduler-tests if EXT:scheduler not loaded
[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 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
71 $this->markTestSkipped('Tests need EXT:scheduler loaded.');
72 }
73 $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
74 $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('getAvailableCommands'));
75
76 $this->fieldProvider = $this->getAccessibleMock(
77 '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
78 array('dummy'),
79 array(),
80 '',
81 FALSE
82 );
83
84 $this->command1 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', 'FuncA'));
85 $this->command1->_set('objectManager', $this->objectManager);
86 $this->command1->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
87 $this->command1->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
88
89 $this->command2 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Acme\\Mypkg\\Command\\MockBCommandController', 'FuncB'));
90 $this->command2->_set('objectManager', $this->objectManager);
91 $this->command2->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
92 $this->command2->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
93
94 $this->command3 = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Tx_Extbase_Command_MockCCommandController', 'FuncC'));
95 $this->command3->_set('objectManager', $this->objectManager);
96 $this->command3->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
97 $this->command3->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
98
99 $this->commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($this->command1, $this->command2, $this->command3)));
100
101 $this->fieldProvider->_set('objectManager', $this->objectManager);
102 $this->fieldProvider->_set('commandManager', $this->commandManager);
103 $this->fieldProvider->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
104 }
105
106 /**
107 * @test
108 * @author Stefan Neufeind <info@speedpartner.de>
109 */
110 public function getCommandControllerActionFieldFetchesCorrectClassNames() {
111 $actualResult = $this->fieldProvider->_call('getCommandControllerActionField', array());
112 $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
113 $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
114 $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
115 }
116
117 /**
118 * @test
119 * @author Stefan Neufeind <info@speedpartner.de>
120 */
121 public function constructResolvesExtensionnameFromNamespaced() {
122 $className = uniqid('DummyController');
123 eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
124 $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
125 $mockController = new $classNameNamespaced();
126 $expectedResult = 'Extbase';
127 $actualResult = $mockController->getExtensionName();
128 $this->assertSame($expectedResult, $actualResult);
129 }
130
131 /**
132 * @test
133 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
134 */
135 public function validateAdditionalFieldsReturnsTrue() {
136 $submittedData = array();
137 $this->assertTrue($this->fieldProvider->validateAdditionalFields($submittedData, new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController()));
138 }
139
140 /**
141 * @test
142 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
143 */
144 public function getAdditionalFieldsRendersRightHtml() {
145 $expectedAdditionalFields = array(
146 'action' => array(
147 'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
148 . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
149 . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
150 . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
151 . '</select>',
152 'label' => 'CommandController Command. <em>Save and reopen to define command arguments</em>'
153 ),
154 'description' => array(
155 'code' => '',
156 'label' => '<strong></strong>'
157 ),
158 'arg' => array(
159 'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
160 'label' => 'Argument: arg. <em>A not required argument</em>'
161 )
162 );
163
164 $taskInfo = array();
165 $task = new \TYPO3\CMS\Extbase\Scheduler\Task();
166 $task->setCommandIdentifier($this->command1->getCommandIdentifier());
167 $schedulerModule = new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController();
168
169 $this->assertEquals($expectedAdditionalFields, $this->fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
170 }
171 }
172
173 ?>