[BUGFIX] Numeric check for upper/lower bound of flexform-values 55/19755/2
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 9 Apr 2013 13:09:22 +0000 (15:09 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 9 Apr 2013 13:31:07 +0000 (15:31 +0200)
The range-check in Flexforms uses the same code as for normal
tables. Normally an integer field would be of type integer.
But in Flexforms the value is a string as is the value in DS.
Change-Id: I3512a961780a4bef91e04f61b8b9547f43f28f3e
Fixes: #15771
Releases: 4.5, 4.6, 4.7, 6.0, 6.1
Reviewed-on: https://review.typo3.org/19753
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
Reviewed-on: https://review.typo3.org/19754
Reviewed-on: https://review.typo3.org/19755

t3lib/class.t3lib_tcemain.php
tests/t3lib/t3lib_tcemainTest.php

index 4549be3..b56df51 100644 (file)
@@ -1373,10 +1373,10 @@ class t3lib_TCEmain {
 
                        // Checking range of value:
                if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && intval($value) !== intval($tcaFieldConf['default'])) {
-                       if (isset($tcaFieldConf['range']['upper']) && $value > $tcaFieldConf['range']['upper']) {
+                       if (isset($tcaFieldConf['range']['upper']) && intval($value) > intval($tcaFieldConf['range']['upper'])) {
                                $value = $tcaFieldConf['range']['upper'];
                        }
-                       if (isset($tcaFieldConf['range']['lower']) && $value < $tcaFieldConf['range']['lower']) {
+                       if (isset($tcaFieldConf['range']['lower']) && intval($value) < intval($tcaFieldConf['range']['lower'])) {
                                $value = $tcaFieldConf['range']['lower'];
                        }
                }
index 2bc0322..5fdf40d 100644 (file)
@@ -178,6 +178,44 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
                }
        }
 
+       /**
+        * Data provider for inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly
+        *
+        * @return array
+        */
+       public function inputValuesStringsDataProvider() {
+               return array(
+                       '"0" returns zero as integer' => array(
+                               '0',
+                               0
+                       ),
+                       '"-1999999" is interpreted correctly as -1999999 and is lot lower then -200000' => array(
+                               '-1999999',
+                               -1999999
+                       ),
+                       '"3000000" is interpreted correctly as 3000000 but is higher then 200000 and set to 200000' => array(
+                               '3000000',
+                               2000000
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider inputValuesStringsDataProvider
+        */
+       public function inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly($value, $expectedReturnValue) {
+               $tcaFieldConf = array(
+                       'input' => array(),
+                       'eval' => 'int',
+                       'range' => array(
+                               'lower' => '-2000000',
+                               'upper' => '2000000'
+                       )
+               );
+               $returnValue = $this->fixture->checkValue_input(array(), $value, $tcaFieldConf, array());
+               $this->assertSame($returnValue['value'], $expectedReturnValue);
+       }
 
        ///////////////////////////////////////////
        // Tests concerning checkModifyAccessList