‪TYPO3CMS  10.4
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 {
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 
85  public function ‪getConfiguredApps($globalsBinSetup, $expected)
86  {
87  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup'] = $globalsBinSetup;
88  $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, ['dummy']);
89  $result = $commandUtilityMock->_call('getConfiguredApps');
90  self::assertSame($expected, $result);
91  }
92 
97  {
98  return [
99  // Some theoretical tests first
100  [
101  '',
102  []
103  ],
104  [
105  'aa bb "cc" "dd"',
106  ['aa', 'bb', '"cc"', '"dd"']
107  ],
108  [
109  'aa bb "cc dd"',
110  ['aa', 'bb', '"cc dd"']
111  ],
112  [
113  '\'aa bb\' "cc dd"',
114  ['\'aa bb\'', '"cc dd"']
115  ],
116  [
117  '\'aa bb\' cc "dd"',
118  ['\'aa bb\'', 'cc', '"dd"']
119  ],
120  // Now test against some real world examples
121  [
122  '/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"',
123  [
124  '/opt/local/bin/gm.exe',
125  'convert',
126  '+profile',
127  '\'*\'',
128  '-geometry',
129  '170x136!',
130  '-negate',
131  '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
132  '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
133  ]
134  ],
135  [
136  '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"',
137  [
138  'C:/opt/local/bin/gm.exe',
139  'convert',
140  '+profile',
141  '\'*\'',
142  '-geometry',
143  '170x136!',
144  '-negate',
145  '"C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
146  '"C:/Program Files/Apache2/htdocs/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
147  ]
148  ],
149  [
150  '/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"',
151  [
152  '/usr/bin/gm',
153  'convert',
154  '+profile',
155  '\'*\'',
156  '-geometry',
157  '170x136!',
158  '-negate',
159  '"/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
160  '"/Shared Items/Data/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
161  ]
162  ],
163  [
164  '/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"',
165  [
166  '/usr/bin/gm',
167  'convert',
168  '+profile',
169  '\'*\'',
170  '-geometry',
171  '170x136!',
172  '-negate',
173  '"/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
174  '"/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
175  ]
176  ],
177  [
178  '/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\'',
179  [
180  '/usr/bin/gm',
181  'convert',
182  '+profile',
183  '\'*\'',
184  '-geometry',
185  '170x136!',
186  '-negate',
187  '\'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\'',
188  '\'/Network/Servers/server01.internal/Projects/typo3temp/var/transient/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\''
189  ]
190  ]
191  ];
192  }
193 
202  public function ‪unQuoteFilenameUnquotesCorrectly(string $source, array $expectedQuoted): void
203  {
204  $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, ['dummy']);
205  $actualQuoted = $commandUtilityMock->_call('unQuoteFilenames', $source);
206  self::assertEquals($expectedQuoted, $actualQuoted);
207  }
208 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\unQuoteFilenameUnquotesCorrectly
‪unQuoteFilenameUnquotesCorrectly(string $source, array $expectedQuoted)
Definition: CommandUtilityTest.php:202
‪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:96
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\getConfiguredApps
‪getConfiguredApps($globalsBinSetup, $expected)
Definition: CommandUtilityTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Utility\CommandUtilityTest\getConfiguredAppsDataProvider
‪array getConfiguredAppsDataProvider()
Definition: CommandUtilityTest.php:33
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49