[FEATURE] Add several testcases for validators
authorAndreas Lappe <nd@off-pist.de>
Wed, 28 Mar 2012 17:04:39 +0000 (19:04 +0200)
committerAndreas Wolf <andreas.wolf@ikt-werk.de>
Wed, 10 Oct 2012 11:18:12 +0000 (13:18 +0200)
This adds several testcases for the provided validators.

Change-Id: Ie7a056cadaf767dbc306a980561c15e70d9698d8
Resolves: #35333
Releases: 4.6, 4.7, 6.0
Reviewed-on: http://review.typo3.org/10067
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
23 files changed:
typo3/sysext/form/Classes/Validation/AbstractValidator.php
typo3/sysext/form/Classes/Validation/AlphabeticValidator.php
typo3/sysext/form/Tests/Unit/Validation/AlphabeticValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/AlphanumericValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/BetweenValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/DateValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/DigitValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/EmailValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/EqualsValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/FileAllowedTypesValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/FileMaximumSizeValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/FileMinimumSizeValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/FloatValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/GreaterThanValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/Helper.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/InArrayValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/IntegerValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/IpValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/LessThanValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/RegExpValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/RequiredValidatorTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Validation/UriValidatorTest.php [new file with mode: 0644]

index a3e5021..1cd4e61 100644 (file)
@@ -88,6 +88,16 @@ abstract class AbstractValidator implements \TYPO3\CMS\Form\Validation\Validator
        protected $localCobj;
 
        /**
+        * Inject the Request Handler
+        *
+        * @param \TYPO3\CMS\Form\Request $requestHandler
+        * @return void
+        */
+       public function injectRequestHandler(\TYPO3\CMS\Form\Request $requestHandler) {
+               $this->requestHandler = $requestHandler;
+       }
+
+       /**
         * Constructor
         *
         * @param array $arguments Typoscript configuration for the validation rule
@@ -95,7 +105,7 @@ abstract class AbstractValidator implements \TYPO3\CMS\Form\Validation\Validator
         */
        public function __construct($arguments) {
                $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
-               $this->requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
+               $this->injectRequestHandler(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request'));
                $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
                $this->setFieldName($arguments['element']);
                $this->setMessage($arguments['message.'], $arguments['message']);
index bc9a394..64b8ba1 100644 (file)
@@ -42,7 +42,7 @@ class AlphabeticValidator extends \TYPO3\CMS\Form\Validation\AbstractValidator {
        /**
         * Alphabetic filter used for validation
         *
-        * @var tx_form_Filter_Alphabetic
+        * @var \TYPO3\CMS\Form\Filter\AlphabeticFilter
         */
        protected $filter;
 
diff --git a/typo3/sysext/form/Tests/Unit/Validation/AlphabeticValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/AlphabeticValidatorTest.php
new file mode 100644 (file)
index 0000000..b2dba29
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\System\Validation\AlphabeticValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class AlphabeticValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\AlphabeticValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\AlphabeticValidator();
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDataProviderWithoutWhitespace() {
+               return array(
+                       'ascii without spaces' => array('thisismyinput'),
+                       'accents without spaces' => array('éóéàèò'),
+                       'umlauts without spaces' => array('üöä'),
+                       'empty string' => array('')
+               );
+       }
+
+       public function validDataProviderWithWhitespace() {
+               return array(
+                       'ascii with spaces' => array('This is my input'),
+                       'accents with spaces' => array('Sigur Rós'),
+                       'umlauts with spaces' => array('Hürriyet Daily News'),
+                       'space' => array(' '),
+                       'empty string' => array('')
+               );
+       }
+
+       public function invalidDataProviderWithoutWhitespace() {
+               return array(
+                       'ascii with dash' => array('my-name'),
+                       'accents with underscore' => array('Sigur_Rós'),
+                       'umlauts with periods' => array('Hürriyet.Daily.News'),
+                       'space' => array(' '),
+               );
+       }
+
+       public function invalidDataProviderWithWhitespace() {
+               return array(
+                       'ascii with spaces and dashes' => array('This is my-name'),
+                       'accents with spaces and underscores' => array('Listen to Sigur_Rós_Band'),
+                       'umlauts with spaces and periods' => array('Go get the Hürriyet.Daily.News')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProviderWithoutWhitespace
+        */
+       public function isValidForValidInputWithoutAllowedWhitespaceReturnsTrue($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProviderWithWhitespace
+        */
+       public function isValidForValidInputWithWhitespaceAllowedReturnsTrue($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setAllowWhiteSpace(TRUE);
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProviderWithoutWhitespace
+        */
+       public function isValidForInvalidInputWithoutAllowedWhitespaceReturnsFalse($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProviderWithWhitespace
+        */
+       public function isValidForInvalidInputWithWhitespaceAllowedReturnsFalse($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setAllowWhiteSpace(TRUE);
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/AlphanumericValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/AlphanumericValidatorTest.php
new file mode 100644 (file)
index 0000000..d77025e
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\AlphanumericValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\AlphanumericValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\AlphanumericValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDataProviderWithoutWhitespace() {
+               return array(
+                       'ascii without spaces' => array('thisismyinput4711'),
+                       'accents without spaces' => array('éóéàèò4711'),
+                       'umlauts without spaces' => array('üöä4711'),
+                       'empty string' => array('')
+               );
+       }
+
+       public function validDataProviderWithWhitespace() {
+               return array(
+                       'ascii with spaces' => array('This is my input 4711'),
+                       'accents with spaces' => array('Sigur Rós 4711'),
+                       'umlauts with spaces' => array('Hürriyet Daily News 4711'),
+                       'space' => array(' '),
+                       'empty string' => array('')
+               );
+       }
+
+       public function invalidDataProviderWithoutWhitespace() {
+               return array(
+                       'ascii with dash' => array('my-name-4711'),
+                       'accents with underscore' => array('Sigur_Rós_4711'),
+                       'umlauts with periods' => array('Hürriyet.Daily.News.4711'),
+                       'space' => array(' '),
+               );
+       }
+
+       public function invalidDataProviderWithWhitespace() {
+               return array(
+                       'ascii with spaces and dashes' => array('This is my-name 4711'),
+                       'accents with spaces and underscores' => array('Listen to Sigur_Rós_Band 4711'),
+                       'umlauts with spaces and periods' => array('Go get the Hürriyet.Daily.News 4711')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProviderWithoutWhitespace
+        */
+       public function isValidForValidInputWithoutAllowedWhitespaceReturnsTrue($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProviderWithWhitespace
+        */
+       public function isValidForValidInputWithAllowedWhitespaceReturnsTrue($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setAllowWhiteSpace(TRUE);
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProviderWithoutWhitespace
+        */
+       public function isValidForInvalidInputWithoutAllowedWhitespaceReturnsFalse($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProviderWithWhitespace
+        */
+       public function isValidForInvalidInputWithAllowedWhitespaceReturnsFalse($input) {
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'name' => $input
+               ));
+
+               $this->fixture->setAllowWhiteSpace(TRUE);
+               $this->fixture->setFieldName('name');
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/BetweenValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/BetweenValidatorTest.php
new file mode 100644 (file)
index 0000000..d91b60d
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\BetweenValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class BetweenValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\BetweenValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\BetweenValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validNonInclusiveDataProvider() {
+               return array(
+                       '3 < 5 < 7'      => array(array(3, 5, 7)),
+                       '0 < 10 < 20'    => array(array(0, 10, 20)),
+                       '-10 < 0 < 10'   => array(array(-10, 0, 10)),
+                       '-20 < -10 < 0'  => array(array(-20, -10, 0)),
+                       '1 < 2 < 3'      => array(array(1, 2, 3)),
+                       '1 < 1.01 < 1.1' => array(array(1, 1.01, 1.1)),
+               );
+       }
+
+       public function invalidNonInclusiveDataProvider() {
+               return array(
+                       '1 < 1 < 2'                 => array(array(1, 1, 2)),
+                       '1 < 2 < 2'                 => array(array(1, 2, 2)),
+                       '1.1 < 1.1 < 1.2'           => array(array(1.1, 1.1, 1.2)),
+                       '1.1 < 1.2 < 1.2'           => array(array(1.1, 1.2, 1.2)),
+                       '-10.1234 < -10.12340 < 10' => array(array(-10.1234, -10.12340, 10)),
+                       '100 < 0 < -100'            => array(array(100, 0, -100))
+               );
+       }
+
+       public function validInclusiveDataProvider() {
+               return array(
+                       '1 ≤ 1 ≤ 1'                 => array(array(1,1,1)),
+                       '-10.1234 ≤ -10.12340 ≤ 10' => array(array(-10.1234, -10.12340, 10)),
+                       '-10.1234 ≤ -10 ≤ 10'       => array(array(-10.1234, -10.12340, 10)),
+               );
+       }
+
+       public function invalidInclusiveDataProvider() {
+               return array(
+                       '-10.1234 ≤ -10.12345 ≤ 10' => array(array(-10.1234, -10.12345, 10)),
+                       '100 ≤ 0 ≤ -100'            => array(array(100, 0, -100))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validNonInclusiveDataProvider
+        */
+       public function isValidWithValidInputAndWithoutInclusiveReturnsTrue($input) {
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[2]);
+               $this->fixture->setFieldName('numericValue');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'numericValue' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validInclusiveDataProvider
+        */
+       public function isValidWithValidInputAndWithInclusiveReturnsTrue($input) {
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[2]);
+               $this->fixture->setFieldName('numericValue');
+               $this->fixture->setInclusive(TRUE);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'numericValue' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidNonInclusiveDataProvider
+        */
+       public function isValidWithInvalidInputAndWithoutInclusiveReturnsFalse($input) {
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[2]);
+               $this->fixture->setFieldName('numericValue');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'numericValue' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidInclusiveDataProvider
+        */
+       public function isValidWithInvalidInputAndWithInclusiveReturnsFalse($input) {
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[2]);
+               $this->fixture->setFieldName('numericValue');
+               $this->fixture->setInclusive(TRUE);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'numericValue' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/DateValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/DateValidatorTest.php
new file mode 100644 (file)
index 0000000..3eed9d7
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\DateValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class DateValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\DateValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\DateValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDateProvider() {
+               return array(
+                       '28-03-2012' => array(array('%e-%m-%Y', '28-03-2012')),
+                       '8-03-2012'  => array(array('%e-%m-%Y', '8-03-2012')),
+                       '29-02-2012' => array(array('%d-%m-%Y', '29-02-2012'))
+               );
+       }
+
+       public function invalidDateProvider() {
+               return array(
+                       '32-03-2012' => array(array('%d-%m-%Y', '32-03-2012')),
+                       '31-13-2012' => array(array('%d-%m-%Y', '31-13-2012')),
+                       '29-02-2011' => array(array('%d-%m-%Y', '29-02-2011'))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDateProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFormat($input[0]);
+               $this->fixture->setFieldName('myDate');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myDate' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDateProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFormat($input[0]);
+               $this->fixture->setFieldName('myDate');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myDate' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/DigitValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/DigitValidatorTest.php
new file mode 100644 (file)
index 0000000..143fa9e
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\DigitValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class DigitValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\DigitValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\DigitValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDigitProvider() {
+               return array(
+                       'stringified integer'                    => array('2012'),
+                       'stringified integer with leading zeros' => array('0002'),
+               );
+       }
+
+       public function invalidDigitProvider() {
+               return array(
+                       'stringified float'      => array('0.2012'),
+                       'stringified scientific' => array('1.9E+11')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDigitProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myDigit');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myDigit' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDigitProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myDigit');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myDigit' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/EmailValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/EmailValidatorTest.php
new file mode 100644 (file)
index 0000000..556d1cc
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\EmailValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class EmailValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\EmailValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\EmailValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validEmailProvider() {
+               return array(
+                       'a@b.de'               => array('a@b.de'),
+                       'somebody@localhost'   => array('somebody@localhost'),
+                       'somebody@mymac.local' => array('somebody@mymac.local')
+               );
+       }
+
+       public function invalidEmailProvider() {
+               return array(
+                       'myemail@'           => array('myemail@'),
+                       'myemail'            => array('myemail'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validEmailProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myEmail');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myEmail' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidEmailProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myEmail');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myEmail' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/EqualsValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/EqualsValidatorTest.php
new file mode 100644 (file)
index 0000000..8e0d85a
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\EqualsValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class EqualsValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\EqualsValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\EqualsValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function invalidPairProvider() {
+               return array(
+                       'somethingElse !== something' => array(array('somethingElse', 'something')),
+                       '4 !== 3'                     => array(array(4, 3))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidPairProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myField');
+               $this->fixture->setField($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myField' => $input[1],
+                       $input[0] => TRUE
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/FileAllowedTypesValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/FileAllowedTypesValidatorTest.php
new file mode 100644 (file)
index 0000000..8ebc1bb
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\FileAllowedTypesValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class FileAllowedTypesValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\FileAllowedTypesValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\FileAllowedTypesValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validTypesProvider() {
+               return array(
+                       'pdf in (pdf)'       => array(array('application/pdf', 'application/pdf')),
+                       'pdf in (pdf, json)' => array(array('application/pdf, application/json', 'application/pdf'))
+
+               );
+       }
+       public function invalidTypesProvider() {
+               return array(
+                       'xml in (pdf, json)' => array(array('application/pdf, application/json', 'application/xml')),
+                       'xml in (pdf)'       => array(array('application/pdf, application/json', 'application/xml'))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validTypesProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setAllowedTypes($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('type' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidTypesProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setAllowedTypes($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('type' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/FileMaximumSizeValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/FileMaximumSizeValidatorTest.php
new file mode 100644 (file)
index 0000000..d2666e8
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\FileMaximumSizeValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class FileMaximumSizeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\FileMaximumSizeValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\FileMaximumSizeValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validSizesProvider() {
+               return array(
+                       '11B for max. 12B' => array(array(12, 11)),
+                       '12B for max. 12B' => array(array(12, 12))
+               );
+       }
+
+       public function invalidSizesProvider() {
+               return array(
+                       '12B for max. 11B' => array(array(11, 12))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validSizesProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMaximum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('size' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider inValidSizesProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMaximum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('size' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/FileMinimumSizeValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/FileMinimumSizeValidatorTest.php
new file mode 100644 (file)
index 0000000..4be653d
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\FileMinimumSizeValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class FileMinimumSizeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\FileMinimumSizeValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\FileMinimumSizeValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validSizesProvider() {
+               return array(
+                       '12B for min. 11B' => array(array(11, 12)),
+                       '12B for min. 12B' => array(array(12, 12))
+               );
+       }
+
+       public function invalidSizesProvider() {
+               return array(
+                       '11B for min. 12B' => array(array(12, 11))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validSizesProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMinimum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('size' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidSizesProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMinimum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => array('size' => $input[1])
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/FloatValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/FloatValidatorTest.php
new file mode 100644 (file)
index 0000000..c13d317
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\FloatValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\FloatValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\FloatValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validFloatProvider() {
+               return array(
+                       '12.1 for en_US locale' => array(array(12.1, 'en_US')),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validFloatProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               setlocale(LC_NUMERIC, $input[1]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => $input[0]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/GreaterThanValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/GreaterThanValidatorTest.php
new file mode 100644 (file)
index 0000000..3df66a8
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\GreaterThanValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class GreaterThanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\GreaterThanValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\GreaterThanValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validNumberProvider() {
+               return array(
+                       '13 > 12' => array(array(12, 13)),
+               );
+       }
+
+       public function invalidNumberProvider() {
+               return array(
+                       '12.1 > 12'  => array(array(12, 12.1)),
+                       '12 > 12'    => array(array(12, 12)),
+                       '11.99 > 12' => array(array(12, 11.99))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validNumberProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMinimum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidNumberProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myFile');
+               $this->fixture->setMinimum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/Helper.php b/typo3/sysext/form/Tests/Unit/Validation/Helper.php
new file mode 100644 (file)
index 0000000..22e0015
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Small helper class to DRY the code.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class Helper extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var array
+        */
+       protected $mockData = array();
+
+       /**
+        * Helper method to get a mock of a requestHandler returning
+        * defined values if asked.
+        *
+        * @param array $data $key => $value pairs to return if asked for key
+        * @return \TYPO3\CMS\Form\Request|\PHPUnit_Framework_MockObject_MockObject
+        */
+       public function getRequestHandler(array $data) {
+               $this->mockData = $data;
+
+               $requestHandlerMock = $this->getMock('TYPO3\\CMS\\Form\\Request', array('has', 'getByMethod'));
+               $requestHandlerMock->expects($this->any())->method('has')->will($this->returnCallback(array($this, 'has')));
+               $requestHandlerMock->expects($this->any())->method('getByMethod')
+                       ->will($this->returnCallback(array($this, 'getByMethod')));
+
+               return $requestHandlerMock;
+       }
+
+       /**
+        * Callback for \TYPO3\CMS\Form\Request::getByMethod.
+        *
+        * Returns the value stored for $key
+        *
+        * @param string $key the key of the value to retrieve, must not be empty
+        * @return mixed the stored value for $key or FALSE if there is no value for $key stored
+        */
+       public function getByMethod($key) {
+               if (!$this->has($key)) {
+                       return FALSE;
+               }
+
+               return $this->mockData[$key];
+       }
+
+       /**
+        * Callback for tx_form_System_Request::has.
+        *
+        * Checks whether a value for $key has been stored.
+        *
+        * @param string $key the key to check, must not be empty
+        * @return boolean whether a value for $key has been stored.
+        */
+       public function has($key) {
+               return isset($this->mockData[$key]);
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/InArrayValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/InArrayValidatorTest.php
new file mode 100644 (file)
index 0000000..f28be11
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\InArrayValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class InArrayValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\InArrayValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\InArrayValidator(array('array.' => array(), 'strict' => FALSE));
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validArrayProvider() {
+               return array(
+                       '12 in (12, 13)' => array(array(array(12, 13), 12))
+               );
+       }
+
+       public function invalidArrayProvider() {
+               return array(
+                       '12 in (11, 13)' => array(array(array(11, 13), 12)),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validArrayProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myfield');
+               $this->fixture->setArray($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myfield' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidArrayProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myfield');
+               $this->fixture->setArray($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myfield' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validArrayProvider
+        */
+       public function isValidForValidInputWithStrictComparisonReturnsTrue($input) {
+               $this->fixture->setFieldName('myfield');
+               $this->fixture->setArray($input[0]);
+               $this->fixture->setStrict(TRUE);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myfield' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidArrayProvider
+        */
+       public function isValidForInvalidInputWithStrictComparisonReturnsFalse($input) {
+               $this->fixture->setFieldName('myfield');
+               $this->fixture->setArray($input[0]);
+               $this->fixture->setStrict(TRUE);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myfield' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/IntegerValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/IntegerValidatorTest.php
new file mode 100644 (file)
index 0000000..4acce81
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\IntegerValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\IntegerValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\IntegerValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validIntegerProvider() {
+               return array(
+                       '12 for de locale'    => array(array(12, 'de')),
+               );
+       }
+
+       public function invalidIntegerProvider() {
+               return array(
+                       '12.1 for en_US locale' => array(array(12.1, 'en_US')),
+                       '12,1 for de_DE locale' => array(array('12,1', 'de_DE'))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validIntegerProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myFile');
+               setlocale(LC_NUMERIC, $input[1]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => $input[0]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidIntegerProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myFile');
+               setlocale(LC_NUMERIC, $input[1]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myFile' => $input[0]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/IpValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/IpValidatorTest.php
new file mode 100644 (file)
index 0000000..a837ecb
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\IpValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class IpValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\IpValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\IpValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper);
+               unset($this->fixture);
+       }
+
+       public function validIpv4Provider() {
+               return array(
+                       '127.0.0.1'   => array('127.0.0.1'),
+                       '10.0.0.4'    => array('10.0.0.4'),
+                       '192.168.0.4' => array('192.168.0.4'),
+                       '0.0.0.0'     => array('0.0.0.0')
+               );
+       }
+
+       public function invalidIpv4Provider() {
+               return array(
+                       '127.0.0.256' => array('127.0.0.256'),
+                       '256.0.0.2'   => array('256.0.0.2')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validIpv4Provider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myIp');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myIp' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidIpv4Provider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myIp');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myIp' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php
new file mode 100644 (file)
index 0000000..146c9e3
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\LengthValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class LengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\LengthValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\LengthValidator(array('minimum' => 0, 'maximum' => 0));
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validLengthProvider() {
+               return array(
+                       '4 ≤ length(myString) ≤ 8' => array(array(4, 8, 'myString')),
+                       '8 ≤ length(myString) ≤ 8' => array(array(8, 8, 'myString')),
+                       '4 ≤ length(myString)'       => array(array(4, NULL, 'myString')),
+                       '4 ≤ length(asdf) ≤ 4'     => array(array(4, 4, 'asdf')),
+               );
+       }
+
+       public function invalidLengthProvider() {
+               return array(
+                       '4 ≤ length(my) ≤ 12'             => array(array(4, 12, 'my')),
+                       '4 ≤ length(my long string) ≤ 12' => array(array(4, 12, 'my long string')),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validLengthProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myLength');
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[1]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myLength' => $input[2]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidLengthProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myLength');
+               $this->fixture->setMinimum($input[0]);
+               $this->fixture->setMaximum($input[1]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myLength' => $input[2]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/LessThanValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/LessThanValidatorTest.php
new file mode 100644 (file)
index 0000000..fc80f7e
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\LessThanValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class LessThanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\LessthanValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\LessthanValidator(array('maximum' => 0));
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validValueProvider() {
+               return array(
+                       '4 < 8' => array(array(8, 4)),
+               );
+       }
+
+       public function invalidValueProvider() {
+               return array(
+                       '8 < 4' => array(array(4, 8)),
+                       '8 < 8' => array(array(8, 8)),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validValueProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myLessthan');
+               $this->fixture->setMaximum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myLessthan' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidValueProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myLessthan');
+               $this->fixture->setMaximum($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myLessthan' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/RegExpValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/RegExpValidatorTest.php
new file mode 100644 (file)
index 0000000..d2e4e86
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\RegExpValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class RegExpValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\RegExpValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\RegExpValidator(array('expression' => ''));
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDataProvider() {
+               return array(
+                       '/^a/ matches a' => array(array('/^a/', 'a')),
+               );
+       }
+
+       public function invalidDataProvider() {
+               return array(
+                       '/[^\d]/ matches 8' => array(array('/[^\d]/', 8)),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myRegexp');
+               $this->fixture->setRegularExpression($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myRegexp' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myRegexp');
+               $this->fixture->setRegularExpression($input[0]);
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myRegexp' => $input[1]
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/RequiredValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/RequiredValidatorTest.php
new file mode 100644 (file)
index 0000000..1c72cc7
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\RequiredValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class RequiredValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\RequiredValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\RequiredValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDataProvider() {
+               return array(
+                       'a'   => array('a'),
+                       'a b' => array('a b'),
+                       '"0"' => array('0'),
+                       '0'   => array(0)
+               );
+       }
+
+       public function invalidDataProvider() {
+               return array(
+                       'empty string'  => array(''),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProvider
+        */
+       public function isValidForValidDataReturnsTrue($input) {
+               $this->fixture->setFieldName('myRequired');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myRequired' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProvider
+        */
+       public function isValidForInvalidDataReturnsFalse($input) {
+               $this->fixture->setFieldName('myRequired');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myRequired' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Validation/UriValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validation/UriValidatorTest.php
new file mode 100644 (file)
index 0000000..2098efb
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Validation;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  All rights reserved
+*
+*  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!
+***************************************************************/
+
+/**
+ * Test case for class \TYPO3\CMS\Form\Validation\UriValidator.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class UriValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
+        */
+       protected $helper;
+
+       /**
+        * @var \TYPO3\CMS\Form\Validation\UriValidator
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
+               $this->fixture = new \TYPO3\CMS\Form\Validation\UriValidator(array());
+       }
+
+       public function tearDown() {
+               unset($this->helper, $this->fixture);
+       }
+
+       public function validDataProvider() {
+               return array(
+                       'http://example.net'              => array('http://example.net'),
+                       'https://example.net'             => array('https://example.net'),
+                       'http://a:b@example.net'          => array('http://a:b@example.net'),
+               );
+       }
+
+       public function invalidDataProvider() {
+               return array(
+                       'index.php' => array('index.php')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProvider
+        */
+       public function isValidForValidInputReturnsTrue($input) {
+               $this->fixture->setFieldName('myUri');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myUri' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertTrue(
+                       $this->fixture->isValid()
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider invalidDataProvider
+        */
+       public function isValidForInvalidInputReturnsFalse($input) {
+               $this->fixture->setFieldName('myUri');
+               $requestHandlerMock = $this->helper->getRequestHandler(array(
+                       'myUri' => $input
+               ));
+               $this->fixture->injectRequestHandler($requestHandlerMock);
+
+               $this->assertFalse(
+                       $this->fixture->isValid()
+               );
+       }
+}
+?>
\ No newline at end of file