[BUGFIX] Correctly apply Extbase-validator-options / Add tests 10/24010/7
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 24 Sep 2013 00:12:03 +0000 (02:12 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 11 Nov 2013 17:12:57 +0000 (18:12 +0100)
* Check supplied options
* Apply default-values of validator if needed
* Check for required options
* Provide options via constructor instead of via setOptions()
  (which is deprecated)
* Add tests for AbstractValidator and AbstractCompositeValidator

Change-Id: I02c72eff93125a002d57e23710b954c44cc84465
Resolves: #52208
Releases: 6.0, 6.1, 6.2
Reviewed-on: https://review.typo3.org/24010
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Pascal Dürsteler
Tested-by: Pascal Dürsteler
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
18 files changed:
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/BooleanValidator.php
typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractCompositeValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTestcase.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AlphanumericValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractCompositeValidatorClass.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractValidatorClass.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/FloatValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/GenericObjectValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/IntegerValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NotEmptyValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringLengthValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php

index 82a7771..851921b 100644 (file)
@@ -67,13 +67,39 @@ abstract class AbstractValidator implements \TYPO3\CMS\Extbase\Validation\Valida
        protected $result;
 
        /**
-        * Sets options for the validator
+        * Constructs the composite validator and sets validation options
         *
-        * @param array $validationOptions Options for the validator
+        * @param array $options Options for the validator
+        * @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         * @api
         */
-       public function __construct($validationOptions = array()) {
-               $this->options = $validationOptions;
+       public function __construct(array $options = array()) {
+               // check for options given but not supported
+               if (($unsupportedOptions = array_diff_key($options, $this->supportedOptions)) !== array()) {
+                       throw new \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException('Unsupported validation option(s) found: ' . implode(', ', array_keys($unsupportedOptions)), 1379981890);
+               }
+
+               // check for required options being set
+               array_walk(
+                       $this->supportedOptions,
+                       function($supportedOptionData, $supportedOptionName, $options) {
+                               if (isset($supportedOptionData[3]) && !array_key_exists($supportedOptionName, $options)) {
+                                       throw new \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException('Required validation option not set: ' . $supportedOptionName, 1379981891);
+                               }
+                       },
+                       $options
+               );
+
+               // merge with default values
+               $this->options = array_merge(
+                       array_map(
+                               function ($value) {
+                                       return $value[0];
+                               },
+                               $this->supportedOptions
+                       ),
+                       $options
+               );
        }
 
        /**
index 029309e..afb3569 100644 (file)
@@ -32,6 +32,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  */
 class BooleanValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
 
+        /**
+         * @var array
+         */
+        protected $supportedOptions = array(
+                'is' => array(TRUE, 'Boolean value', 'boolean|string|integer')
+        );
+
        /**
         * Returns TRUE if the given property value is a boolean matching the expectation.
         *
@@ -44,9 +51,6 @@ class BooleanValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractV
         * @return boolean TRUE if the value is within the range, otherwise FALSE
         */
        public function isValid($value) {
-               if (!isset($this->options['is'])) {
-                       return;
-               }
                switch (strtolower((string)$this->options['is'])) {
                        case 'true':
                        case '1':
index 23c11a3..8f3206c 100644 (file)
@@ -105,11 +105,7 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface {
                         */
                        $validatorObjectName = $this->resolveValidatorObjectName($validatorType);
 
-                       $validator = $this->objectManager->get($validatorObjectName);
-                       if (method_exists($validator, 'setOptions')) {
-                               // @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
-                               $validator->setOptions($validatorOptions);
-                       }
+                       $validator = $this->objectManager->get($validatorObjectName, $validatorOptions);
 
                        if (!($validator instanceof \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface)) {
                                throw new Exception\NoSuchValidatorException('The validator "' . $validatorObjectName . '" does not implement TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface!', 1300694875);
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractCompositeValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractCompositeValidatorTest.php
new file mode 100644 (file)
index 0000000..630701f
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
+
+/*                                                                        *
+ * This script belongs to the Extbase framework.                            *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License, or (at your *
+ * option) any later version.                                             *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
+ * General Public License for more details.                               *
+ *                                                                        *
+ * You should have received a copy of the GNU Lesser General Public       *
+ * License along with the script.                                         *
+ * If not, see http://www.gnu.org/licenses/lgpl.html                      *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Testcase for the abstract base-class of composite-validators
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class AbstractCompositeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function validatorAcceptsSupportedOptions() {
+               $inputOptions = array(
+                       'requiredOption' => 666,
+                       'demoOption' => 42
+               );
+               $expectedOptions = $inputOptions;
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractCompositeValidatorClass', array('dummy'), array($inputOptions));
+               $this->assertSame($expectedOptions, $validator->_get('options'));
+       }
+
+       /**
+        * @test
+        */
+       public function validatorHasDefaultOptions() {
+               $inputOptions = array('requiredOption' => 666);
+               $expectedOptions = array(
+                       'requiredOption' => 666,
+                       'demoOption' => PHP_INT_MAX
+               );
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractCompositeValidatorClass', array('dummy'), array($inputOptions));
+               $this->assertSame($expectedOptions, $validator->_get('options'));
+       }
+
+       /**
+        * @test
+        */
+       public function validatorThrowsExceptionOnNotSupportedOptions() {
+               $inputOptions = array('invalidoption' => 42);
+               $this->setExpectedException('TYPO3\\CMS\\Extbase\\Validation\\Exception\\InvalidValidationOptionsException', '', 1339079804);
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractCompositeValidatorClass', array('dummy'), array($inputOptions));
+       }
+
+
+       /**
+        * @test
+        */
+       public function validatorThrowsExceptionOnMissingRequiredOptions() {
+               $inputOptions = array();
+               $this->setExpectedException('TYPO3\\CMS\\Extbase\\Validation\\Exception\\InvalidValidationOptionsException', '', 1339163922);
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractCompositeValidatorClass', array('dummy'), array($inputOptions));
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTest.php
new file mode 100644 (file)
index 0000000..d4efbe1
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
+
+/*                                                                        *
+ * This script belongs to the Extbase framework.                            *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License, or (at your *
+ * option) any later version.                                             *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
+ * General Public License for more details.                               *
+ *                                                                        *
+ * You should have received a copy of the GNU Lesser General Public       *
+ * License along with the script.                                         *
+ * If not, see http://www.gnu.org/licenses/lgpl.html                      *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Testcase for the abstract base-class of validators
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class AbstractValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function validatorAcceptsSupportedOptions() {
+               $inputOptions = array(
+                       'requiredOption' => 666,
+                       'demoOption' => 42
+               );
+               $expectedOptions = $inputOptions;
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array('dummy'), array($inputOptions));
+               $this->assertSame($expectedOptions, $validator->_get('options'));
+       }
+
+       /**
+        * @test
+        */
+       public function validatorHasDefaultOptions() {
+               $inputOptions = array('requiredOption' => 666);
+               $expectedOptions = array(
+                       'requiredOption' => 666,
+                       'demoOption' => PHP_INT_MAX
+               );
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array('dummy'), array($inputOptions));
+               $this->assertSame($expectedOptions, $validator->_get('options'));
+       }
+
+       /**
+        * @test
+        */
+       public function validatorThrowsExceptionOnNotSupportedOptions() {
+               $inputOptions = array('invalidoption' => 42);
+               $this->setExpectedException('TYPO3\\CMS\\Extbase\\Validation\\Exception\\InvalidValidationOptionsException', '', 1379981890);
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array('dummy'), array($inputOptions));
+       }
+
+
+       /**
+        * @test
+        */
+       public function validatorThrowsExceptionOnMissingRequiredOptions() {
+               $inputOptions = array();
+               $this->setExpectedException('TYPO3\\CMS\\Extbase\\Validation\\Exception\\InvalidValidationOptionsException', '', 1379981891);
+               $validator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array('dummy'), array($inputOptions));
+       }
+
+}
+
+?>
\ No newline at end of file
index e38dba8..8f6ed55 100644 (file)
@@ -34,10 +34,6 @@ abstract class AbstractValidatorTestcase extends \TYPO3\CMS\Extbase\Tests\Unit\B
         */
        protected $validator;
 
-       public function setUp() {
-               $this->validator = $this->getValidator();
-       }
-
        /**
         * @param array $options
         * @return mixed
index 00d57f3..d2f5054 100644 (file)
@@ -30,6 +30,10 @@ class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
index fbe4da3..991e23d 100644 (file)
@@ -30,6 +30,10 @@ class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * Data provider with valid email addresses
         *
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractCompositeValidatorClass.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractCompositeValidatorClass.php
new file mode 100644 (file)
index 0000000..a5e1b0d
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\Fixture;
+
+/*                                                                        *
+ * This script belongs to the Extbase framework.                            *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License, or (at your *
+ * option) any later version.                                             *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
+ * General Public License for more details.                               *
+ *                                                                        *
+ * You should have received a copy of the GNU Lesser General Public       *
+ * License along with the script.                                         *
+ * If not, see http://www.gnu.org/licenses/lgpl.html                      *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Testcase for the abstract base-class of vvalidators
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class AbstractCompositeValidatorClass extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator {
+
+       /**
+        * @var array
+        */
+       protected $supportedOptions = array(
+               'requiredOption' => array(0, 'Some value', 'integer', TRUE),
+               'demoOption' => array(PHP_INT_MAX, 'Some value', 'integer'),
+       );
+
+       /**
+        * Check if $value is valid. If it is not valid, needs to add an error
+        * to Result.
+        *
+        * @param mixed $value
+        * @return void
+        */
+       protected function isValid($value) {
+               // dummy
+       }
+
+
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractValidatorClass.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/Fixture/AbstractValidatorClass.php
new file mode 100644 (file)
index 0000000..f1b1713
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\Fixture;
+
+/*                                                                        *
+ * This script belongs to the Extbase framework.                            *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License, or (at your *
+ * option) any later version.                                             *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
+ * General Public License for more details.                               *
+ *                                                                        *
+ * You should have received a copy of the GNU Lesser General Public       *
+ * License along with the script.                                         *
+ * If not, see http://www.gnu.org/licenses/lgpl.html                      *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Testcase for the abstract base-class of vvalidators
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class AbstractValidatorClass extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+
+       /**
+        * @var array
+        */
+       protected $supportedOptions = array(
+               'requiredOption' => array(0, 'Some value', 'integer', TRUE),
+               'demoOption' => array(PHP_INT_MAX, 'Some value', 'integer'),
+       );
+
+       /**
+        * Check if $value is valid. If it is not valid, needs to add an error
+        * to Result.
+        *
+        * @param mixed $value
+        * @return void
+        */
+       protected function isValid($value) {
+               // dummy
+       }
+
+
+}
+?>
\ No newline at end of file
index 0fcd973..9b256ef 100644 (file)
@@ -30,6 +30,10 @@ class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Valida
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * Data provider with valid floats
         *
index fcbe0ac..fed0bd0 100644 (file)
@@ -36,7 +36,7 @@ class GenericObjectValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validatio
        protected $configurationManager;
 
        public function setUp() {
-               parent::setUp();
+               $this->validator = $this->getValidator();
 
                $this->configurationManager = $this->getMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('isFeatureEnabled'), array(), '', FALSE);
                $this->configurationManager->expects($this->any())->method('isFeatureEnabled')->with('rewrittenPropertyMapper')->will($this->returnValue(TRUE));
index 8d46cde..b450754 100644 (file)
@@ -30,6 +30,10 @@ class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * Data provider with valid integers
         *
index 4de1801..8f68b7a 100644 (file)
@@ -30,6 +30,10 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Val
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
index 9ad776b..a892724 100644 (file)
@@ -30,10 +30,9 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator';
 
-       /**
-        * @var \TYPO3\Flow\Validation\Validator\StringLengthValidator
-        */
-       protected $validator;
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
 
        /**
         * @test
@@ -75,7 +74,6 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
 
        /**
         * @test
-        * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorReturnsNoErrorsForAStringLongerThanThanMinLengthAndMaxLengthNotSpecified() {
                $this->validatorOptions(array('minimum' => 5));
@@ -100,7 +98,6 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
 
        /**
         * @test
-        * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorReturnsNoErrorForAStringLengthEqualToMinLengthAndMaxLengthNotSpecified() {
                $this->validatorOptions(array('minimum' => 10));
@@ -136,7 +133,6 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorThrowsAnExceptionIfMinLengthIsGreaterThanMaxLength() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
                $this->validatorOptions(array('minimum' => 101, 'maximum' => 100));
                $this->validator->validate('1234567890');
        }
@@ -154,7 +150,6 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @test
         */
        public function stringLengthValidatorCanHandleAnObjectWithAToStringMethod() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
                $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
 
                $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
@@ -175,7 +170,6 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @test
         */
        public function validateReturnsErrorsIfTheGivenObjectCanNotBeConvertedToAString() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
                $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
 
                $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
index 4cfbeb8..537297e 100644 (file)
@@ -30,6 +30,10 @@ class StringValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Valid
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * @test
         * @author Sebastian Kurfürst <sebastian@typo3.org>
index 898ad89..23b7b68 100644 (file)
@@ -30,6 +30,10 @@ class TextValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validat
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator';
 
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
index 3206bd7..9ab5180 100644 (file)
@@ -158,13 +158,14 @@ class ValidatorResolverTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function createValidatorResolvesAndReturnsAValidatorAndPassesTheGivenOptions() {
                $className = uniqid('Test');
-               $mockValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ObjectValidatorInterface', array('setOptions', 'canValidate', 'isPropertyValid', 'setValidatedInstancesContainer'), array(), $className);
-               $mockValidator->expects($this->once())->method('setOptions')->with(array('foo' => 'bar'));
-               $this->mockObjectManager->expects($this->any())->method('get')->with($className)->will($this->returnValue($mockValidator));
+               $validatorOptions = array('requiredOption' => 'foo', 'demoOption' => 'bar');
+               $mockValidator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array('dummy'), array($validatorOptions), $className);
+               $this->mockObjectManager->expects($this->any())->method('get')->with($className, $validatorOptions)->will($this->returnValue($mockValidator));
                $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName'));
                $validatorResolver->_set('objectManager', $this->mockObjectManager);
                $validatorResolver->expects($this->once())->method('resolveValidatorObjectName')->with($className)->will($this->returnValue($className));
-               $validator = $validatorResolver->createValidator($className, array('foo' => 'bar'));
+               $validator = $validatorResolver->createValidator($className, $validatorOptions);
+               $this->assertEquals($validatorOptions, $validator->_get('options'));
                $this->assertSame($mockValidator, $validator);
        }