[BUGFIX] Use same line endings in test as in function
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Cli / CommandTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli;
3
4 /* *
5 * This script belongs to the Extbase framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Extbase\Mvc\Cli\Command;
26 use TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition;
27 use TYPO3\CMS\Extbase\Object\ObjectManager;
28 use TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockCCommandController;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30
31 /**
32 * Test case
33 */
34 class CommandTest extends UnitTestCase
35 {
36 /**
37 * @var bool Reset singletons created by subject
38 */
39 protected $resetSingletonInstances = true;
40
41 /**
42 * @return array
43 */
44 public function commandIdentifiers()
45 {
46 return [
47
48 ['Tx\ExtensionKey\Command\CacheCommandController', 'flush', 'extension_key:cache:flush'],
49 ['Tx\Ext\Command\CookieCommandController', 'bake', 'ext:cookie:bake'],
50 ['Tx\OtherExtensionKey\Foo\Faa\Fuuum\Command\CoffeeCommandController', 'brew', 'other_extension_key:coffee:brew'],
51 ];
52 }
53
54 /**
55 * @test
56 * @dataProvider commandIdentifiers
57 * @param string $controllerClassName
58 * @param string $commandName
59 * @param string $expectedCommandIdentifier
60 */
61 public function constructRendersACommandIdentifierByTheGivenControllerAndCommandName($controllerClassName, $commandName, $expectedCommandIdentifier)
62 {
63 $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command($controllerClassName, $commandName);
64 $this->assertEquals($expectedCommandIdentifier, $command->getCommandIdentifier());
65 }
66
67 /**
68 * @return array
69 */
70 public function invalidCommandClassNames()
71 {
72 return [
73 [''],
74 // CommandClassName must not be empty
75 ['Foo']
76 ];
77 }
78
79 /**
80 * @test
81 * @dataProvider invalidCommandClassNames
82 * @param string $controllerClassName
83 */
84 public function constructThrowsExceptionIfCommandClassNameIsInvalid($controllerClassName)
85 {
86 $this->expectException(\InvalidArgumentException::class);
87 $this->expectExceptionCode(1438782187);
88 new \TYPO3\CMS\Extbase\Mvc\Cli\Command($controllerClassName, 'foo');
89 }
90
91 public function testIsInternal()
92 {
93 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
94 Command::class,
95 MockCCommandController::class,
96 'empty'
97 );
98
99 static::assertFalse($commandController->isInternal());
100
101 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
102 Command::class,
103 MockCCommandController::class,
104 'internal'
105 );
106
107 static::assertTrue($commandController->isInternal());
108 }
109
110 public function testIsCliOnly()
111 {
112 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
113 Command::class,
114 MockCCommandController::class,
115 'empty'
116 );
117
118 static::assertFalse($commandController->isCliOnly());
119
120 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
121 Command::class,
122 MockCCommandController::class,
123 'cliOnly'
124 );
125
126 static::assertTrue($commandController->isCliOnly());
127 }
128
129 public function testIsFlushinCaches()
130 {
131 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
132 Command::class,
133 MockCCommandController::class,
134 'empty'
135 );
136
137 static::assertFalse($commandController->isFlushingCaches());
138
139 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
140 Command::class,
141 MockCCommandController::class,
142 'flushingCaches'
143 );
144
145 static::assertTrue($commandController->isFlushingCaches());
146 }
147
148 public function testHasArguments()
149 {
150 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
151 Command::class,
152 MockCCommandController::class,
153 'empty'
154 );
155
156 static::assertFalse($commandController->hasArguments());
157
158 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
159 Command::class,
160 MockCCommandController::class,
161 'withArguments'
162 );
163
164 static::assertTrue($commandController->hasArguments());
165 }
166
167 public function testGetArgumentDefinitions()
168 {
169 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
170 Command::class,
171 MockCCommandController::class,
172 'empty'
173 );
174
175 static::assertSame([], $commandController->getArgumentDefinitions());
176
177 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
178 Command::class,
179 MockCCommandController::class,
180 'withArguments'
181 );
182
183 $expected = [
184 new CommandArgumentDefinition('foo', true, 'FooParamDescription'),
185 new CommandArgumentDefinition('bar', false, 'BarParamDescription'),
186 ];
187
188 static::assertEquals($expected, $commandController->getArgumentDefinitions());
189 }
190
191 public function testGetDescription()
192 {
193 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
194 Command::class,
195 MockCCommandController::class,
196 'empty'
197 );
198
199 static::assertSame('', $commandController->getDescription());
200
201 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
202 Command::class,
203 MockCCommandController::class,
204 'withDescription'
205 );
206
207 $expected = 'Longer Description' . LF .
208 'Multine' . LF . LF .
209 'Much Multiline';
210
211 static::assertEquals($expected, $commandController->getDescription());
212 }
213
214 public function testGetShortDescription()
215 {
216 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
217 Command::class,
218 MockCCommandController::class,
219 'empty'
220 );
221
222 static::assertSame('', $commandController->getShortDescription());
223
224 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
225 Command::class,
226 MockCCommandController::class,
227 'withDescription'
228 );
229
230 $expected = 'Short Description';
231
232 static::assertEquals($expected, $commandController->getShortDescription());
233 }
234
235 public function testGetRelatedCommandIdentifiers()
236 {
237 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
238 Command::class,
239 MockCCommandController::class,
240 'empty'
241 );
242
243 static::assertSame([], $commandController->getRelatedCommandIdentifiers());
244
245 $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
246 Command::class,
247 MockCCommandController::class,
248 'relatedCommandIdentifiers'
249 );
250
251 $expected = ['Foo:Bar:Baz'];
252 static::assertEquals($expected, $commandController->getRelatedCommandIdentifiers());
253 }
254 }