[!!!][+FEATURE] (Validation): Adjusted and re-done Validation API
authorSebastian Kurfuerst <sebastian@typo3.org>
Wed, 22 Jun 2011 14:56:51 +0000 (16:56 +0200)
committerSebastian Kurfuerst <sebastian@typo3.org>
Thu, 30 Jun 2011 05:42:23 +0000 (07:42 +0200)
* Completely reworked Validation API, adjusting all validators.
  Validators now return a Error_Result object.
* Validators can now be singletons or prototypes
* Validator options are passed in the constructor

The whole change is *backwards-compatible*, so all default validators can be
used with the new MVC stack in Extbase 1.4, and with the MVC stack in
compatibility mode.

The same goes for *custom validators* which extend *AbstractValidator*. They
are automatically upwards-compatible.

!!! If an extension author directly implemented the *ValidatorInterface*,
he needs to adjust his validator to support the new API.

Resolves: #27653
Change-Id: I6b3c9f4a629728f7e1fa2cd672f38f69c7321f52

46 files changed:
typo3/sysext/extbase/Classes/Validation/PropertyError.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractObjectValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/GenericObjectValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php
typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php
typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php
typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithGettersAndSetters.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTestcase.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AlphanumericValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/AlphanumericValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/ConjunctionValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/DateTimeValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/EmailAddressValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/FloatValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/GenericObjectValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/IntegerValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NotEmptyValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RawValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RegularExpressionValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/StringLengthValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/TextValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/ConjunctionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/DateTimeValidatorTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/DisjunctionValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php
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/NumberRangeValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NumberValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/RawValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/RegularExpressionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringLengthValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringValidatorTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php

index 44cc0d6..7fa3464 100644 (file)
@@ -33,6 +33,7 @@
  * @version $Id$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @scope prototype
+ * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
  */
 class Tx_Extbase_Validation_PropertyError extends Tx_Extbase_Validation_Error {
 
index 5abfeb2..c799d01 100644 (file)
@@ -64,6 +64,7 @@ abstract class Tx_Extbase_Validation_Validator_AbstractCompositeValidator implem
         *
         * @param array $options Not used
         * @return void
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function setOptions(array $options) {
        }
@@ -72,6 +73,7 @@ abstract class Tx_Extbase_Validation_Validator_AbstractCompositeValidator implem
         * Returns an array of errors which occurred during the last isValid() call.
         *
         * @return array An array of Tx_Extbase_Validation_Error objects or an empty array if no errors occurred.
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function getErrors() {
                return $this->errors;
index f46cddc..6a501bd 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -31,6 +31,7 @@
  * @package Extbase
  * @subpackage Validation\Validator
  * @version $Id$
+ * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
  */
 abstract class Tx_Extbase_Validation_Validator_AbstractObjectValidator extends Tx_Extbase_Validation_Validator_AbstractValidator implements Tx_Extbase_Validation_Validator_ObjectValidatorInterface {
 
index 275b76e..37657dd 100644 (file)
@@ -40,14 +40,54 @@ abstract class Tx_Extbase_Validation_Validator_AbstractValidator implements Tx_E
 
        /**
         * @var array
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. You should use constructor parameter to set validation options.
         */
        protected $errors = array();
 
        /**
+        * @var Tx_Extbase_Error_Result
+        */
+       protected $result;
+
+       /**
+        * Sets options for the validator
+        *
+        * @param array $validationOptions Options for the validator
+        * @return void
+        * @api
+        */
+       public function __construct($validationOptions = array()) {
+               $this->options = $validationOptions;
+       }
+
+       /**
+        * Checks if the given value is valid according to the validator, and returns
+        * the Error Messages object which occured.
+        *
+        * @param mixed $value The value that should be validated
+        * @return Tx_Extbase_Error_Result
+        * @api
+        */
+       public function validate($value) {
+               $this->result = new Tx_Extbase_Error_Result();
+               $this->isValid($value);
+               return $this->result;
+       }
+
+       /**
+        * Check if $value is valid. If it is not valid, needs to add an error
+        * to Result.
+        *
+        * @return void
+        */
+       abstract protected function isValid($value);
+
+       /**
         * Sets options for the validator
         *
         * @param array $options Options for the validator
         * @return void
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. use constructor instead.
         */
        public function setOptions(array $options) {
                $this->options = $options;
@@ -57,6 +97,7 @@ abstract class Tx_Extbase_Validation_Validator_AbstractValidator implements Tx_E
         * Returns an array of errors which occurred during the last isValid() call.
         *
         * @return array An array of Tx_Extbase_Validation_Error objects or an empty array if no errors occurred.
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. use validate() instead.
         */
        public function getErrors() {
                return $this->errors;
@@ -70,6 +111,11 @@ abstract class Tx_Extbase_Validation_Validator_AbstractValidator implements Tx_E
         * @return void
         */
        protected function addError($message, $code) {
+               if ($this->result !== NULL) {
+                               // backwards compatibility before Extbase 1.4.0: we cannot expect the "result" object to be there.
+                       $this->result->addError(new Tx_Extbase_Validation_Error($message, $code));
+               }
+               // the following is @deprecated since Extbase 1.4.0:
                $this->errors[] = new Tx_Extbase_Validation_Error($message, $code);
        }
 }
index f6d0c50..ab959b6 100644 (file)
  * @scope prototype
  */
 class Tx_Extbase_Validation_Validator_ConjunctionValidator extends Tx_Extbase_Validation_Validator_AbstractCompositeValidator {
+
+       /**
+        * Checks if the given value is valid according to the validators of the conjunction.
+        *
+        * @param mixed $value The value that should be validated
+        * @return \F3\FLOW3\Error\Result
+        * @api
+        */
+       public function validate($value) {
+               $result = new Tx_Extbase_Error_Result();
+               foreach ($this->validators as $validator) {
+                       $result->merge($validator->validate($value));
+               }
+               return $result;
+       }
+
        /**
         * Checks if the given value is valid according to the validators of the conjunction.
         *
         * If at least one error occurred, the result is FALSE.
         *
         * @param mixed $value The value that should be validated
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0.
         */
        public function isValid($value) {
                $result = TRUE;
index ef8deba..299659d 100644 (file)
  * @scope prototype
  */
 class Tx_Extbase_Validation_Validator_DisjunctionValidator extends Tx_Extbase_Validation_Validator_AbstractCompositeValidator {
+
+       /**
+        * Checks if the given value is valid according to the validators of the
+        * disjunction.
+        *
+        * If all validators fail, the result is FALSE.
+        *
+        * @param mixed $value The value that should be validated
+        * @param boolean $resetInstancesCurrentlyUnderValidation Reserved for internal use!
+        * @return Tx_Extbase_Error_Result
+        * @api
+        */
+       public function validate($value, $resetInstancesCurrentlyUnderValidation = TRUE) {
+               $result = new Tx_Extbase_Error_Result();
+
+               $oneWithoutErrors = FALSE;
+               foreach ($this->validators as $validator) {
+                       $validatorResult = $validator->validate($value);
+                       if ($validatorResult->hasErrors()) {
+                               $result->merge($validatorResult);
+                       } else {
+                               $oneWithoutErrors = TRUE;
+                       }
+               }
+
+               if ($oneWithoutErrors === TRUE) {
+                       $result = new Tx_Extbase_Error_Result();
+               }
+               return $result;
+       }
+
        /**
         * Checks if the given value is valid according to the validators of the conjunction.
         *
@@ -45,6 +76,7 @@ class Tx_Extbase_Validation_Validator_DisjunctionValidator extends Tx_Extbase_Va
         *
         * @param mixed $value The value that should be validated
         * @return boolean TRUE if the value is valid, FALSE if an error occured
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function isValid($value) {
                $result = FALSE;
index 94d8bc0..1bc8a7f 100644 (file)
@@ -40,6 +40,89 @@ class Tx_Extbase_Validation_Validator_GenericObjectValidator extends Tx_Extbase_
         */
        protected $propertyValidators = array();
 
+
+       /**
+        *
+        * @var Tx_Extbase_Persistence_ObjectStorage
+        */
+       static protected $instancesCurrentlyUnderValidation;
+
+       /**
+        * Checks if the given value is valid according to the property validators
+        *
+        * If at least one error occurred, the result is FALSE.
+        *
+        * @param mixed $value The value that should be validated
+        * @return Tx_Extbase_Error_Result
+        * @api
+        */
+       public function validate($object) {
+               $messages = new Tx_Extbase_Error_Result();
+
+               if (self::$instancesCurrentlyUnderValidation === NULL) {
+                       self::$instancesCurrentlyUnderValidation = new Tx_Extbase_Persistence_ObjectStorage();
+               }
+
+               if ($object === NULL) {
+                       return $messages;
+               }
+
+               if (!is_object($object)) {
+                       $messages->addError(new Tx_Extbase_Validation_Error('Object expected, ' . gettype($object) . ' given.', 1241099149));
+                       return $messages;
+               }
+
+               if (self::$instancesCurrentlyUnderValidation->contains($object)) {
+                       return $messages;
+               } else {
+                       self::$instancesCurrentlyUnderValidation->attach($object);
+               }
+
+               foreach ($this->propertyValidators as $propertyName => $validators) {
+                       $propertyValue = $this->getPropertyValue($object, $propertyName);
+                       $this->checkProperty($propertyValue, $validators, $messages->forProperty($propertyName));
+               }
+
+               self::$instancesCurrentlyUnderValidation->detach($object);
+               return $messages;
+       }
+
+       /**
+        * Load the property value to be used for validation.
+        *
+        * In case the object is a doctrine proxy, we need to load the real instance first.
+        *
+        * @param object $object
+        * @param string $propertyName
+        * @return mixed
+        */
+       protected function getPropertyValue($object, $propertyName) {
+                       // TODO: add support for lazy loading proxies, if needed
+
+               if (Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($object, $propertyName)) {
+                       return Tx_Extbase_Reflection_ObjectAccess::getProperty($object, $propertyName);
+               } else {
+                       return Tx_Extbase_Reflection_ObjectAccess::getProperty($object, $propertyName, TRUE);
+               }
+       }
+
+       /**
+        * Checks if the specified property of the given object is valid, and adds
+        * found errors to the $messages object.
+        *
+        * @param mixed $value The value to be validated
+        * @param array $validators The validators to be called on the value
+        * @param Tx_Extbase_Error_Result $messages the result object to which the validation errors should be added
+        * @return void
+        * @author Sebastian Kurfürst <sebastian@typo3.org>
+        */
+
+       protected function checkProperty($value, $validators, Tx_Extbase_Error_Result $messages) {
+               foreach ($validators as $validator) {
+                       $messages->merge($validator->validate($value));
+               }
+       }
+
        /**
         * Checks if the given value is valid according to the property validators
         *
@@ -48,6 +131,7 @@ class Tx_Extbase_Validation_Validator_GenericObjectValidator extends Tx_Extbase_
         * @param mixed $value The value that should be validated
         * @return boolean TRUE if the value is valid, FALSE if an error occured
         * @api
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function isValid($value) {
                if (!is_object($value)) {
@@ -84,6 +168,7 @@ class Tx_Extbase_Validation_Validator_GenericObjectValidator extends Tx_Extbase_
         * @param string $propertyName Name of the property to validate
         * @return boolean TRUE if the property value is valid, FALSE if an error occured
         * @api
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function isPropertyValid($object, $propertyName) {
                if (!is_object($object)) throw new InvalidArgumentException('Object expected, ' . gettype($object) . ' given.', 1241099149);
@@ -103,6 +188,7 @@ class Tx_Extbase_Validation_Validator_GenericObjectValidator extends Tx_Extbase_
         * @param array $errors Array of Tx_Extbase_Validation_Error
         * @param string $propertyName Name of the property to add errors
         * @return void
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        protected function addErrorsForProperty($errors, $propertyName) {
                if (!isset($this->errors[$propertyName])) {
index c56f39b..47a3c56 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -44,6 +44,13 @@ class Tx_Extbase_Validation_Validator_NumberRangeValidator extends Tx_Extbase_Va
         * @return boolean TRUE if the value is within the range, otherwise FALSE
         */
        public function isValid($value) {
+               if (isset($this->options['minimum'])) {
+                       $this->options['startRange'] = $this->options['minimum'];
+               }
+               if (isset($this->options['maximum'])) {
+                       $this->options['endRange'] = $this->options['maximum'];
+               }
+
                $this->errors = array();
                if (!is_numeric($value)) {
                        $this->addError('The given subject was not a valid number.', 1221563685);
index a3c0c29..bada273 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -31,6 +31,7 @@
  * @package Extbase
  * @subpackage Validation\Validator
  * @version $Id$
+ * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
  */
 interface Tx_Extbase_Validation_Validator_ObjectValidatorInterface extends Tx_Extbase_Validation_Validator_ValidatorInterface {
 
index 57f3200..61feb52 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -39,6 +39,7 @@ class Tx_Extbase_Validation_Validator_RawValidator implements Tx_Extbase_Validat
         *
         * @param mixed $value The value that should be validated
         * @return boolean TRUE
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function isValid($value) {
                return TRUE;
@@ -49,6 +50,7 @@ class Tx_Extbase_Validation_Validator_RawValidator implements Tx_Extbase_Validat
         *
         * @param array $options Not used
         * @return void
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function setOptions(array $options) {
        }
@@ -57,10 +59,23 @@ class Tx_Extbase_Validation_Validator_RawValidator implements Tx_Extbase_Validat
         * Returns an array of errors which occurred during the last isValid() call.
         *
         * @return array An array of error messages or an empty array if no errors occurred.
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0
         */
        public function getErrors() {
                return array();
        }
 
+       /**
+        * Always returns TRUE
+        *
+        * @param mixed $value The value that should be validated
+        * @return \F3\FLOW3\Error\Result
+        * @author Robert Lemke <robert@typo3.org>
+        * @api
+        */
+       public function validate($value) {
+               return new Tx_Extbase_Error_Result();
+       }
+
 }
 ?>
\ No newline at end of file
index 7f69e7e..b795c5c 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -46,7 +46,13 @@ class Tx_Extbase_Validation_Validator_StringValidator extends Tx_Extbase_Validat
         * @api
         */
        public function isValid($value) {
-               return is_string($value);
+               if(!is_string($value)) {
+                       $this->addError('A valid string is expected.', 1238108067);
+                       return FALSE;
+               }
+
+               return TRUE;
+
        }
 }
 
index 6346938..557042a 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 ***************************************************************/
 
 /**
- * Contract for a validator
+ * Contract for a validator. This interface has drastically changed with Extbase 1.4.0, so that's why this interface does not contain any mandatory methods.
+ *
+ * For compatibility with Extbase < 1.4.0, the following methods need to exist:
+ * - setOptions($options) to set validation options
+ * - isValid($object) to check whether an object is valid (returns boolean value)
+ * - getErrors() to get errors occuring during validation.
+ *
+ * For Extbase >= 1.4.0, the following methods need to exist:
+ * - __construct($options) to set validation options
+ * - validate($object) to check whether the given object is valid. Returns a Tx_Extbase_Error_Result object which can then be checked for validity.
+ *
+ * Please see the source file for proper documentation of the above methods.
  *
  * @package Extbase
  * @subpackage Validation\Validator
- * @version $ID:$
+ * @version $ID:
+ * @api
  */
 interface Tx_Extbase_Validation_Validator_ValidatorInterface {
 
        /**
+        * Sets validation options for the validator
+        *
+        * @param array $validationOptions The validation options
+        * @api
+        */
+       //public function __construct(array $validationOptions = array());
+
+       /**
+        * Checks if the given value is valid according to the validator, and returns
+        * the Error Messages object which occured.
+        *
+        * @param mixed $value The value that should be validated
+        * @return \F3\FLOW3\Error\Result
+        * @api
+        */
+       //public function validate($value);
+
+       /**
         * Checks if the given value is valid according to the validator.
         *
         * If at least one error occurred, the result is FALSE and any errors can
@@ -45,23 +75,26 @@ interface Tx_Extbase_Validation_Validator_ValidatorInterface {
         *
         * @param mixed $value The value that should be validated
         * @return boolean TRUE if the value is valid, FALSE if an error occured
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. use validate() instead.
         */
-       public function isValid($value);
+       //public function isValid($value);
 
        /**
         * Sets validation options for the validator
         *
         * @param array $validationOptions The validation options
         * @return void
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. Use constructor instead.
         */
-       public function setOptions(array $validationOptions);
+       //public function setOptions(array $validationOptions);
 
        /**
         * Returns an array of errors which occurred during the last isValid() call.
         *
         * @return array An array of error messages or an empty array if no errors occurred.
+        * @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0. The errors are returned from validate() now.
         */
-       public function getErrors();
+       //public function getErrors();
 
 }
 
index c0b475e..865cb6f 100644 (file)
@@ -113,12 +113,14 @@ class Tx_Extbase_Validation_ValidatorResolver implements t3lib_Singleton {
        public function createValidator($validatorName, array $validatorOptions = array()) {
                $validatorClassName = $this->resolveValidatorObjectName($validatorName);
                if ($validatorClassName === FALSE) return NULL;
-               $validator = $this->objectManager->get($validatorClassName);
+               $validator = $this->objectManager->get($validatorClassName, $validatorOptions);
                if (!($validator instanceof Tx_Extbase_Validation_Validator_ValidatorInterface)) {
                        return NULL;
                }
-
-               $validator->setOptions($validatorOptions);
+               if (method_exists($validator, 'setOptions')) {
+                               // @deprecated since Extbase 1.4.0, will be removed in Extbase 1.6.0.
+                       $validator->setOptions($validatorOptions);
+               }
                return $validator;
        }
 
@@ -280,7 +282,7 @@ class Tx_Extbase_Validation_ValidatorResolver implements t3lib_Singleton {
        /**
         * Removes escapings from a given argument string and trims the outermost
         * quotes.
-        * 
+        *
         * This method is meant as a helper for regular expression results.
         *
         * @param string &$quotedValue Value to unquote
index 9099293..c7f7ea2 100644 (file)
@@ -38,7 +38,7 @@ class Tx_Extbase_Tests_Unit_Reflection_Fixture_DummyClassWithGettersAndSetters {
 
        protected $protectedProperty;
 
-       protected $unexposedProperty;
+       protected $unexposedProperty = 'unexposed';
 
        public $publicProperty;
        public $publicProperty2 = 42;
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTestcase.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/AbstractValidatorTestcase.php
new file mode 100644 (file)
index 0000000..56de355
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+/*                                                                        *
+ * 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 Validator
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+abstract class Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       protected $validatorClassName;
+
+       /**
+        *
+        * @var Tx_Extbase_Validation_Validator_ValidatorInterface
+        */
+       protected $validator;
+
+       public function setUp() {
+               $this->validator = $this->getValidator();
+       }
+
+       protected function getValidator($options = array()) {
+               $validator = new $this->validatorClassName($options);
+
+               return $validator;
+       }
+
+       protected function validatorOptions($options) {
+               $this->validator = $this->getValidator($options);
+       }
+}
+
+?>
\ No newline at end of file
index b6f39c4..935df4e 100644 (file)
@@ -1,62 +1,59 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the alphanumeric validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: AlphanumericValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_AlphanumericValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_AlphanumericValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_AlphanumericValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function alphanumericValidatorReturnsTrueForAnAlphanumericString() {
-               $alphanumericValidator = new Tx_Extbase_Validation_Validator_AlphanumericValidator();
-               $this->assertTrue($alphanumericValidator->isValid('12ssDF34daweidf'));
+       public function alphanumericValidatorShouldReturnNoErrorsForAnAlphanumericString() {
+               $this->assertFalse($this->validator->validate('12ssDF34daweidf')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function alphanumericValidatorReturnsFalseForAStringWithSpecialCharacters() {
-       $alphanumericValidator = $this->getMock('Tx_Extbase_Validation_Validator_AlphanumericValidator', array('addError'), array(), '', FALSE);
-       $this->assertFalse($alphanumericValidator->isValid('adsf%&/$jklsfdö'));
+       public function alphanumericValidatorReturnsErrorsForAStringWithSpecialCharacters() {
+               $this->assertTrue($this->validator->validate('adsf%&/$jklsfdö')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function alphanumericValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $alphanumericValidator = $this->getMock('Tx_Extbase_Validation_Validator_AlphanumericValidator', array('addError'), array(), '', FALSE);
-               $alphanumericValidator->expects($this->once())->method('addError')->with('The given subject was not a valid alphanumeric string.', 1221551320);
-               $alphanumericValidator->isValid('adsf%&/$jklsfdö');
+               $this->assertEquals(1, count($this->validator->validate('adsf%&/$jklsfdö')->getErrors()));
+
        }
 }
 
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/AlphanumericValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/AlphanumericValidatorTest.php
new file mode 100644 (file)
index 0000000..2aa3038
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the alphanumeric validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: AlphanumericValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_AlphanumericValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function alphanumericValidatorReturnsTrueForAnAlphanumericString() {
+               $alphanumericValidator = new Tx_Extbase_Validation_Validator_AlphanumericValidator();
+               $this->assertTrue($alphanumericValidator->isValid('12ssDF34daweidf'));
+       }
+
+       /**
+        * @test
+        */
+       public function alphanumericValidatorReturnsFalseForAStringWithSpecialCharacters() {
+               $alphanumericValidator = $this->getMock('Tx_Extbase_Validation_Validator_AlphanumericValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($alphanumericValidator->isValid('adsf%&/$jklsfdö'));
+       }
+
+       /**
+        * @test
+        */
+       public function alphanumericValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
+               $alphanumericValidator = $this->getMock('Tx_Extbase_Validation_Validator_AlphanumericValidator', array('addError'), array(), '', FALSE);
+               $alphanumericValidator->expects($this->once())->method('addError')->with('The given subject was not a valid alphanumeric string.', 1221551320);
+               $alphanumericValidator->isValid('adsf%&/$jklsfdö');
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/ConjunctionValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/ConjunctionValidatorTest.php
new file mode 100644 (file)
index 0000000..1d787b9
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the Conjunction Validators
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: ConjunctionValidator_testcase.php 1729 2009-11-25 21:37:20Z stucki $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_ConjunctionValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function addingValidatorsToAJunctionValidatorWorks() {
+               $proxyClassName = $this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_ConjunctionValidator');
+               $conjunctionValidator = new $proxyClassName;
+
+               $mockValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid'));
+               $conjunctionValidator->addValidator($mockValidator);
+               $this->assertTrue($conjunctionValidator->_get('validators')->contains($mockValidator));
+       }
+
+       /**
+        * @test
+        */
+       public function allValidatorsInTheConjunctionAreCalledEvenIfOneReturnsFalse() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid'));
+               $validatorObject->expects($this->once())->method('isValid')->will($this->returnValue(TRUE));
+
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid', 'getErrors'));
+               $secondValidatorObject->expects($this->once())->method('isValid')->will($this->returnValue(FALSE));
+               $secondValidatorObject->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
+
+               $thirdValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid'));
+               $thirdValidatorObject->expects($this->once())->method('isValid')->will($this->returnValue(TRUE));
+
+               $validatorConjunction->addValidator($validatorObject);
+               $validatorConjunction->addValidator($secondValidatorObject);
+               $validatorConjunction->addValidator($thirdValidatorObject);
+
+               $validatorConjunction->isValid('some subject');
+       }
+
+       /**
+        * @test
+        */
+       public function validatorConjunctionReturnsTrueIfAllJunctionedValidatorsReturnTrue() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid'));
+               $validatorObject->expects($this->any())->method('isValid')->will($this->returnValue(TRUE));
+
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid'));
+               $secondValidatorObject->expects($this->any())->method('isValid')->will($this->returnValue(TRUE));
+
+               $validatorConjunction->addValidator($validatorObject);
+               $validatorConjunction->addValidator($secondValidatorObject);
+
+               $this->assertTrue($validatorConjunction->isValid('some subject'));
+       }
+
+       /**
+        * @test
+        */
+       public function validatorConjunctionReturnsFalseIfOneValidatorReturnsFalse() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('isValid', 'getErrors'));
+               $validatorObject->expects($this->any())->method('isValid')->will($this->returnValue(FALSE));
+               $validatorObject->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
+
+               $validatorConjunction->addValidator($validatorObject);
+
+               $this->assertFalse($validatorConjunction->isValid('some subject'));
+       }
+
+       /**
+        * @test
+        */
+       public function removingAValidatorOfTheValidatorConjunctionWorks() {
+               $validatorConjunction = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_ConjunctionValidator'), array('dummy'), array(), '', TRUE);
+
+               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+
+               $validatorConjunction->addValidator($validator1);
+               $validatorConjunction->addValidator($validator2);
+
+               $validatorConjunction->removeValidator($validator1);
+
+               $this->assertFalse($validatorConjunction->_get('validators')->contains($validator1));
+               $this->assertTrue($validatorConjunction->_get('validators')->contains($validator2));
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_Validation_Exception_NoSuchValidator
+        */
+       public function removingANotExistingValidatorIndexThrowsException() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+               $validator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validatorConjunction->removeValidator($validator);
+       }
+
+       /**
+        * @test
+        */
+       public function countReturnesTheNumberOfValidatorsContainedInTheConjunction() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+
+               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+
+               $this->assertSame(0, count($validatorConjunction));
+
+               $validatorConjunction->addValidator($validator1);
+               $validatorConjunction->addValidator($validator2);
+
+               $this->assertSame(2, count($validatorConjunction));
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/DateTimeValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/DateTimeValidatorTest.php
new file mode 100644 (file)
index 0000000..aab543d
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the DateTime validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: DateTimeValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_DateTimeValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function dateTimeValidatorReturnsTrueForAValidDateTimeObject() {
+               $dateTimeValidator = new Tx_Extbase_Validation_Validator_DateTimeValidator();
+               $this->assertTrue($dateTimeValidator->isValid(new DateTime));
+       }
+
+       /**
+        * @test
+        */
+       public function dateTimeValidatorReturnsFalseForAnInvalidDateTimeObject() {
+               $dateTimeValidator = $this->getMock('Tx_Extbase_Validation_Validator_DateTimeValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($dateTimeValidator->isValid('blah'));
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/EmailAddressValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/EmailAddressValidatorTest.php
new file mode 100644 (file)
index 0000000..481cd40
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the email address validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: EmailAddressValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * Data provider with valid email addresses
+        *
+        * @return array
+        */
+       public function validAddresses() {
+               return array(
+                       array('andreas.foerthner@netlogix.de'),
+                       array('user@localhost'),
+                       array('user@localhost.localdomain'),
+                       array('info@guggenheim.museum'),
+                       array('just@test.invalid'),
+                       array('just+spam@test.de'),
+                       array('local@192.168.0.2')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validAddresses
+        */
+       public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
+               $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
+               $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
+       }
+
+       /**
+        * Data provider with invalid email addresses
+        *
+        * @return array
+        */
+       public function invalidAddresses() {
+               return array(
+                       array('andreas.foerthner@'),
+                       array('andreas@foerthner@example.com'),
+                       array('@typo3.org'),
+                       array('someone@typo3.'),
+                       array('local@192.168.2'),
+                       array('local@192.168.270.1'),
+                       array('just@test.invalid ')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidAddresses
+        */
+       public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
+               $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($emailAddressValidator->isValid($address));
+       }
+
+       /**
+        * @test
+        */
+       public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
+               $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
+               $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
+               $emailAddressValidator->isValid('notAValidMail@Address');
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/FloatValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/FloatValidatorTest.php
new file mode 100644 (file)
index 0000000..f1a7f4b
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the float validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: FloatValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_FloatValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * Data provider with valid floating point numbers
+        *
+        * @return array Floats, both as float and string
+        */
+       public function validFloatingPointNumbers() {
+               return array(
+                       array(1029437.234726),
+                       array(-666.66),
+                       array('123.45'),
+                       array('+123.45'),
+                       array('-123.45'),
+                       array('123.45e3'),
+                       array(123.45e3)
+               );
+       }
+
+       /**
+        * Data provider with valid floating point numbers
+        *
+        * @return array Floats, both as float and string
+        */
+       public function invalidFloatingPointNumbers() {
+               return array(
+                       array(1029437),
+                       array(-666),
+                       array('1029437'),
+                       array('-666'),
+                       array('not a number')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validFloatingPointNumbers
+        */
+       public function floatValidatorReturnsTrueForAValidFloat($number) {
+               $floatValidator = new Tx_Extbase_Validation_Validator_FloatValidator();
+               $this->assertTrue($floatValidator->isValid($number), "Validator declared $number as invalid though it is valid.");
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidFloatingPointNumbers
+        */
+       public function floatValidatorReturnsFalseForAnInvalidFloat($number) {
+               $floatValidator = $this->getMock('Tx_Extbase_Validation_Validator_FloatValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($floatValidator->isValid($number), "Validator declared $number as valid though it is invalid.");
+       }
+
+       /**
+        * @test
+        */
+       public function floatValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
+               $floatValidator = new Tx_Extbase_Validation_Validator_FloatValidator();
+               $floatValidator = $this->getMock('Tx_Extbase_Validation_Validator_FloatValidator', array('addError'), array(), '', FALSE);
+               $floatValidator->expects($this->once())->method('addError')->with('The given subject was not a valid float.', 1221560288);
+               $floatValidator->isValid(123456);
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/GenericObjectValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/GenericObjectValidatorTest.php
new file mode 100644 (file)
index 0000000..b3b290d
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the Generic Object Validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: GenericObjectValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_GenericObjectValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function isValidReturnsFalseIfTheValueIsNoObject() {
+               $validator = $this->getMock('Tx_Extbase_Validation_Validator_GenericObjectValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($validator->isValid('foo'));
+       }
+
+       /**
+        * @test
+        */
+       public function isValidChecksAllPropertiesForWhichAPropertyValidatorExists() {
+               $mockPropertyValidators = array('foo' => 'validator', 'bar' => 'validator');
+               $mockObject = new stdClass;
+
+               $validator = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_GenericObjectValidator'), array('addError', 'isPropertyValid'), array(), '', FALSE);
+               $validator->_set('propertyValidators', $mockPropertyValidators);
+
+               $validator->expects($this->at(0))->method('isPropertyValid')->with($mockObject, 'foo')->will($this->returnValue(TRUE));
+               $validator->expects($this->at(1))->method('isPropertyValid')->with($mockObject, 'bar')->will($this->returnValue(TRUE));
+
+               $validator->isValid($mockObject);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/IntegerValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/IntegerValidatorTest.php
new file mode 100644 (file)
index 0000000..233fe15
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the integer validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: IntegerValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_IntegerValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * Data provider with valid integer numbers
+        *
+        * @return array Integers, both as int and strings
+        */
+       public function validIntegerNumbers() {
+               return array(
+                       array(1029437),
+                       array(-666),
+                       array('12345'),
+                       array('+12345'),
+                       array('-12345')
+               );
+       }
+
+       /**
+        * Data provider with invalid integer numbers
+        *
+        * @return array Various values of int, float and strings
+        */
+       public function invalidIntegerNumbers() {
+               return array(
+                       array('not a number'),
+                       array(3.1415),
+                       array(-0.75),
+                       array('12345.987'),
+                       array('-123.45')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validIntegerNumbers
+        */
+       public function integerValidatorReturnsTrueForAValidInteger($number) {
+               $integerValidator = new Tx_Extbase_Validation_Validator_IntegerValidator();
+               $this->assertTrue($integerValidator->isValid($number), "Validator declared $number as invalid though it is valid.");
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidIntegerNumbers
+        */
+       public function integerValidatorReturnsFalseForAnInvalidInteger($number) {
+               $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($integerValidator->isValid($number), "Validator declared $number as valid though it is invalid.");
+       }
+
+       /**
+        * @test
+        */
+       public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
+               $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
+               $integerValidator->expects($this->once())->method('addError')->with('The given subject was not a valid integer.', 1221560494);
+               $integerValidator->isValid('not a number');
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NotEmptyValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NotEmptyValidatorTest.php
new file mode 100644 (file)
index 0000000..00660ce
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the not empty validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: NotEmptyValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_NotEmptyValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function notEmptyValidatorReturnsTrueForASimpleString() {
+               $notEmptyValidator = new Tx_Extbase_Validation_Validator_NotEmptyValidator();
+               $this->assertTrue($notEmptyValidator->isValid('a not empty string'));
+       }
+
+       /**
+        * @test
+        */
+       public function notEmptyValidatorReturnsFalseForAnEmptyString() {
+               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($notEmptyValidator->isValid(''));
+       }
+
+       /**
+        * @test
+        */
+       public function notEmptyValidatorReturnsFalseForANullValue() {
+               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($notEmptyValidator->isValid(NULL));
+       }
+
+       /**
+        * @test
+        */
+       public function notEmptyValidatorCreatesTheCorrectErrorForAnEmptySubject() {
+               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was empty.', 1221560718);
+               $notEmptyValidator->isValid('');
+       }
+
+       /**
+        * @test
+        */
+       public function notEmptyValidatorCreatesTheCorrectErrorForANullValue() {
+               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was NULL.', 1221560910);
+               $notEmptyValidator->isValid(NULL);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php
new file mode 100644 (file)
index 0000000..dbab0b0
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the number range validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: NumberRangeValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_NumberRangeValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorReturnsTrueForASimpleIntegerInRange() {
+               $numberRangeValidator = new Tx_Extbase_Validation_Validator_NumberRangeValidator();
+               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
+
+               $this->assertTrue($numberRangeValidator->isValid(10.5));
+       }
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorReturnsFalseForANumberOutOfRange() {
+               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
+               $this->assertFalse($numberRangeValidator->isValid(1000.1));
+       }
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorReturnsTrueForANumberInReversedRange() {
+               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator->setOptions(array('startRange' => 1000, 'endRange' => 0));
+               $this->assertTrue($numberRangeValidator->isValid(100));
+       }
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorReturnsFalseForAString() {
+               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
+               $this->assertFalse($numberRangeValidator->isValid('not a number'));
+       }
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorCreatesTheCorrectErrorForANumberOutOfRange() {
+               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not in the valid range (1 - 42).', 1221561046);
+               $numberRangeValidator->setOptions(array('startRange' => 1, 'endRange' => 42));
+               $numberRangeValidator->isValid(4711);
+       }
+
+       /**
+        * @test
+        */
+       public function numberRangeValidatorCreatesTheCorrectErrorForAStringSubject() {
+               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
+               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 42));
+               $numberRangeValidator->isValid('this is not between 0 an 42');
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberValidatorTest.php
new file mode 100644 (file)
index 0000000..f005571
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the number validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: NumberValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_NumberValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function numberValidatorReturnsTrueForASimpleInteger() {
+               $numberValidator = new Tx_Extbase_Validation_Validator_NumberValidator();
+               $this->assertTrue($numberValidator->isValid(1029437));
+       }
+
+       /**
+        * @test
+        */
+       public function numberValidatorReturnsFalseForAString() {
+               $numberValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($numberValidator->isValid('not a number'));
+       }
+
+       /**
+        * @test
+        */
+       public function numberValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
+               $numberValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberValidator', array('addError'), array(), '', FALSE);
+               $numberValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
+               $numberValidator->isValid('this is not a number');
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RawValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RawValidatorTest.php
new file mode 100644 (file)
index 0000000..83ddede
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the raw validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: RawValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_RawValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function theRawValidatorAlwaysReturnsTRUE() {
+               $rawValidator = new Tx_Extbase_Validation_Validator_RawValidator();
+
+               $this->assertTrue($rawValidator->isValid('simple1expression'));
+               $this->assertTrue($rawValidator->isValid(''));
+               $this->assertTrue($rawValidator->isValid(NULL));
+               $this->assertTrue($rawValidator->isValid(FALSE));
+               $this->assertTrue($rawValidator->isValid(new ArrayObject()));
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RegularExpressionValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RegularExpressionValidatorTest.php
new file mode 100644 (file)
index 0000000..f2ba5b0
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the regular expression validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: RegularExpressionValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_RegularExpressionValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function regularExpressionValidatorMatchesABasicExpressionCorrectly() {
+               $regularExpressionValidator = $this->getMock('Tx_Extbase_Validation_Validator_RegularExpressionValidator', array('addError'), array(), '', FALSE);
+               $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
+
+               $this->assertTrue($regularExpressionValidator->isValid('simple1expression'));
+               $this->assertFalse($regularExpressionValidator->isValid('simple1expressions'));
+       }
+
+       /**
+        * @test
+        */
+       public function regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch() {
+               $regularExpressionValidator = $this->getMock('Tx_Extbase_Validation_Validator_RegularExpressionValidator', array('addError'), array(), '', FALSE);
+               $regularExpressionValidator->expects($this->once())->method('addError')->with('The given subject did not match the pattern.', 1221565130);
+               $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
+               $regularExpressionValidator->isValid('some subject that will not match');
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/StringLengthValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/StringLengthValidatorTest.php
new file mode 100644 (file)
index 0000000..28a2d8a
--- /dev/null
@@ -0,0 +1,193 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the string length validator
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: StringLengthValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_StringLengthValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function stgringLengthValidatorReturnsTrueForAStringShorterThanMaxLengthAndLongerThanMinLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 0, 'maximum' => 50));
+               $this->assertTrue($stringLengthValidator->isValid('this is a very simple string'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsFalseForAStringShorterThanThanMinLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
+               $this->assertFalse($stringLengthValidator->isValid('this is a very short string'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsFalseForAStringLongerThanThanMaxLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 10));
+               $this->assertFalse($stringLengthValidator->isValid('this is a very short string'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueForAStringLongerThanThanMinLengthAndMaxLengthNotSpecified() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 5));
+               $this->assertTrue($stringLengthValidator->isValid('this is a very short string'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueForAStringShorterThanThanMaxLengthAndMinLengthNotSpecified() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('maximum' => 100));
+               $this->assertTrue($stringLengthValidator->isValid('this is a very short string'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueForAStringLengthEqualToMaxLengthAndMinLengthNotSpecified() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('maximum' => 10));
+               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueForAStringLengthEqualToMinLengthAndMaxLengthNotSpecified() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 10));
+               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueIfMinLengthAndMaxLengthAreEqualAndTheGivenStringMatchesThisValue() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 10, 'maximum' => 10));
+               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueIfTheStringLengthIsEqualToMaxLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 1, 'maximum' => 10));
+               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorReturnsTrueIfTheStringLengthIsEqualToMinLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 10, 'maximum' => 100));
+               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_Validation_Exception_InvalidValidationOptions
+        */
+       public function stringLengthValidatorThrowsAnExceptionIfMinLengthIsGreaterThanMaxLength() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 101, 'maximum' => 100));
+               $stringLengthValidator->isValid('1234567890');
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorInsertsAnErrorObjectIfValidationFails() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->expects($this->once())->method('addError');
+               $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
+
+               $stringLengthValidator->isValid('this is a very short string');
+       }
+
+       /**
+        * @test
+        */
+       public function stringLengthValidatorCanHandleAnObjectWithAToStringMethod() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 100));
+
+               $className = uniqid('TestClass');
+
+               eval('
+                       class ' . $className . ' {
+                               public function __toString() {
+                                       return \'some string\';
+                               }
+                       }
+               ');
+
+               $object = new $className();
+               $this->assertTrue($stringLengthValidator->isValid($object));
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_Validation_Exception_InvalidSubject
+        */
+       public function stringLengthValidatorThrowsAnExceptionIfTheGivenObjectCanNotBeConvertedToAString() {
+               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 100));
+
+               $className = uniqid('TestClass');
+
+               eval('
+                       class ' . $className . ' {
+                               protected $someProperty;
+                       }
+               ');
+
+               $object = new $className();
+               $stringLengthValidator->isValid($object);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/TextValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/TextValidatorTest.php
new file mode 100644 (file)
index 0000000..19e0d66
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the text validator.
+ *
+ * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
+ * we do not break backwards compatibility.
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $Id: TextValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_TextValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function textValidatorReturnsTrueForASimpleString() {
+               $textValidator = new Tx_Extbase_Validation_Validator_TextValidator();
+               $this->assertTrue($textValidator->isValid('this is a very simple string'));
+       }
+
+       /**
+        * @test
+        */
+       public function textValidatorAllowsTheNewLineCharacter() {
+               $sampleText = "Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. \nVu dan durch jéngt gréng, ze rou Monn voll stolz. \nKe kille Minutt d'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zënter, Welt Ronn grousse der ke. Wou fond eraus Wisen am. Hu dénen d'Gaassen eng, eng am virun geplot d'Lëtzebuerger, get botze rëscht Blieder si. Dat Dauschen schéinste Milliounen fu. Ze riede méngem Keppchen déi, si gét fergiess erwaacht, räich jéngt duerch en nun. Gëtt Gaas d'Vullen hie hu, laacht Grénge der dé. Gemaacht gehéiert da aus, gutt gudden d'wäiss mat wa.";
+               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
+               $this->assertTrue($textValidator->isValid($sampleText));
+       }
+
+       /**
+        * @test
+        */
+       public function textValidatorAllowsCommonSpecialCharacters() {
+               $sampleText = "3% of most people tend to use semikolae; we need to check & allow that. And hashes (#) are not evil either, nor is the sign called 'quote'.";
+               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
+               $this->assertTrue($textValidator->isValid($sampleText));
+       }
+
+       /**
+        * @test
+        */
+       public function textValidatorReturnsFalseForAStringWithHtml() {
+               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>'));
+       }
+
+       /**
+        * @test
+        */
+       public function textValidatorReturnsFalseForAStringWithPercentEncodedHtml() {
+               $this->markTestIncomplete('The text validator currently allows percent encoded HTML!');
+               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
+               $this->assertFalse($textValidator->isValid('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'));
+       }
+
+       /**
+        * @test
+        */
+       public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
+               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
+               $textValidator->expects($this->once())->method('addError')->with('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
+               $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
+       }
+}
+
+?>
\ No newline at end of file
index 04fdd8b..0f9d969 100644 (file)
@@ -1,45 +1,38 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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 Conjunction Validators
+ * Testcase for the Conjunction Validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: ConjunctionValidator_testcase.php 1729 2009-11-25 21:37:20Z stucki $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
 class Tx_Extbase_Tests_Unit_Validation_Validator_ConjunctionValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
-
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
        public function addingValidatorsToAJunctionValidatorWorks() {
                $proxyClassName = $this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_ConjunctionValidator');
-               $conjunctionValidator = new $proxyClassName;
+               $conjunctionValidator = new $proxyClassName(array());
 
                $mockValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
                $conjunctionValidator->addValidator($mockValidator);
@@ -48,65 +41,76 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_ConjunctionValidatorTest extend
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
+        * @author Robert Lemke <robert@typo3.org>
+        * @author Christopher Hlubek <hlubek@networkteam.com>
         */
-       public function allValidatorsInTheConjunctionAreCalledEvenIfOneReturnsFalse() {
-               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
-               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $validatorObject->expects($this->once())->method('isValid')->will($this->returnValue(TRUE));
+       public function allValidatorsInTheConjunctionAreCalledEvenIfOneReturnsError() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator(array());
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
 
-               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $secondValidatorObject->expects($this->once())->method('isValid')->will($this->returnValue(FALSE));
-               $secondValidatorObject->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
+               $errors = new Tx_Extbase_Error_Result();
+               $errors->addError(new Tx_Extbase_Error_Error('Error', 123));
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $secondValidatorObject->expects($this->once())->method('validate')->will($this->returnValue($errors));
 
-               $thirdValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $thirdValidatorObject->expects($this->once())->method('isValid')->will($this->returnValue(TRUE));
+               $thirdValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $thirdValidatorObject->expects($this->once())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
 
                $validatorConjunction->addValidator($validatorObject);
                $validatorConjunction->addValidator($secondValidatorObject);
                $validatorConjunction->addValidator($thirdValidatorObject);
 
-               $validatorConjunction->isValid('some subject');
+               $validatorConjunction->validate('some subject');
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function validatorConjunctionReturnsTrueIfAllJunctionedValidatorsReturnTrue() {
-               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
-               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $validatorObject->expects($this->any())->method('isValid')->will($this->returnValue(TRUE));
+       public function validatorConjunctionReturnsNoErrorsIfAllJunctionedValidatorsReturnNoErrors() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator(array());
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
 
-               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $secondValidatorObject->expects($this->any())->method('isValid')->will($this->returnValue(TRUE));
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
 
                $validatorConjunction->addValidator($validatorObject);
                $validatorConjunction->addValidator($secondValidatorObject);
 
-               $this->assertTrue($validatorConjunction->isValid('some subject'));
+               $this->assertFalse($validatorConjunction->validate('some subject')->hasErrors());
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
+        * @author Christopher Hlubek <hlubek@networkteam.com>
         */
-       public function validatorConjunctionReturnsFalseIfOneValidatorReturnsFalse() {
-               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
-               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $validatorObject->expects($this->any())->method('isValid')->will($this->returnValue(FALSE));
-               $validatorObject->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
+       public function validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors() {
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator(array());
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+
+               $errors = new Tx_Extbase_Error_Result();
+               $errors->addError(new Tx_Extbase_Error_Error('Error', 123));
+
+               $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
 
                $validatorConjunction->addValidator($validatorObject);
 
-               $this->assertFalse($validatorConjunction->isValid('some subject'));
+               $this->assertTrue($validatorConjunction->validate('some subject')->hasErrors());
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
        public function removingAValidatorOfTheValidatorConjunctionWorks() {
-               $validatorConjunction = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_ConjunctionValidator'), array('dummy'), array(), '', TRUE);
+               $validatorConjunction = $this->getAccessibleMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array('dummy'), array(array()), '', TRUE);
 
-               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
 
                $validatorConjunction->addValidator($validator1);
                $validatorConjunction->addValidator($validator2);
@@ -119,22 +123,24 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_ConjunctionValidatorTest extend
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         * @expectedException Tx_Extbase_Validation_Exception_NoSuchValidator
         */
        public function removingANotExistingValidatorIndexThrowsException() {
-               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
-               $validator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator(array());
+               $validator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
                $validatorConjunction->removeValidator($validator);
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
        public function countReturnesTheNumberOfValidatorsContainedInTheConjunction() {
-               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator();
+               $validatorConjunction = new Tx_Extbase_Validation_Validator_ConjunctionValidator(array());
 
-               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
-               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface');
+               $validator1 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validator2 = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
 
                $this->assertSame(0, count($validatorConjunction));
 
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/DateTimeValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/DateTimeValidatorTest.php
deleted file mode 100644 (file)
index fa879fd..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-
-/**
- * Testcase for the DateTime validator
- *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: DateTimeValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
- */
-class Tx_Extbase_Tests_Unit_Validation_Validator_DateTimeValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
-
-       /**
-        * @test
-        */
-       public function dateTimeValidatorReturnsTrueForAValidDateTimeObject() {
-               $dateTimeValidator = new Tx_Extbase_Validation_Validator_DateTimeValidator();
-               $this->assertTrue($dateTimeValidator->isValid(new DateTime));
-       }
-
-       /**
-        * @test
-        */
-       public function dateTimeValidatorReturnsFalseForAnInvalidDateTimeObject() {
-               $dateTimeValidator = $this->getMock('Tx_Extbase_Validation_Validator_DateTimeValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($dateTimeValidator->isValid('blah'));
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/DisjunctionValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/DisjunctionValidatorTest.php
new file mode 100644 (file)
index 0000000..c411151
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+
+/*                                                                        *
+ * 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 Disjunction Validator
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_DisjunctionValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @test
+        * @author Christopher Hlubek <hlubek@networkteam.com>
+        */
+       public function allValidatorsInTheDisjunctionAreCalledEvenIfOneReturnsNoError() {
+               $validatorDisjunction = new Tx_Extbase_Validation_Validator_DisjunctionValidator(array());
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
+
+               $errors = new Tx_Extbase_Error_Result();
+               $errors->addError(new Tx_Extbase_Error_Error('Error', 123));
+
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $secondValidatorObject->expects($this->exactly(1))->method('validate')->will($this->returnValue($errors));
+
+               $validatorDisjunction->addValidator($validatorObject);
+               $validatorDisjunction->addValidator($secondValidatorObject);
+
+               $validatorDisjunction->validate('some subject');
+       }
+
+       /**
+        * @test
+        * @author Christopher Hlubek <hlubek@networkteam.com>
+        */
+       public function validateReturnsNoErrorsIfOneValidatorReturnsNoError() {
+               $validatorDisjunction = new Tx_Extbase_Validation_Validator_DisjunctionValidator(array());
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new Tx_Extbase_Error_Result()));
+
+               $errors = new Tx_Extbase_Error_Result();
+               $errors->addError(new Tx_Extbase_Error_Error('Error', 123));
+
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
+
+               $validatorDisjunction->addValidator($validatorObject);
+               $validatorDisjunction->addValidator($secondValidatorObject);
+
+               $this->assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
+       }
+
+       /**
+        * @test
+        * @author Christopher Hlubek <hlubek@networkteam.com>
+        */
+       public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors() {
+               $validatorDisjunction = new Tx_Extbase_Validation_Validator_DisjunctionValidator(array());
+
+               $error1 = new Tx_Extbase_Error_Error('Error', 123);
+               $error2 = new Tx_Extbase_Error_Error('Error2', 123);
+
+               $errors1 = new Tx_Extbase_Error_Result();
+               $errors1->addError($error1);
+               $validatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
+
+               $errors2 = new Tx_Extbase_Error_Result();
+               $errors2->addError($error2);
+               $secondValidatorObject = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
+
+               $validatorDisjunction->addValidator($validatorObject);
+               $validatorDisjunction->addValidator($secondValidatorObject);
+
+               $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
+       }
+}
+
+?>
\ No newline at end of file
index 57f4eb2..98a27b4 100644 (file)
@@ -1,43 +1,41 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the email address validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: EmailAddressValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_EmailAddressValidator';
 
        /**
         * Data provider with valid email addresses
         *
         * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
        public function validAddresses() {
                return array(
@@ -47,54 +45,55 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest exten
                        array('info@guggenheim.museum'),
                        array('just@test.invalid'),
                        array('just+spam@test.de'),
+                       array('just+spam@192.168.249.100'),
                        array('local@192.168.0.2')
                );
        }
 
        /**
+        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
         * @dataProvider validAddresses
         */
-       public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
-               $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
-               $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
+       public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
+               $this->assertFalse($this->validator->validate($address)->hasErrors());
        }
 
        /**
         * Data provider with invalid email addresses
         *
         * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
        public function invalidAddresses() {
                return array(
                        array('andreas.foerthner@'),
-                       array('andreas@foerthner@example.com'),
                        array('@typo3.org'),
                        array('someone@typo3.'),
                        array('local@192.168.2'),
                        array('local@192.168.270.1'),
-                       array('just@test.invalid ')
+                       array('foo@bar.com' . chr(0)),
+                       array('foo@bar.org' . chr(10)),
+                       array('andreas@foerthner@example.com'),
+                       array('some@one.net ')
                );
        }
 
        /**
+        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
         * @dataProvider invalidAddresses
         */
        public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
-               $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($emailAddressValidator->isValid($address));
+               $this->assertTrue($this->validator->validate($address)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
-               $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
-               $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
-               $emailAddressValidator->isValid('notAValidMail@Address');
+               $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
        }
-
 }
-
 ?>
\ No newline at end of file
index fd1f997..4add06c 100644 (file)
@@ -1,97 +1,91 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the float validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: FloatValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_FloatValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_FloatValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_FloatValidator';
 
        /**
-        * Data provider with valid floating point numbers
+        * Data provider with valid floats
         *
-        * @return array Floats, both as float and string
+        * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function validFloatingPointNumbers() {
+       public function validFloats() {
                return array(
                        array(1029437.234726),
-                       array(-666.66),
                        array('123.45'),
                        array('+123.45'),
                        array('-123.45'),
                        array('123.45e3'),
                        array(123.45e3)
-                       );
+               );
+       }
+
+       /**
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        * @test
+        * @dataProvider validFloats
+        */
+       public function floatValidatorReturnsNoErrorsForAValidFloat($float) {
+               $this->assertFalse($this->validator->validate($float)->hasErrors());
        }
 
        /**
-        * Data provider with valid floating point numbers
+        * Data provider with invalid floats
         *
-        * @return array Floats, both as float and string
+        * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function invalidFloatingPointNumbers() {
+       public function invalidFloats() {
                return array(
                        array(1029437),
-                       array(-666),
                        array('1029437'),
-                       array('-666'),
                        array('not a number')
-                       );
+               );
        }
 
        /**
+        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
-        * @dataProvider validFloatingPointNumbers
+        * @dataProvider invalidFloats
         */
-       public function floatValidatorReturnsTrueForAValidFloat($number) {
-               $floatValidator = new Tx_Extbase_Validation_Validator_FloatValidator();
-               $this->assertTrue($floatValidator->isValid($number), "Validator declared $number as invalid though it is valid.");
+       public function floatValidatorReturnsErrorForAnInvalidFloat($float) {
+               $this->assertTrue($this->validator->validate($float)->hasErrors());
        }
 
        /**
-        * @test
-        * @dataProvider invalidFloatingPointNumbers
-        */
-       public function floatValidatorReturnsFalseForAnInvalidFloat($number) {
-               $floatValidator = $this->getMock('Tx_Extbase_Validation_Validator_FloatValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($floatValidator->isValid($number), "Validator declared $number as valid though it is invalid.");
-       }
-
-       /**
-        * @test
+        * test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function floatValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $floatValidator = new Tx_Extbase_Validation_Validator_FloatValidator();
-               $floatValidator = $this->getMock('Tx_Extbase_Validation_Validator_FloatValidator', array('addError'), array(), '', FALSE);
-               $floatValidator->expects($this->once())->method('addError')->with('The given subject was not a valid float.', 1221560288);
-               $floatValidator->isValid(123456);
+               $this->assertEquals(1, count($this->validator->validate(123456)->getErrors()));
        }
 
 }
index 55faee2..9e1280b 100644 (file)
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the Generic Object Validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: GenericObjectValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_GenericObjectValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_GenericObjectValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_GenericObjectValidator';
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
-       public function isValidReturnsFalseIfTheValueIsNoObject() {
-               $validator = $this->getMock('Tx_Extbase_Validation_Validator_GenericObjectValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($validator->isValid('foo'));
+       public function validatorShouldReturnErrorsIfTheValueIsNoObjectAndNotNull() {
+               $this->assertTrue($this->validator->validate('foo')->hasErrors());
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
-       public function isValidChecksAllPropertiesForWhichAPropertyValidatorExists() {
-               $mockPropertyValidators = array('foo' => 'validator', 'bar' => 'validator');
-               $mockObject = new stdClass;
+       public function validatorShouldReturnNoErrorsIfTheValueIsNull() {
+               $this->assertFalse($this->validator->validate(NULL)->hasErrors());
+       }
+
+       public function dataProviderForValidator() {
+               $error1 = new Tx_Extbase_Error_Error('error1', 1);
+               $error2 = new Tx_Extbase_Error_Error('error2', 2);
+
+               $emptyResult1 = new Tx_Extbase_Error_Result();
+               $emptyResult2 = new Tx_Extbase_Error_Result();
+
+               $resultWithError1 = new Tx_Extbase_Error_Result();
+               $resultWithError1->addError($error1);
+
+               $resultWithError2 = new Tx_Extbase_Error_Result();
+               $resultWithError2->addError($error2);
+
+               $classNameForObjectWithPrivateProperties = 'B' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameForObjectWithPrivateProperties . '{ protected $foo = \'foovalue\'; protected $bar = \'barvalue\'; }');
+               $objectWithPrivateProperties = new $classNameForObjectWithPrivateProperties();
+
+               return array(
+                       // If no errors happened, this is shown
+                       array($objectWithPrivateProperties, $emptyResult1, $emptyResult2, array()),
+
+                       // If errors on two properties happened, they are merged together.
+                       array($objectWithPrivateProperties, $resultWithError1, $resultWithError2, array('foo' => array($error1), 'bar' => array($error2)))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider dataProviderForValidator
+        * @author Robert Lemke <robert@typo3.org>
+        */
+       public function validateChecksAllPropertiesForWhichAPropertyValidatorExists($mockObject, $validationResultForFoo, $validationResultForBar, $errors) {
+
+               $validatorForFoo = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorForFoo->expects($this->once())->method('validate')->with('foovalue')->will($this->returnValue($validationResultForFoo));
+
+               $validatorForBar = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $validatorForBar->expects($this->once())->method('validate')->with('barvalue')->will($this->returnValue($validationResultForBar));
+
+               $this->validator->addPropertyValidator('foo', $validatorForFoo);
+               $this->validator->addPropertyValidator('bar', $validatorForBar);
+               $this->assertEquals($errors, $this->validator->validate($mockObject)->getFlattenedErrors());
+       }
+
+       /**
+        * @test
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        */
+       public function validateCanHandleRecursiveTargetsWithoutEndlessLooping() {
+               $classNameA = 'B' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameA . '{ public $b; }');
+               $classNameB = 'B' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameB . '{ public $a; }');
+               $A = new $classNameA();
+               $B = new $classNameB();
+               $A->b = $B;
+               $B->a = $A;
+
+               $aValidator = new Tx_Extbase_Validation_Validator_GenericObjectValidator(array());
+               $bValidator = new Tx_Extbase_Validation_Validator_GenericObjectValidator(array());
+               $aValidator->addPropertyValidator('b', $bValidator);
+               $bValidator->addPropertyValidator('a', $aValidator);
+
+               $this->assertFalse($aValidator->validate($A)->hasErrors());
+       }
+
+       /**
+        * @test
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        */
+       public function validateDetectsFailuresInRecursiveTargetsI() {
+               $classNameA = 'A' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameA . '{ public $b; }');
+               $classNameB = 'B' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameB . '{ public $a; public $uuid = 0xF; }');
+               $A = new $classNameA();
+               $B = new $classNameB();
+               $A->b = $B;
+               $B->a = $A;
+
+               $aValidator = $this->getValidator();
+               $bValidator = $this->getValidator();
+
+               $aValidator->addPropertyValidator('b', $bValidator);
+               $bValidator->addPropertyValidator('a', $aValidator);
+
+               $error = new Tx_Extbase_Error_Error('error1', 123);
+               $result = new Tx_Extbase_Error_Result();
+               $result->addError($error);
+               $mockUuidValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $mockUuidValidator->expects($this->any())->method('validate')->with(0xF)->will($this->returnValue($result));
+               $bValidator->addPropertyValidator('uuid', $mockUuidValidator);
+
+               $this->assertSame(array('b.uuid' => array($error)), $aValidator->validate($A)->getFlattenedErrors());
+       }
+
+       /**
+        * @test
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        */
+       public function validateDetectsFailuresInRecursiveTargetsII() {
+               $classNameA = 'A' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameA . '{ public $b; public $uuid = 0xF; }');
+               $classNameB = 'B' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $classNameB . '{ public $a; public $uuid = 0xF; }');
+               $A = new $classNameA();
+               $B = new $classNameB();
+               $A->b = $B;
+               $B->a = $A;
+
+               $aValidator = $this->getValidator();
+               $bValidator = $this->getValidator();
 
-               $validator = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Validation_Validator_GenericObjectValidator'), array('addError', 'isPropertyValid'), array(), '', FALSE);
-               $validator->_set('propertyValidators', $mockPropertyValidators);
+               $aValidator->addPropertyValidator('b', $bValidator);
+               $bValidator->addPropertyValidator('a', $aValidator);
 
-               $validator->expects($this->at(0))->method('isPropertyValid')->with($mockObject, 'foo')->will($this->returnValue(TRUE));
-               $validator->expects($this->at(1))->method('isPropertyValid')->with($mockObject, 'bar')->will($this->returnValue(TRUE));
+               $error1 = new Tx_Extbase_Error_Error('error1', 123);
+               $result1 = new Tx_Extbase_Error_Result();
+               $result1->addError($error1);
+               $mockUuidValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array('validate'));
+               $mockUuidValidator->expects($this->any())->method('validate')->with(0xF)->will($this->returnValue($result1));
+               $aValidator->addPropertyValidator('uuid', $mockUuidValidator);
+               $bValidator->addPropertyValidator('uuid', $mockUuidValidator);
 
-               $validator->isValid($mockObject);
+               $this->assertSame(array('b.uuid' => array($error1), 'uuid' => array($error1)), $aValidator->validate($A)->getFlattenedErrors());
        }
 }
 
index c68fc40..1a6c7fe 100644 (file)
@@ -1,94 +1,89 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the integer validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: IntegerValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_IntegerValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_IntegerValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_IntegerValidator';
 
        /**
-        * Data provider with valid integer numbers
+        * Data provider with valid integers
         *
-        * @return array Integers, both as int and strings
+        * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function validIntegerNumbers() {
+       public function validIntegers() {
                return array(
                        array(1029437),
-                       array(-666),
                        array('12345'),
                        array('+12345'),
                        array('-12345')
-                       );
+               );
        }
 
        /**
-        * Data provider with invalid integer numbers
-        *
-        * @return array Various values of int, float and strings
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        * @test
+        * @dataProvider validIntegers
         */
-       public function invalidIntegerNumbers() {
-               return array(
-                       array('not a number'),
-                       array(3.1415),
-                       array(-0.75),
-                       array('12345.987'),
-                       array('-123.45')
-                       );
+       public function integerValidatorReturnsNoErrorsForAValidInteger($integer) {
+               $this->assertFalse($this->validator->validate($integer)->hasErrors());
        }
 
        /**
-        * @test
-        * @dataProvider validIntegerNumbers
+        * Data provider with invalid integers
+        *
+        * @return array
+        * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function integerValidatorReturnsTrueForAValidInteger($number) {
-               $integerValidator = new Tx_Extbase_Validation_Validator_IntegerValidator();
-               $this->assertTrue($integerValidator->isValid($number), "Validator declared $number as invalid though it is valid.");
+       public function invalidIntegers() {
+               return array(
+                       array('not a number'),
+                       array(3.1415),
+                       array('12345.987')
+               );
        }
 
        /**
+        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
-        * @dataProvider invalidIntegerNumbers
+        * @dataProvider invalidIntegers
         */
-       public function integerValidatorReturnsFalseForAnInvalidInteger($number) {
-               $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($integerValidator->isValid($number), "Validator declared $number as valid though it is invalid.");
+       public function integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger) {
+               $this->assertTrue($this->validator->validate($invalidInteger)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
-               $integerValidator->expects($this->once())->method('addError')->with('The given subject was not a valid integer.', 1221560494);
-               $integerValidator->isValid('not a number');
+               $this->assertEquals(1, count($this->validator->validate('not a number')->getErrors()));
        }
 
 }
index fff3f23..6a836e9 100644 (file)
@@ -1,79 +1,74 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the not empty validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: NotEmptyValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_NotEmptyValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_NotEmptyValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_NotEmptyValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function notEmptyValidatorReturnsTrueForASimpleString() {
-               $notEmptyValidator = new Tx_Extbase_Validation_Validator_NotEmptyValidator();
-               $this->assertTrue($notEmptyValidator->isValid('a not empty string'));
+       public function notEmptyValidatorReturnsNoErrorForASimpleString() {
+               $this->assertFalse($this->validator->validate('a not empty string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function notEmptyValidatorReturnsFalseForAnEmptyString() {
-               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($notEmptyValidator->isValid(''));
+       public function notEmptyValidatorReturnsErrorForAnEmptyString() {
+               $this->assertTrue($this->validator->validate('')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function notEmptyValidatorReturnsFalseForANullValue() {
-               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($notEmptyValidator->isValid(NULL));
+       public function notEmptyValidatorReturnsErrorForANullValue() {
+               $this->assertTrue($this->validator->validate(NULL)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function notEmptyValidatorCreatesTheCorrectErrorForAnEmptySubject() {
-               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was empty.', 1221560718);
-               $notEmptyValidator->isValid('');
+               $this->assertEquals(1, count($this->validator->validate('')->getErrors()));
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function notEmptyValidatorCreatesTheCorrectErrorForANullValue() {
-               $notEmptyValidator = $this->getMock('Tx_Extbase_Validation_Validator_NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was NULL.', 1221560910);
-               $notEmptyValidator->isValid(NULL);
+               $this->assertEquals(1, count($this->validator->validate(NULL)->getErrors()));
        }
 }
 
index 3992a74..adb329d 100644 (file)
@@ -1,94 +1,71 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the number range validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: NumberRangeValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_NumberRangeValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_NumberRangeValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
 
-       /**
-        * @test
-        */
-       public function numberRangeValidatorReturnsTrueForASimpleIntegerInRange() {
-               $numberRangeValidator = new Tx_Extbase_Validation_Validator_NumberRangeValidator();
-               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
-
-               $this->assertTrue($numberRangeValidator->isValid(10.5));
-       }
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_NumberRangeValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function numberRangeValidatorReturnsFalseForANumberOutOfRange() {
-               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
-               $this->assertFalse($numberRangeValidator->isValid(1000.1));
-       }
+       public function numberRangeValidatorReturnsNoErrorForASimpleIntegerInRange() {
+               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
 
-       /**
-        * @test
-        */
-       public function numberRangeValidatorReturnsTrueForANumberInReversedRange() {
-               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->setOptions(array('startRange' => 1000, 'endRange' => 0));
-               $this->assertTrue($numberRangeValidator->isValid(100));
+               $this->assertFalse($this->validator->validate(10.5)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function numberRangeValidatorReturnsFalseForAString() {
-               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
-               $this->assertFalse($numberRangeValidator->isValid('not a number'));
+       public function numberRangeValidatorReturnsErrorForANumberOutOfRange() {
+               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
+               $this->assertTrue($this->validator->validate(1000.1)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function numberRangeValidatorCreatesTheCorrectErrorForANumberOutOfRange() {
-               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not in the valid range (1 - 42).', 1221561046);
-               $numberRangeValidator->setOptions(array('startRange' => 1, 'endRange' => 42));
-               $numberRangeValidator->isValid(4711);
+       public function numberRangeValidatorReturnsNoErrorForANumberInReversedRange() {
+               $this->validatorOptions(array('minimum' => 1000, 'maximum' => 0));
+               $this->assertFalse($this->validator->validate(100)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function numberRangeValidatorCreatesTheCorrectErrorForAStringSubject() {
-               $numberRangeValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
-               $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 42));
-               $numberRangeValidator->isValid('this is not between 0 an 42');
+       public function numberRangeValidatorReturnsErrorForAString() {
+               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
+               $this->assertTrue($this->validator->validate('not a number')->hasErrors());
        }
 }
 
index e9abf96..d30ed04 100644 (file)
@@ -1,62 +1,52 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the number validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: NumberValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_NumberValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_NumberValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_NumberValidator';
 
        /**
         * @test
         */
        public function numberValidatorReturnsTrueForASimpleInteger() {
                $numberValidator = new Tx_Extbase_Validation_Validator_NumberValidator();
-               $this->assertTrue($numberValidator->isValid(1029437));
+               $this->assertFalse($numberValidator->validate(1029437)->hasErrors());
        }
 
        /**
         * @test
         */
        public function numberValidatorReturnsFalseForAString() {
-               $numberValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($numberValidator->isValid('not a number'));
-       }
-
-       /**
-        * @test
-        */
-       public function numberValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $numberValidator = $this->getMock('Tx_Extbase_Validation_Validator_NumberValidator', array('addError'), array(), '', FALSE);
-               $numberValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
-               $numberValidator->isValid('this is not a number');
+               $expectedResult = new Tx_Extbase_Error_Result();
+               $expectedResult->addError(new Tx_Extbase_Validation_Error('The given subject was not a valid number.', 1221563685));
+               $numberValidator = new Tx_Extbase_Validation_Validator_NumberValidator();
+               $this->assertEquals($expectedResult, $numberValidator->validate('not a number'));
        }
 }
 
index 1870025..6c4c204 100644 (file)
@@ -1,50 +1,48 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the raw validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: RawValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_RawValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_RawValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_RawValidator';
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
-       public function theRawValidatorAlwaysReturnsTRUE() {
-               $rawValidator = new Tx_Extbase_Validation_Validator_RawValidator();
+       public function theRawValidatorAlwaysReturnsNoErrors() {
+               $rawValidator = new Tx_Extbase_Validation_Validator_RawValidator(array());
 
-               $this->assertTrue($rawValidator->isValid('simple1expression'));
-               $this->assertTrue($rawValidator->isValid(''));
-               $this->assertTrue($rawValidator->isValid(NULL));
-               $this->assertTrue($rawValidator->isValid(FALSE));
-               $this->assertTrue($rawValidator->isValid(new ArrayObject()));
+               $this->assertFalse($rawValidator->validate('simple1expression')->hasErrors());
+               $this->assertFalse($rawValidator->validate('')->hasErrors());
+               $this->assertFalse($rawValidator->validate(NULL)->hasErrors());
+               $this->assertFalse($rawValidator->validate(FALSE)->hasErrors());
+               $this->assertFalse($rawValidator->validate(new ArrayObject())->hasErrors());
        }
 }
 
index 0f08826..2c6aa7a 100644 (file)
@@ -1,58 +1,55 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the regular expression validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: RegularExpressionValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_RegularExpressionValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_RegularExpressionValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_RegularExpressionValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function regularExpressionValidatorMatchesABasicExpressionCorrectly() {
-               $regularExpressionValidator = $this->getMock('Tx_Extbase_Validation_Validator_RegularExpressionValidator', array('addError'), array(), '', FALSE);
-               $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
+               $this->validatorOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
 
-               $this->assertTrue($regularExpressionValidator->isValid('simple1expression'));
-               $this->assertFalse($regularExpressionValidator->isValid('simple1expressions'));
+               $this->assertFalse($this->validator->validate('simple1expression')->hasErrors());
+               $this->assertTrue($this->validator->validate('simple1expressions')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch() {
-               $regularExpressionValidator = $this->getMock('Tx_Extbase_Validation_Validator_RegularExpressionValidator', array('addError'), array(), '', FALSE);
-               $regularExpressionValidator->expects($this->once())->method('addError')->with('The given subject did not match the pattern.', 1221565130);
-               $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
-               $regularExpressionValidator->isValid('some subject that will not match');
+               $this->validatorOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
+               $errors = $this->validator->validate('some subject that will not match')->getErrors();
+               $this->assertEquals(array(new Tx_Extbase_Validation_Error('The given subject did not match the pattern.', 1221565130)), $errors);
        }
 }
 
index ef593de..566f73c 100644 (file)
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the string length validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: StringLengthValidator_testcase.php 1408 2009-10-08 13:15:09Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_StringLengthValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_StringLengthValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_StringLengthValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stgringLengthValidatorReturnsTrueForAStringShorterThanMaxLengthAndLongerThanMinLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 0, 'maximum' => 50));
-               $this->assertTrue($stringLengthValidator->isValid('this is a very simple string'));
+       public function stringLengthValidatorReturnsNoErrorForAStringShorterThanMaxLengthAndLongerThanMinLength() {
+               $this->validatorOptions(array('minimum' => 0, 'maximum' => 50));
+               $this->assertFalse($this->validator->validate('this is a very simple string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsFalseForAStringShorterThanThanMinLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
-               $this->assertFalse($stringLengthValidator->isValid('this is a very short string'));
+       public function stringLengthValidatorReturnsErrorForAStringShorterThanThanMinLength() {
+               $this->validatorOptions(array('minimum' => 50, 'maximum' => 100));
+               $this->assertTrue($this->validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsFalseForAStringLongerThanThanMaxLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 10));
-               $this->assertFalse($stringLengthValidator->isValid('this is a very short string'));
+       public function stringLengthValidatorReturnsErrorsForAStringLongerThanThanMaxLength() {
+               $this->validatorOptions(array('minimum' => 5, 'maximum' => 10));
+               $this->assertTrue($this->validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueForAStringLongerThanThanMinLengthAndMaxLengthNotSpecified() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 5));
-               $this->assertTrue($stringLengthValidator->isValid('this is a very short string'));
+       public function stringLengthValidatorReturnsNoErrorsForAStringLongerThanThanMinLengthAndMaxLengthNotSpecified() {
+               $this->validatorOptions(array('minimum' => 5));
+               $this->assertFalse($this->validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueForAStringShorterThanThanMaxLengthAndMinLengthNotSpecified() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('maximum' => 100));
-               $this->assertTrue($stringLengthValidator->isValid('this is a very short string'));
+       public function stringLengthValidatorReturnsNoErrorsForAStringShorterThanThanMaxLengthAndMinLengthNotSpecified() {
+               $this->validatorOptions(array('maximum' => 100));
+               $this->assertFalse($this->validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueForAStringLengthEqualToMaxLengthAndMinLengthNotSpecified() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('maximum' => 10));
-               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       public function stringLengthValidatorReturnsNoErrorsForAStringLengthEqualToMaxLengthAndMinLengthNotSpecified() {
+               $this->validatorOptions(array('maximum' => 10));
+               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueForAStringLengthEqualToMinLengthAndMaxLengthNotSpecified() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 10));
-               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       public function stringLengthValidatorReturnsNoErrorForAStringLengthEqualToMinLengthAndMaxLengthNotSpecified() {
+               $this->validatorOptions(array('minimum' => 10));
+               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueIfMinLengthAndMaxLengthAreEqualAndTheGivenStringMatchesThisValue() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 10, 'maximum' => 10));
-               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       public function stringLengthValidatorReturnsNoErrorIfMinLengthAndMaxLengthAreEqualAndTheGivenStringMatchesThisValue() {
+               $this->validatorOptions(array('minimum' => 10, 'maximum' => 10));
+               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueIfTheStringLengthIsEqualToMaxLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 1, 'maximum' => 10));
-               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       public function stringLengthValidatorReturnsNoErrorsfTheStringLengthIsEqualToMaxLength() {
+               $this->validatorOptions(array('minimum' => 1, 'maximum' => 10));
+               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function stringLengthValidatorReturnsTrueIfTheStringLengthIsEqualToMinLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 10, 'maximum' => 100));
-               $this->assertTrue($stringLengthValidator->isValid('1234567890'));
+       public function stringLengthValidatorReturnsNoErrorIfTheStringLengthIsEqualToMinLength() {
+               $this->validatorOptions(array('minimum' => 10, 'maximum' => 100));
+               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
         * @expectedException Tx_Extbase_Validation_Exception_InvalidValidationOptions
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function stringLengthValidatorThrowsAnExceptionIfMinLengthIsGreaterThanMaxLength() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 101, 'maximum' => 100));
-               $stringLengthValidator->isValid('1234567890');
+               $this->validator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $this->validatorOptions(array('minimum' => 101, 'maximum' => 100));
+               $this->validator->validate('1234567890');
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function stringLengthValidatorInsertsAnErrorObjectIfValidationFails() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->expects($this->once())->method('addError');
-               $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
+               $this->validatorOptions(array('minimum' => 50, 'maximum' => 100));
 
-               $stringLengthValidator->isValid('this is a very short string');
+               $this->assertEquals(1, count($this->validator->validate('this is a very short string')->getErrors()));
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function stringLengthValidatorCanHandleAnObjectWithAToStringMethod() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 100));
+               $this->validator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
 
-               $className = uniqid('TestClass');
+               $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
 
                eval('
                        class ' . $className . ' {
@@ -163,18 +161,19 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_StringLengthValidatorTest exten
                ');
 
                $object = new $className();
-               $this->assertTrue($stringLengthValidator->isValid($object));
+               $this->assertFalse($this->validator->validate($object)->hasErrors());
        }
 
        /**
         * @test
         * @expectedException Tx_Extbase_Validation_Exception_InvalidSubject
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function stringLengthValidatorThrowsAnExceptionIfTheGivenObjectCanNotBeConvertedToAString() {
-               $stringLengthValidator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
-               $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 100));
+               $this->validator = $this->getMock('Tx_Extbase_Validation_Validator_StringLengthValidator', array('addError'), array(), '', FALSE);
+               $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
 
-               $className = uniqid('TestClass');
+               $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
 
                eval('
                        class ' . $className . ' {
@@ -183,7 +182,7 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_StringLengthValidatorTest exten
                ');
 
                $object = new $className();
-               $stringLengthValidator->isValid($object);
+               $this->validator->validate($object);
        }
 }
 
diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringValidatorTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringValidatorTest.php
new file mode 100644 (file)
index 0000000..f15e1ee
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
+/**
+ * Testcase for the string length validator
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class Tx_Extbase_Tests_Unit_Validation_Validator_StringValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_StringValidator';
+
+       /**
+        * @test
+        * @author Sebastian Kurfürst <sebastian@typo3.org>
+        */
+       public function stringValidatorShouldValidateString() {
+               $this->assertFalse($this->validator->validate('Hello World')->hasErrors());
+       }
+
+       /**
+        * @test
+        * @author Sebastian Kurfürst <sebastian@typo3.org>
+        */
+       public function stringValidatorShouldReturnErrorIfNumberIsGiven() {
+               $this->assertTrue($this->validator->validate(42)->hasErrors());
+       }
+
+       /**
+        * @test
+        * @author Sebastian Kurfürst <sebastian@typo3.org>
+        */
+       public function stringValidatorShouldReturnErrorIfObjectWithToStringMethodStringIsGiven() {
+               $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
+
+               eval('
+                       class ' . $className . ' {
+                               public function __toString() {
+                                       return "ASDF";
+                               }
+                       }
+               ');
+               $object = new $className();
+               $this->assertTrue($this->validator->validate($object)->hasErrors());
+       }
+
+}
+
+?>
\ No newline at end of file
index 6f64847..c2d6f5a 100644 (file)
@@ -1,89 +1,77 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+
+/*                                                                        *
+ * 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!                         *
+ *                                                                        */
+
+require_once('AbstractValidatorTestcase.php');
 
 /**
  * Testcase for the text validator
  *
- * @package Extbase
- * @subpackage extbase
- * @version $Id: TextValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Tx_Extbase_Tests_Unit_Validation_Validator_TextValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+class Tx_Extbase_Tests_Unit_Validation_Validator_TextValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
+
+       protected $validatorClassName = 'Tx_Extbase_Validation_Validator_TextValidator';
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function textValidatorReturnsTrueForASimpleString() {
-               $textValidator = new Tx_Extbase_Validation_Validator_TextValidator();
-               $this->assertTrue($textValidator->isValid('this is a very simple string'));
+       public function textValidatorReturnsNoErrorForASimpleString() {
+               $this->assertFalse($this->validator->validate('this is a very simple string')->hasErrors());
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
        public function textValidatorAllowsTheNewLineCharacter() {
-               $sampleText = "Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. \nVu dan durch jéngt gréng, ze rou Monn voll stolz. \nKe kille Minutt d'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zënter, Welt Ronn grousse der ke. Wou fond eraus Wisen am. Hu dénen d'Gaassen eng, eng am virun geplot d'Lëtzebuerger, get botze rëscht Blieder si. Dat Dauschen schéinste Milliounen fu. Ze riede méngem Keppchen déi, si gét fergiess erwaacht, räich jéngt duerch en nun. Gëtt Gaas d'Vullen hie hu, laacht Grénge der dé. Gemaacht gehéiert da aus, gutt gudden d'wäiss mat wa.";
-               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
-               $this->assertTrue($textValidator->isValid($sampleText));
+               $sampleText = "Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. nVu dan durch jéngt gréng, ze rou Monn voll stolz. nKe kille Minutt d'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zënter, Welt Ronn grousse der ke. Wou fond eraus Wisen am. Hu dénen d'Gaassen eng, eng am virun geplot d'Lëtzebuerger, get botze rëscht Blieder si. Dat Dauschen schéinste Milliounen fu. Ze riede méngem Keppchen déi, si gét fergiess erwaacht, räich jéngt duerch en nun. Gëtt Gaas d'Vullen hie hu, laacht Grénge der dé. Gemaacht gehéiert da aus, gutt gudden d'wäiss mat wa.";
+               $this->assertFalse($this->validator->validate($sampleText)->hasErrors());
        }
 
        /**
         * @test
+        * @author Robert Lemke <robert@typo3.org>
         */
        public function textValidatorAllowsCommonSpecialCharacters() {
                $sampleText = "3% of most people tend to use semikolae; we need to check & allow that. And hashes (#) are not evil either, nor is the sign called 'quote'.";
-               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
-               $this->assertTrue($textValidator->isValid($sampleText));
-       }
-
-       /**
-        * @test
-        */
-       public function textValidatorReturnsFalseForAStringWithHtml() {
-               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>'));
+               $this->assertFalse($this->validator->validate($sampleText)->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
-       public function textValidatorReturnsFalseForAStringWithPercentEncodedHtml() {
-               $this->markTestIncomplete('The text validator currently allows percent encoded HTML!');
-               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
-               $this->assertFalse($textValidator->isValid('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'));
+       public function textValidatorReturnsErrorForAStringWithHtml() {
+               $this->assertTrue($this->validator->validate('<span style="color: #BBBBBB;">a nice text</span>')->hasErrors());
        }
 
        /**
         * @test
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
-               $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
-               $textValidator->expects($this->once())->method('addError')->with('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
-               $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
+               $expected = array(new Tx_Extbase_Validation_Error('The given subject was not a valid text (e.g. contained XML tags).', 1221565786));
+               $this->assertEquals($expected, $this->validator->validate('<span style="color: #BBBBBB;">a nice text</span>')->getErrors());
        }
 }
 
index d8e88e6..76765cd 100644 (file)
@@ -70,7 +70,7 @@ class Tx_Extbase_Tests_Unit_Validation_ValidatorResolverTest extends Tx_Extbase_
         */
        public function createValidatorResolvesAndReturnsAValidatorAndPassesTheGivenOptions() {
                $className = uniqid('Test');
-               $mockValidator = $this->getMock('Tx_Extbase_Validation_Validator_ObjectValidatorInterface', array(), array(), $className);
+               $mockValidator = $this->getMock('Tx_Extbase_Validation_Validator_ObjectValidatorInterface', array('setOptions', 'canValidate', 'isPropertyValid'), array(), $className);
                $mockValidator->expects($this->once())->method('setOptions')->with(array('foo' => 'bar'));
 
                $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');