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