[BUGFIX] Reimplement ranges in NumberRangeValidator 22/29722/9
authorStefan Froemken <froemken@gmail.com>
Tue, 29 Apr 2014 08:51:14 +0000 (10:51 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 29 Apr 2014 21:14:24 +0000 (23:14 +0200)
We have removed startRange and endRange too early
in NumberRangeValidator. As long as TYPO3 6.3
is not reached we have to reimplement these options
again.

Resolves: #58313
Releases: 6.2
Change-Id: Id012da11227230890b27aa24e1dba1787210f931
Reviewed-on: https://review.typo3.org/29722
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php

index 6b84a21..0f2b698 100644 (file)
@@ -40,7 +40,9 @@ class NumberRangeValidator extends AbstractValidator {
         */
        protected $supportedOptions = array(
                'minimum' => array(0, 'The minimum value to accept', 'integer'),
-               'maximum' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer')
+               'maximum' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer'),
+               'startRange' => array(0, 'The minimum value to accept', 'integer'),
+               'endRange' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer')
        );
 
        /**
@@ -60,19 +62,23 @@ class NumberRangeValidator extends AbstractValidator {
                        return;
                }
 
-               $minimum = $this->options['minimum'];
-               $maximum = $this->options['maximum'];
-
                /**
-                * @todo: remove this fallback in 6.3
+                * @todo: remove this fallback to startRange/endRange in 6.3 when the setOptions() method is removed too
                 * @deprecated since Extbase 1.4, will be removed two versions after Extbase 6.1
                 */
-               if ($minimum === NULL && isset($this->options['startRange'])) {
+               if (isset($this->options['minimum'])) {
+                       $minimum = $this->options['minimum'];
+               } elseif (isset($this->options['startRange'])) {
                        $minimum = $this->options['startRange'];
+               } else {
+                       $minimum = 0;
                }
-
-               if ($maximum === NULL && isset($this->options['endRange'])) {
+               if (isset($this->options['maximum'])) {
+                       $maximum = $this->options['maximum'];
+               } elseif (isset($this->options['endRange'])) {
                        $maximum = $this->options['endRange'];
+               } else {
+                       $maximum = PHP_INT_MAX;
                }
 
                if ($minimum > $maximum) {
index b14970b..6db72bb 100644 (file)
@@ -39,6 +39,17 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function deprecatedOptionsAreStillSupported() {
+               $this->getMock(
+                       'TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator',
+                       array(),
+                       array(array('startRange' => 0, 'endRange' => 1000))
+               );
+       }
+
+       /**
+        * @test
+        */
        public function numberRangeValidatorReturnsTrueForASimpleIntegerInRange() {
                $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
                $numberRangeValidator->expects($this->never())->method('addError');