From 2b188da1e6d8033a5589614dc979f7f255a68f52 Mon Sep 17 00:00:00 2001 From: Andreas Lappe Date: Wed, 28 Mar 2012 19:04:39 +0200 Subject: [PATCH] [FEATURE] Add several testcases for validators 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 --- .../Classes/Validation/AbstractValidator.php | 12 +- .../Validation/AlphabeticValidator.php | 2 +- .../Validation/AlphabeticValidatorTest.php | 161 +++++++++++++++++ .../Validation/AlphanumericValidatorTest.php | 160 +++++++++++++++++ .../Unit/Validation/BetweenValidatorTest.php | 166 ++++++++++++++++++ .../Unit/Validation/DateValidatorTest.php | 104 +++++++++++ .../Unit/Validation/DigitValidatorTest.php | 100 +++++++++++ .../Unit/Validation/EmailValidatorTest.php | 101 +++++++++++ .../Unit/Validation/EqualsValidatorTest.php | 79 +++++++++ .../FileAllowedTypesValidatorTest.php | 102 +++++++++++ .../FileMaximumSizeValidatorTest.php | 101 +++++++++++ .../FileMinimumSizeValidatorTest.php | 100 +++++++++++ .../Unit/Validation/FloatValidatorTest.php | 77 ++++++++ .../Validation/GreaterThanValidatorTest.php | 101 +++++++++++ .../form/Tests/Unit/Validation/Helper.php | 86 +++++++++ .../Unit/Validation/InArrayValidatorTest.php | 136 ++++++++++++++ .../Unit/Validation/IntegerValidatorTest.php | 101 +++++++++++ .../Tests/Unit/Validation/IpValidatorTest.php | 103 +++++++++++ .../Unit/Validation/LengthValidatorTest.php | 106 +++++++++++ .../Unit/Validation/LessThanValidatorTest.php | 101 +++++++++++ .../Unit/Validation/RegExpValidatorTest.php | 100 +++++++++++ .../Unit/Validation/RequiredValidatorTest.php | 101 +++++++++++ .../Unit/Validation/UriValidatorTest.php | 100 +++++++++++ 23 files changed, 2298 insertions(+), 2 deletions(-) create mode 100644 typo3/sysext/form/Tests/Unit/Validation/AlphabeticValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/AlphanumericValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/BetweenValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/DateValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/DigitValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/EmailValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/EqualsValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/FileAllowedTypesValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/FileMaximumSizeValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/FileMinimumSizeValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/FloatValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/GreaterThanValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/Helper.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/InArrayValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/IntegerValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/IpValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/LessThanValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/RegExpValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/RequiredValidatorTest.php create mode 100644 typo3/sysext/form/Tests/Unit/Validation/UriValidatorTest.php diff --git a/typo3/sysext/form/Classes/Validation/AbstractValidator.php b/typo3/sysext/form/Classes/Validation/AbstractValidator.php index a3e5021c97e8..1cd4e61f6eb3 100644 --- a/typo3/sysext/form/Classes/Validation/AbstractValidator.php +++ b/typo3/sysext/form/Classes/Validation/AbstractValidator.php @@ -87,6 +87,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 * @@ -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']); diff --git a/typo3/sysext/form/Classes/Validation/AlphabeticValidator.php b/typo3/sysext/form/Classes/Validation/AlphabeticValidator.php index bc9a3947b073..64b8ba11e10c 100644 --- a/typo3/sysext/form/Classes/Validation/AlphabeticValidator.php +++ b/typo3/sysext/form/Classes/Validation/AlphabeticValidator.php @@ -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 index 000000000000..b2dba2961ef7 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/AlphabeticValidatorTest.php @@ -0,0 +1,161 @@ +, 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 + * @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 index 000000000000..d77025ed974e --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/AlphanumericValidatorTest.php @@ -0,0 +1,160 @@ +, 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 + * @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 index 000000000000..d91b60d9163c --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/BetweenValidatorTest.php @@ -0,0 +1,166 @@ +, 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 + * @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 index 000000000000..3eed9d7f6b5a --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/DateValidatorTest.php @@ -0,0 +1,104 @@ +, 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 + * @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 index 000000000000..143fa9e1231b --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/DigitValidatorTest.php @@ -0,0 +1,100 @@ +, 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 + * @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 index 000000000000..556d1cc934d6 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/EmailValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..8e0d85af3457 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/EqualsValidatorTest.php @@ -0,0 +1,79 @@ +, 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 + * @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 index 000000000000..8ebc1bb38606 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/FileAllowedTypesValidatorTest.php @@ -0,0 +1,102 @@ +, 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 + * @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 index 000000000000..d2666e83461a --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/FileMaximumSizeValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..4be653db4697 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/FileMinimumSizeValidatorTest.php @@ -0,0 +1,100 @@ +, 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 + * @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 index 000000000000..c13d3174f681 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/FloatValidatorTest.php @@ -0,0 +1,77 @@ +, 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 + * @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 index 000000000000..3df66a84abaa --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/GreaterThanValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..22e001579f35 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/Helper.php @@ -0,0 +1,86 @@ +, 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 + * @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 index 000000000000..f28be11dbfaa --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/InArrayValidatorTest.php @@ -0,0 +1,136 @@ +, 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 + * @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 index 000000000000..4acce8147d68 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/IntegerValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..a837ecbd2e17 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/IpValidatorTest.php @@ -0,0 +1,103 @@ +, 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 + * @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 index 000000000000..146c9e34fb94 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php @@ -0,0 +1,106 @@ +, 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 + * @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 index 000000000000..fc80f7ef829b --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/LessThanValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..d2e4e86e4cab --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/RegExpValidatorTest.php @@ -0,0 +1,100 @@ +, 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 + * @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 index 000000000000..1c72cc7a92d6 --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/RequiredValidatorTest.php @@ -0,0 +1,101 @@ +, 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 + * @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 index 000000000000..2098efbe6f9d --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Validation/UriValidatorTest.php @@ -0,0 +1,100 @@ +, 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 + * @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 -- 2.20.1