[TASK] Merge submodule linkvalidator into core
[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 $this->controller = $this->getAccessibleMock('TYPO3\CMS\Extbase\Tests\MockACommandController', array('dummy'));
69 $this->controller->injectReflectionService($this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
70 $this->controller->injectObjectManager($this->objectManager);
71
72 $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\CMS\Extbase\Tests\MockACommandController', 'funcA');
73 $nullBackend = new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production');
74 $variableFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('foo', $nullBackend);
75
76 $this->cacheManager = $this->getMock('TYPO3\CMS\Core\Cache\CacheManager', array('dummy', 'getCache'));
77 $this->cacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
78 $GLOBALS['typo3CacheManager'] = $this->cacheManager;
79
80 $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
81 $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('dummy', 'getCommandByIdentifier'));
82 $this->configurationManager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
83
84 $this->configurationManager
85 ->expects($this->once())
86 ->method('getConfiguration')
87 ->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
88 ->will($this->returnValue(array()));
89
90 $this->commandManager
91 ->expects($this->any())
92 ->method('getCommandByIdentifier')
93 ->will($this->returnValue($command));
94 }
95
96 /**
97 * @test
98 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
99 */
100 public function executeDispatchesTheRightCommandControllerAndCommandAction() {
101 $dispatcher = $this->getMock('TYPO3\CMS\Extbase\Mvc\Dispatcher', array('resolveController'), array($this->objectManager));
102 $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($this->controller));
103 $dispatcher->injectSignalSlotDispatcher($this->objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'));
104
105 $this->taskExecuter = $this->getAccessibleMock('TYPO3\CMS\Extbase\Scheduler\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
106 $this->taskExecuter->expects($this->any())->method('getDispatcher')->will($this->returnValue($dispatcher));
107 $this->taskExecuter->injectObjectManager($this->objectManager);
108 $this->taskExecuter->injectCommandManager($this->commandManager);
109 $this->taskExecuter->injectConfigurationManager($this->configurationManager);
110 $this->taskExecuter->initializeObject();
111
112 /** @var $task \TYPO3\CMS\Extbase\Scheduler\Task|\PHPUnit_Framework_MockObject_MockObject */
113 $task = $this->getMock('TYPO3\CMS\Extbase\Scheduler\Task', array('dummy', 'getCommandIdentifier'));
114 $task->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:controller:command'));
115 $this->taskExecuter->execute($task);
116
117 $this->assertSame('Foo', $this->taskExecuter->_get('response')->getContent());
118 }
119 }
120
121 ?>