[TASK] Add unit tests for CommandUtility::unQuoteFilenames 88/57888/3
authorWouter Wolters <typo3@wouterwolters.nl>
Mon, 13 Aug 2018 18:43:30 +0000 (20:43 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 14 Aug 2018 10:28:47 +0000 (12:28 +0200)
While moving this method to CommandUtility class the unit tests
were missing. They are re-added now.

Resolves: #85837
Releases: master
Change-Id: I993a06d6da107a333d186706dcbee1fcc4b2731e
Reviewed-on: https://review.typo3.org/57888
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Tests/Unit/Utility/CommandUtilityTest.php

index 6932386..e2014ab 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
 
 /*
@@ -13,12 +14,14 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Core\Utility\CommandUtility;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
- * Test case for class \TYPO3\CMS\Core\Utility\CommandUtility
+ * Test case
  */
-class CommandUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class CommandUtilityTest extends UnitTestCase
 {
     /**
      * Data provider for getConfiguredApps
@@ -84,4 +87,120 @@ class CommandUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $result = $commandUtilityMock->_call('getConfiguredApps');
         $this->assertSame($expected, $result);
     }
+
+    /**
+     * Data provider unQuoteFilenameUnquotesCorrectly
+     */
+    public function unQuoteFilenameUnquotesCorrectlyDataProvider(): array
+    {
+        return [
+            // Some theoretical tests first
+            [
+                '',
+                []
+            ],
+            [
+                'aa bb "cc" "dd"',
+                ['aa', 'bb', '"cc"', '"dd"']
+            ],
+            [
+                'aa bb "cc dd"',
+                ['aa', 'bb', '"cc dd"']
+            ],
+            [
+                '\'aa bb\' "cc dd"',
+                ['\'aa bb\'', '"cc dd"']
+            ],
+            [
+                '\'aa bb\' cc "dd"',
+                ['\'aa bb\'', 'cc', '"dd"']
+            ],
+            // Now test against some real world examples
+            [
+                '/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"',
+                [
+                    '/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"'
+                ]
+            ],
+            [
+                '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"',
+                [
+                    '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"'
+                ]
+            ],
+            [
+                '/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"',
+                [
+                    '/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"'
+                ]
+            ],
+            [
+                '/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"',
+                [
+                    '/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"'
+                ]
+            ],
+            [
+                '/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\'',
+                [
+                    '/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\''
+                ]
+            ]
+        ];
+    }
+
+    /**
+     * Tests if the commands are exploded and unquoted correctly
+     *
+     * @dataProvider unQuoteFilenameUnquotesCorrectlyDataProvider
+     * @test
+     * @param string $source
+     * @param array $expectedQuoted
+     */
+    public function unQuoteFilenameUnquotesCorrectly(string $source, array $expectedQuoted): void
+    {
+        $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, ['dummy']);
+        $actualQuoted = $commandUtilityMock->_call('unQuoteFilenames', $source);
+        $this->assertEquals($expectedQuoted, $actualQuoted);
+    }
 }