[TASK] Disable scheduler-tests if EXT:scheduler not loaded
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Scheduler / TaskExecuterTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
3
4 require_once __DIR__ . '/Fixtures/MockACommandController.php';
5
6 /***************************************************************
7 * Copyright notice
8 *
9 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
10 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
11 * All rights reserved
12 *
13 * This script is part of the TYPO3 project. The TYPO3 project is
14 * free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * The GNU General Public License can be found at
20 * http://www.gnu.org/copyleft/gpl.html.
21 * A copy is found in the textfile GPL.txt and important notices to the license
22 * from the author is found in LICENSE.txt distributed with these scripts.
23 *
24 *
25 * This script is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * This copyright notice MUST APPEAR in all copies of the script!
31 ***************************************************************/
32 /**
33 * TaskExecutor Test Class
34 */
35 class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Mvc\Controller\CommandController|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
39 */
40 protected $controller;
41
42 /**
43 * @var \TYPO3\CMS\Core\Cache\CacheManager|\PHPUnit_Framework_MockObject_MockObject
44 */
45 protected $cacheManager;
46
47 /**
48 * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
49 */
50 protected $objectManager;
51
52 /**
53 * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager|\PHPUnit_Framework_MockObject_MockObject
54 */
55 protected $commandManager;
56
57 /**
58 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
59 */
60 protected $configurationManager;
61
62 /**
63 * @var \TYPO3\CMS\Extbase\Scheduler\TaskExecutor|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
64 */
65 protected $taskExecuter;
66
67 public function setUp() {
68 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
69 $this->markTestSkipped('Tests need EXT:scheduler loaded.');
70 }
71 $this->controller = $this->getAccessibleMock('TYPO3\CMS\Extbase\Tests\MockACommandController', array('dummy'));
72 $this->controller->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
73 $this->controller->_set('objectManager', $this->objectManager);
74
75 $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\CMS\Extbase\Tests\MockACommandController', 'funcA');
76 $nullBackend = new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production');
77 $variableFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('foo', $nullBackend);
78
79 $this->cacheManager = $this->getMock('TYPO3\CMS\Core\Cache\CacheManager', array('dummy', 'getCache'));
80 $this->cacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
81 $GLOBALS['typo3CacheManager'] = $this->cacheManager;
82
83 $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
84 $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('dummy', 'getCommandByIdentifier'));
85 $this->configurationManager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
86
87 $this->configurationManager
88 ->expects($this->once())
89 ->method('getConfiguration')
90 ->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
91 ->will($this->returnValue(array()));
92
93 $this->commandManager
94 ->expects($this->any())
95 ->method('getCommandByIdentifier')
96 ->will($this->returnValue($command));
97 }
98
99 /**
100 * @test
101 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
102 */
103 public function executeDispatchesTheRightCommandControllerAndCommandAction() {
104 $dispatcher = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Dispatcher', array('resolveController'), array($this->objectManager));
105 $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($this->controller));
106 $dispatcher->_set('signalSlotDispatcher', $this->objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'));
107
108 $this->taskExecuter = $this->getAccessibleMock('TYPO3\CMS\Extbase\Scheduler\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
109 $this->taskExecuter->expects($this->any())->method('getDispatcher')->will($this->returnValue($dispatcher));
110 $this->taskExecuter->_set('objectManager', $this->objectManager);
111 $this->taskExecuter->_set('commandManager', $this->commandManager);
112 $this->taskExecuter->_set('configurationManager', $this->configurationManager);
113 $this->taskExecuter->initializeObject();
114
115 /** @var $task \TYPO3\CMS\Extbase\Scheduler\Task|\PHPUnit_Framework_MockObject_MockObject */
116 $task = $this->getMock('TYPO3\CMS\Extbase\Scheduler\Task', array('dummy', 'getCommandIdentifier'));
117 $task->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:controller:command'));
118 $this->taskExecuter->execute($task);
119
120 $this->assertSame('Foo', $this->taskExecuter->_get('response')->getContent());
121 }
122 }
123
124 ?>