[TASK] Migrate "GFX/processor_effects" to boolean 91/57391/5
authorMathias Brodala <mbrodala@pagemachine.de>
Wed, 27 Jun 2018 07:27:30 +0000 (09:27 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 28 Jun 2018 17:51:04 +0000 (19:51 +0200)
Ensure "GFX/processor_effects" is a true boolean as suggested in
the settings module and silently migrate integer/string values
accordingly.

Resolves: #83591
Releases: master
Change-Id: I006e907e75e273009333363a4d42661183ba8721
Reviewed-on: https://review.typo3.org/57391
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/install/Classes/Configuration/Image/CustomPreset.php
typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php
typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php
typo3/sysext/install/Resources/Public/Images/TestReference/About.txt
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php

index d408494..5e3d0e1 100644 (file)
@@ -29,7 +29,7 @@ class CustomPreset extends Configuration\AbstractCustomPreset implements Configu
         'GFX/processor_path' => '',
         'GFX/processor_path_lzw' => '',
         'GFX/processor' => '',
-        'GFX/processor_effects' => 0,
+        'GFX/processor_effects' => false,
         'GFX/processor_allowTemporaryMasksAsPng' => true,
         'GFX/processor_colorspace' => '',
     ];
index e289af8..410163f 100644 (file)
@@ -40,7 +40,7 @@ class GraphicsMagickPreset extends AbstractImagePreset
         'GFX/processor_path' => '',
         'GFX/processor_path_lzw' => '',
         'GFX/processor' => 'GraphicsMagick',
-        'GFX/processor_effects' => -1,
+        'GFX/processor_effects' => false,
         'GFX/processor_allowTemporaryMasksAsPng' => false,
         'GFX/processor_colorspace' => 'RGB',
     ];
index 504e059..b528ecd 100644 (file)
@@ -40,7 +40,7 @@ class ImageMagick6Preset extends AbstractImagePreset
         'GFX/processor_path' => '',
         'GFX/processor_path_lzw' => '',
         'GFX/processor' => 'ImageMagick',
-        'GFX/processor_effects' => 1,
+        'GFX/processor_effects' => true,
         'GFX/processor_allowTemporaryMasksAsPng' => false,
         'GFX/processor_colorspace' => 'sRGB',
     ];
index 4cad8be..7beb55f 100644 (file)
@@ -433,21 +433,21 @@ class SilentConfigurationUpgradeService
     {
         $changedValues = [];
         try {
-            $currentImValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_enabled');
+            $currentEnabledValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_enabled');
         } catch (MissingArrayPathException $e) {
-            $currentImValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_enabled');
+            $currentEnabledValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_enabled');
         }
 
         try {
-            $currentImPathValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path');
+            $currentPathValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path');
         } catch (MissingArrayPathException $e) {
-            $currentImPathValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path');
+            $currentPathValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path');
         }
 
         try {
-            $currentImPathLzwValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path_lzw');
+            $currentPathLzwValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path_lzw');
         } catch (MissingArrayPathException $e) {
-            $currentImPathLzwValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path_lzw');
+            $currentPathLzwValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path_lzw');
         }
 
         try {
@@ -462,11 +462,11 @@ class SilentConfigurationUpgradeService
             $currentThumbnailsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails');
         }
 
-        if (!$currentImValue) {
-            if ($currentImPathValue != '') {
+        if (!$currentEnabledValue) {
+            if ($currentPathValue != '') {
                 $changedValues['GFX/processor_path'] = '';
             }
-            if ($currentImPathLzwValue != '') {
+            if ($currentPathLzwValue != '') {
                 $changedValues['GFX/processor_path_lzw'] = '';
             }
             if ($currentImageFileExtValue !== 'gif,jpg,jpeg,png') {
@@ -512,6 +512,10 @@ class SilentConfigurationUpgradeService
         }
 
         if ((string)$currentProcessorValue !== '') {
+            if (!is_bool($currentProcessorEffectsValue)) {
+                $changedValues['GFX/processor_effects'] = (int)$currentProcessorEffectsValue > 0;
+            }
+
             if ($currentProcessorMaskValue != 0) {
                 $changedValues['GFX/processor_allowTemporaryMasksAsPng'] = 0;
             }
index d0feeb6..5220611 100644 (file)
@@ -10,7 +10,7 @@ $TYPO3_CONF_VARS['GFX']['TTFdpi'] = '96';
 $TYPO3_CONF_VARS['GFX']['gdlib_png'] = '1';
 $TYPO3_CONF_VARS['GFX']['processor_path'] = '/usr/bin/';
 $TYPO3_CONF_VARS['GFX']['processor'] = 'im5';
-$TYPO3_CONF_VARS['GFX']['processor_effects'] = '1';
+$TYPO3_CONF_VARS['GFX']['processor_effects'] = true;
 $TYPO3_CONF_VARS['GFX']['gdlib_2'] = 1;
 
 - PHP / GD configuration:
index d5427c6..0478980 100644 (file)
@@ -537,7 +537,7 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
         $currentLocalConfiguration = [
             ['GFX/processor', 'GraphicsMagick'],
             ['GFX/processor_allowTemporaryMasksAsPng', 1],
-            ['GFX/processor_effects', 0]
+            ['GFX/processor_effects', false],
         ];
         $this->createConfigurationManagerWithMockedMethods(
             [
@@ -553,9 +553,11 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
             ->method('getDefaultConfigurationValueByPath');
         $this->configurationManager->expects($this->once())
             ->method('setLocalConfigurationValuesByPathValuePairs')
-            ->withConsecutive(
-                [['GFX/processor_allowTemporaryMasksAsPng' => 0]]
-            );
+            ->withConsecutive([
+                [
+                    'GFX/processor_allowTemporaryMasksAsPng' => 0,
+                ]
+            ]);
 
         $this->expectException(ConfigurationChangedException::class);
 
@@ -581,7 +583,7 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
         $currentLocalConfiguration = [
             ['GFX/processor', ''],
             ['GFX/processor_allowTemporaryMasksAsPng', 0],
-            ['GFX/processor_effects', 0]
+            ['GFX/processor_effects', 0],
         ];
         $this->createConfigurationManagerWithMockedMethods(
             [
@@ -605,6 +607,64 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
 
     /**
      * @test
+     * @dataProvider graphicsProcessorEffects
+     *
+     * @param mixed $currentValue
+     * @param bool $expectedMigratedValue
+     */
+    public function migratesGraphicsProcessorEffects($currentValue, $expectedMigratedValue)
+    {
+        /** @var ConfigurationManager|\Prophecy\Prophecy\ObjectProphecy */
+        $configurationManager = $this->prophesize(ConfigurationManager::class);
+        $configurationManager->getLocalConfigurationValueByPath('GFX/processor')->willReturn('GraphicsMagick');
+        $configurationManager->getLocalConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng')->willReturn(false);
+        $configurationManager->getLocalConfigurationValueByPath('GFX/processor_effects')->willReturn($currentValue);
+        $configurationManager->setLocalConfigurationValuesByPathValuePairs([
+            'GFX/processor_effects' => $expectedMigratedValue,
+        ])->shouldBeCalled();
+
+        $this->expectException(ConfigurationChangedException::class);
+
+        $silentConfigurationUpgradeService = new SilentConfigurationUpgradeService($configurationManager->reveal());
+
+        $this->callInaccessibleMethod($silentConfigurationUpgradeService, 'setImageMagickDetailSettings');
+    }
+
+    /**
+     * @return array
+     */
+    public function graphicsProcessorEffects(): array
+    {
+        return [
+            'integer 1' => [
+                1,
+                true,
+            ],
+            'integer 0' => [
+                0,
+                false,
+            ],
+            'integer -1' => [
+                -1,
+                false,
+            ],
+            'string "1"' => [
+                '1',
+                true,
+            ],
+            'string "0"' => [
+                '0',
+                false,
+            ],
+            'string "-1"' => [
+                '-1',
+                false,
+            ],
+        ];
+    }
+
+    /**
+     * @test
      */
     public function migrateNonExistingLangDebug()
     {