‪TYPO3CMS  11.5
CommandUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪CommandUtilityTest extends UnitTestCase
27 {
33  public function ‪getConfiguredAppsDataProvider(): array
34  {
35  $defaultExpected = [
36  'perl' => [
37  'app' => 'perl',
38  'path' => '/usr/bin/',
39  'valid' => true,
40  ],
41  'unzip' => [
42  'app' => 'unzip',
43  'path' => '/usr/local/bin/',
44  'valid' => true,
45  ],
46  ];
47  return [
48  'returns empty array for empty string' => [
49  '',
50  [],
51  ],
52  'separated by comma' => [
53  'perl=/usr/bin/perl,unzip=/usr/local/bin/unzip',
54  $defaultExpected,
55  ],
56  'separated by new line' => [
57  'perl=/usr/bin/perl ' . LF . ' unzip=/usr/local/bin/unzip',
58  $defaultExpected,
59  ],
60  'separated by new line with spaces' => [
61  'perl = /usr/bin/perl ' . LF . ' unzip = /usr/local/bin/unzip',
62  $defaultExpected,
63  ],
64  'separated by new line with spaces and empty rows' => [
65  LF . 'perl = /usr/bin/perl ' . LF . LF . ' unzip = /usr/local/bin/unzip' . LF,
66  $defaultExpected,
67  ],
68  'separated by char(10)' => [
69  'perl=/usr/bin/perl\'.chr(10).\'unzip=/usr/local/bin/unzip',
70  $defaultExpected,
71  ],
72  'separated by LF as string' => [
73  'perl=/usr/bin/perl\' . LF . \'unzip=/usr/local/bin/unzip',
74  $defaultExpected,
75  ],
76  ];
77  }
78 
86  public function ‪getConfiguredApps($globalsBinSetup, $expected): void
87  {
88  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup'] = $globalsBinSetup;
89  $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, ['dummy']);
90  $result = $commandUtilityMock->_call('getConfiguredApps');
91  self::assertSame($expected, $result);
92  }
93 
98  {
99  return [
100  // Some theoretical tests first
101  [
102  '',
103  [],
104  ],
105  [
106  'aa bb "cc" "dd"',
107  ['aa', 'bb', '"cc"', '"dd"'],
108  ],
109  [
110  'aa bb "cc dd"',
111  ['aa', 'bb', '"cc dd"'],
112  ],
113  [
114  '\'aa bb\' "cc dd"',
115  ['\'aa bb\'', '"cc dd"'],
116  ],
117  [
118  '\'aa bb\' cc "dd"',
119  ['\'aa bb\'', 'cc', '"dd"'],
120  ],
121  // Now test against some real world examples
122  [
123  '/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136! -negate "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
124  [
125  '/opt/local/bin/gm.exe',
126  'convert',
127  '+profile',
128  '\'*\'',
129  '-geometry',
130  '170x136!',
131  '-negate',
132  '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
133  '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
134  ],
135  ],
136  [
137  'C:/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136! -negate "C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
138  [
139  'C:/opt/local/bin/gm.exe',
140  'convert',
141  '+profile',
142  '\'*\'',
143  '-geometry',
144  '170x136!',
145  '-negate',
146  '"C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
147  '"C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
148  ],
149  ],
150  [
151  '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate "/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
152  [
153  '/usr/bin/gm',
154  'convert',
155  '+profile',
156  '\'*\'',
157  '-geometry',
158  '170x136!',
159  '-negate',
160  '"/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
161  '"/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
162  ],
163  ],
164  [
165  '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate "/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
166  [
167  '/usr/bin/gm',
168  'convert',
169  '+profile',
170  '\'*\'',
171  '-geometry',
172  '170x136!',
173  '-negate',
174  '"/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
175  '"/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
176  ],
177  ],
178  [
179  '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate \'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\' \'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\'',
180  [
181  '/usr/bin/gm',
182  'convert',
183  '+profile',
184  '\'*\'',
185  '-geometry',
186  '170x136!',
187  '-negate',
188  '\'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\'',
189  '\'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\'',
190  ],
191  ],
192  ];
193  }
194 
203  public function ‪unQuoteFilenameUnquotesCorrectly(string $source, array $expectedQuoted): void
204  {
205  $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, ['dummy']);
206  $actualQuoted = $commandUtilityMock->_call('unQuoteFilenames', $source);
207  self::assertEquals($expectedQuoted, $actualQuoted);
208  }
209 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\unQuoteFilenameUnquotesCorrectly
‪unQuoteFilenameUnquotesCorrectly(string $source, array $expectedQuoted)
Definition: CommandUtilityTest.php:203
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest
Definition: CommandUtilityTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\unQuoteFilenameUnquotesCorrectlyDataProvider
‪unQuoteFilenameUnquotesCorrectlyDataProvider()
Definition: CommandUtilityTest.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\getConfiguredApps
‪getConfiguredApps($globalsBinSetup, $expected)
Definition: CommandUtilityTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\getConfiguredAppsDataProvider
‪array getConfiguredAppsDataProvider()
Definition: CommandUtilityTest.php:33
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49