[TASK] Disable scheduler-tests if EXT:scheduler not loaded
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Scheduler / TaskTest.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 textfile 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 * Testcase for the Task object
32 *
33 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
34 */
35 class TaskTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Scheduler\Task|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
39 */
40 protected $task;
41
42 /**
43 * @var \TYPO3\CMS\Extbase\Scheduler\TaskExecutor|\PHPUnit_Framework_MockObject_MockObject
44 */
45 protected $taskExecutor;
46
47 public function setUp() {
48 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
49 $this->markTestSkipped('Tests need EXT:scheduler loaded.');
50 }
51 $this->taskExecutor = $this->getMock('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor', array('execute'));
52 $this->task = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Scheduler\\Task', array('logException'), array(), '', FALSE);
53 $this->task->_set('objectManager', \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'));
54 $this->task->_set('commandManager', \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager'));
55 }
56
57 /**
58 * @test
59 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
60 */
61 public function executeCallsLogExceptionOnCaughtException() {
62 $this->taskExecutor->expects($this->once())->method('execute')->will($this->throwException(new \Exception()));
63 $this->task->_set('taskExecutor', $this->taskExecutor);
64 $this->task->expects($this->once())->method('logException');
65 $this->task->execute();
66 }
67
68 /**
69 * @test
70 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
71 */
72 public function executeReturnsTrueIfNoExceptionIsCaught() {
73 $this->task->_set('taskExecutor', $this->taskExecutor);
74 $this->assertTrue($this->task->execute());
75 }
76
77 /**
78 * @test
79 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
80 */
81 public function setCommandIdentifierSetsCommandIdentifierCorrectly() {
82 $this->task->setCommandIdentifier('Foo');
83 $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
84 }
85
86 /**
87 * @test
88 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
89 */
90 public function getCommandIdentifierReturnsCorrectCommandIdentifier() {
91 $this->task->_set('commandIdentifier', 'Foo');
92 $this->assertSame('Foo', $this->task->getCommandIdentifier());
93 }
94
95 /**
96 * @test
97 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
98 */
99 public function setArgumentsSetsArgumentsCorrectly() {
100 $this->task->setArguments(array('Foo'));
101 $this->assertSame(array('Foo'), $this->task->_get('arguments'));
102 }
103
104 /**
105 * @test
106 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
107 */
108 public function getArgumentsReturnsCorrectArguments() {
109 $this->task->_set('arguments', array('Foo'));
110 $this->assertSame(array('Foo'), $this->task->getArguments());
111 }
112
113 /**
114 * @test
115 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
116 */
117 public function setDefaultsSetsDefaultsCorrectly() {
118 $this->task->setDefaults(array('Foo'));
119 $this->assertSame(array('Foo'), $this->task->_get('defaults'));
120 }
121
122 /**
123 * @test
124 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
125 */
126 public function getDefaultsReturnsCorrectDefaults() {
127 $this->task->_set('defaults', array('Foo'));
128 $this->assertSame(array('Foo'), $this->task->getDefaults());
129 }
130
131 /**
132 * @test
133 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
134 */
135 public function addDefaultValueAddsDefaultToDefaults() {
136 $defaults = array('foo' => 'bar');
137 $this->task->_set('defaults', $defaults);
138
139 $defaults['baz'] = 'qux';
140 $this->task->addDefaultValue('baz', 'qux');
141
142 $this->assertSame($defaults, $this->task->getDefaults());
143 }
144
145 /**
146 * @test
147 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
148 */
149 public function addDefaultValueConvertsBooleanValuesToInteger() {
150 $defaults = array('foo' => 'bar');
151 $this->task->_set('defaults', $defaults);
152
153 $defaults['baz'] = 1;
154 $this->task->addDefaultValue('baz', TRUE);
155
156 $this->assertSame($defaults, $this->task->getDefaults());
157 }
158
159 /**
160 * @test
161 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
162 */
163 public function getAdditionalInformationRespectsArguments() {
164 $this->task->_set('commandIdentifier', 'foo');
165 $this->task->_set('defaults', array('bar' => 'baz'));
166 $this->task->_set('arguments', array('qux' => 'quux'));
167
168 $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation());
169 }
170 }
171
172 ?>