[TASK] Use name-resolution instead of strings where possible: 3
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class TaskTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Scheduler\Task|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
24 */
25 protected $task;
26
27 /**
28 * @var \TYPO3\CMS\Extbase\Scheduler\TaskExecutor|\PHPUnit_Framework_MockObject_MockObject
29 */
30 protected $taskExecutor;
31
32 public function setUp() {
33 $this->taskExecutor = $this->getMock(\TYPO3\CMS\Extbase\Scheduler\TaskExecutor::class, array('execute'), array(), '', FALSE);
34 $this->task = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Scheduler\Task::class, array('logException', '__wakeup'), array(), '', FALSE);
35 }
36
37 /**
38 * @test
39 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
40 */
41 public function executeCallsLogExceptionOnCaughtException() {
42 $this->taskExecutor->expects($this->once())->method('execute')->will($this->throwException(new \Exception()));
43 $this->task->_set('taskExecutor', $this->taskExecutor);
44 $this->task->expects($this->once())->method('logException');
45 $this->task->execute();
46 }
47
48 /**
49 * @test
50 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
51 */
52 public function executeReturnsTrueIfNoExceptionIsCaught() {
53 $this->task->_set('taskExecutor', $this->taskExecutor);
54 $this->assertTrue($this->task->execute());
55 }
56
57 /**
58 * @test
59 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
60 */
61 public function setCommandIdentifierSetsCommandIdentifierCorrectly() {
62 $this->task->setCommandIdentifier('Foo');
63 $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
64 }
65
66 /**
67 * @test
68 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
69 */
70 public function getCommandIdentifierReturnsCorrectCommandIdentifier() {
71 $this->task->_set('commandIdentifier', 'Foo');
72 $this->assertSame('Foo', $this->task->getCommandIdentifier());
73 }
74
75 /**
76 * @test
77 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
78 */
79 public function setArgumentsSetsArgumentsCorrectly() {
80 $this->task->setArguments(array('Foo'));
81 $this->assertSame(array('Foo'), $this->task->_get('arguments'));
82 }
83
84 /**
85 * @test
86 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
87 */
88 public function getArgumentsReturnsCorrectArguments() {
89 $this->task->_set('arguments', array('Foo'));
90 $this->assertSame(array('Foo'), $this->task->getArguments());
91 }
92
93 /**
94 * @test
95 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
96 */
97 public function setDefaultsSetsDefaultsCorrectly() {
98 $this->task->setDefaults(array('Foo'));
99 $this->assertSame(array('Foo'), $this->task->_get('defaults'));
100 }
101
102 /**
103 * @test
104 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
105 */
106 public function getDefaultsReturnsCorrectDefaults() {
107 $this->task->_set('defaults', array('Foo'));
108 $this->assertSame(array('Foo'), $this->task->getDefaults());
109 }
110
111 /**
112 * @test
113 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
114 */
115 public function addDefaultValueAddsDefaultToDefaults() {
116 $defaults = array('foo' => 'bar');
117 $this->task->_set('defaults', $defaults);
118
119 $defaults['baz'] = 'qux';
120 $this->task->addDefaultValue('baz', 'qux');
121
122 $this->assertSame($defaults, $this->task->getDefaults());
123 }
124
125 /**
126 * @test
127 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
128 */
129 public function addDefaultValueConvertsBooleanValuesToInteger() {
130 $defaults = array('foo' => 'bar');
131 $this->task->_set('defaults', $defaults);
132
133 $defaults['baz'] = 1;
134 $this->task->addDefaultValue('baz', TRUE);
135
136 $this->assertSame($defaults, $this->task->getDefaults());
137 }
138
139 /**
140 * @test
141 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
142 */
143 public function getAdditionalInformationRespectsArguments() {
144 $this->task->_set('commandIdentifier', 'foo');
145 $this->task->_set('defaults', array('bar' => 'baz'));
146 $this->task->_set('arguments', array('qux' => 'quux'));
147
148 $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation());
149 }
150 }