[TASK] ext:form Unit test all filters
authorAndreas Lappe <nd@off-pist.de>
Thu, 29 Nov 2012 23:00:02 +0000 (00:00 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 30 Nov 2012 19:08:45 +0000 (20:08 +0100)
Add several tests for each filter of the form extension.

Resolves: #43473
Releases: 6.1, 6.0

Change-Id: I1c5ebf074cb68cbab12b3ea25cd895853284f686
Reviewed-on: http://review.typo3.org/16896
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
12 files changed:
typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterTest.php
typo3/sysext/form/Tests/Unit/Filter/AlphanumericFilterTest.php
typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/DigitFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/IntegerFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/LowerCaseFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/RegExpFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/RemoveXssFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/StripNewLinesFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/TitleCaseFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/TrimFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/UpperCaseFilterTest.php [new file with mode: 0644]

index 770583b..eef228e 100644 (file)
@@ -24,12 +24,13 @@ namespace TYPO3\CMS\Form\Tests\Unit\Filter;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Testcase for AlphabeticFilter
+ * Test case
  *
  * @author Andreas Lappe <a.lappe@kuehlhaus.com>
  */
-class AlphabeticFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+class AlphabeticFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @var \TYPO3\CMS\Form\Filter\AlphabeticFilter
index 5ab3971..639f102 100644 (file)
@@ -24,12 +24,13 @@ namespace TYPO3\CMS\Form\Tests\Unit\Filter;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Test case for class tx_form_System_Filter_Alphanumeric
+ * Test case
  *
  * @author Andreas Lappe <a.lappe@kuehlhaus.com>
  */
-class AlphanumericFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+class AlphanumericFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @var \TYPO3\CMS\Form\Filter\AlphanumericFilter
diff --git a/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php
new file mode 100644 (file)
index 0000000..e925718
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class CurrencyFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\CurrencyFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\CurrencyFilter();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       public function validDataProvider() {
+               return array(
+                       '1200 => 1.200,00' => array(
+                               1200, // input
+                               '.', // thousand separator
+                               ',', // decimal point
+                               '1.200,00' // expected
+                       ),
+                       '0 => 0,00' => array(
+                               0,
+                               NULL,
+                               ',',
+                               '0,00'
+                       ),
+                       '3333.33 => 3,333.33' => array(
+                               3333.33,
+                               ',',
+                               '.',
+                               '3,333.33'
+                       ),
+                       '1099.33 => 1 099,33' => array(
+                               1099.33,
+                               ' ',
+                               ',',
+                               '1 099,33'
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProvider
+        */
+       public function filterForVariousIntegerInputsReturnsFormattedCurrencyNotation($input, $thousandSeparator, $decimalPoint, $expected) {
+               $this->fixture->setThousandSeparator($thousandSeparator);
+               $this->fixture->setDecimalsPoint($decimalPoint);
+               $this->assertSame($expected, $this->fixture->filter($input));
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/DigitFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/DigitFilterTest.php
new file mode 100644 (file)
index 0000000..547cadc
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class DigitFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\DigitFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\DigitFilter();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       public function validDataProvider() {
+               return array(
+                       '1,00 -> 100' => array('1,00', '100'),
+                       '1E+49 -> 149' => array('1E+49', '149'),
+                       '100 -> 100' => array('100', '100'),
+                       '00000 -> 00000' => array('00000', '00000'),
+                       'ABCD -> ""' => array('ABCD', ''),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validDataProvider
+        */
+       public function filterForStringsReturnsStringsFilteredToOnlyContainDigits($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/IntegerFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/IntegerFilterTest.php
new file mode 100644 (file)
index 0000000..6b3e91b
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class IntegerFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\IntegerFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\IntegerFilter();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       public function dataProvider() {
+               return array(
+                       '"1" -> 1' => array('1', 1),
+                       '1 -> 1' => array(1, 1),
+                       '1.1 -> 1' => array(1.1, 1),
+                       '1+E42 -> 1' => array(1+E42, 1),
+                       'a -> 0' => array(a, 0),
+                       'a42 -> 0' => array('a42', 0),
+                       '-100.00 -> -100' => array(-100.00, -100),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider dataProvider
+        */
+       public function filterForVariousInputReturnsInputCastedToInteger($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/LowerCaseFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/LowerCaseFilterTest.php
new file mode 100644 (file)
index 0000000..21ba243
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class LowerCaseFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\LowerCaseFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\LowerCaseFilter();
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->csConvObj = new \TYPO3\CMS\Core\Charset\CharsetConverter();
+               $GLOBALS['TSFE']->renderCharset = 'utf-8';
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+               unset($GLOBALS['TSFE']);
+       }
+
+       public function dataProvider() {
+               return array(
+                       'a -> a' => array('a', 'a'),
+                       'A -> a' => array('A', 'a'),
+                       'AaA -> aaa' => array('AaA', 'aaa'),
+                       'ÜßbÉØ -> üßbéø' => array('ÜßbÉØ', 'üßbéø'),
+                       '01A23b -> 01a23b' => array('01A23b', '01a23b'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider dataProvider
+        */
+       public function filterForVariousInputReturnsLowercasedInput($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/RegExpFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/RegExpFilterTest.php
new file mode 100644 (file)
index 0000000..19fd56b
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class RegExpFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\RegExpFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\RegExpFilter();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       public function dataProvider() {
+               return array(
+                       'a-a -> aa for /-/' => array(
+                               'a-a',
+                               '/-/',
+                               'aa'
+                       ),
+                       'aaa -> "" for /.+/' => array(
+                               'aaa',
+                               '/.+/',
+                               ''
+                       ),
+                       'aAa -> aa for /[^a]+/' => array(
+                               'aAa',
+                               '/[^a]+/',
+                               'aa'
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider dataProvider
+        */
+       public function filterForStringReturnsInputWithoutCharactersMatchedByRegularExpression($input, $regularExpression, $expected) {
+               $this->fixture->setRegularExpression($regularExpression);
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/RemoveXssFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/RemoveXssFilterTest.php
new file mode 100644 (file)
index 0000000..18ad1b2
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class RemoveXssFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\RemoveXssFilter
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\RemoveXssFilter();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       public function maliciousStringProvider() {
+               return array(
+                       '<IMG SRC="javascript:alert(\'XSS\');">' => array('<IMG SRC="javascript:alert(\'XSS\');">'),
+                       '<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>' => array('<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>'),
+                       '<IMG SRC=JaVaScRiPt:alert(\'XSS\')>' => array('<IMG SRC=JaVaScRiPt:alert(\'XSS\')>'),
+                       '<IMG SRC=javascript:alert(&quot;XSS&quot;)>' => array('<IMG SRC=javascript:alert(&quot;XSS&quot;)>'),
+                       '<IMG SRC=`javascript:alert("RSnake says, \'XSS\'")`>' => array('<IMG SRC=`javascript:alert("RSnake says, \'XSS\'")`>'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider maliciousStringProvider
+        */
+       public function filterForMaliciousStringReturnsInputFilteredOfXssCode($input) {
+               $this->assertNotSame(
+                       $input,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/StripNewLinesFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/StripNewLinesFilterTest.php
new file mode 100644 (file)
index 0000000..f8028ba
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class StripNewLinesFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\StripNewLinesFilter
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\StripNewLinesFilter();
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       public function dataProviderWithNewlines() {
+               return array(
+                       'some\ntext' => array("some\ntext", 'some text'),
+                       'somechr(10)text' => array('some' . chr(10) . 'text', 'some text'),
+                       'some^Mtext' => array('some
+text', 'some text'),
+                       'trailing newline^M' => array('trailing newline
+', 'trailing newline '),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider dataProviderWithNewlines
+        */
+       public function filterForStringWithNewlineReturnsStringWithoutNewline($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/TitleCaseFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/TitleCaseFilterTest.php
new file mode 100644 (file)
index 0000000..5a49e47
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class TitleCaseFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\TitleCaseFilter
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\TitleCaseFilter();
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       public function stringProvider() {
+               return array(
+                       'some text' => array('some text', 'Some Text'),
+                       'some Text' => array('some Text', 'Some Text'),
+                       'Ein Maß' => array('Ein Maß', 'Ein Maß'),
+                       '¿por que?' => array('¿por que?', '¿por Que?'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider stringProvider
+        */
+       public function filterForStringReturnsStringWithUppercasedWords($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/TrimFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/TrimFilterTest.php
new file mode 100644 (file)
index 0000000..59bffde
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class TrimFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\TrimFilter
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\TrimFilter();
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       public function stringProvider() {
+               return array(
+                       '\tsome text ' => array("\tsome text ", 'some text'),
+                       'some text   ' => array('some text   ', 'some text'),
+                       'some text^M' => array('some text
+', 'some text'),
+               );
+       }
+
+       public function stringProviderForCharacterList() {
+               return array(
+                       '$some text;' => array('$some text;', 'some text', '$;'),
+                       '$some text ' => array('$some text ', 'some text', '$ '),
+                       '^Msome text ' => array('
+some text ', 'some text', '
+ '),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider stringProvider
+        */
+       public function filterForStringWithWhitespaceInFrontAndEndReturnsStringWithoutThisWhitespace($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider stringProviderForCharacterList
+        */
+       public function filterForStringWithCharactersInCharacterListReturnsStringWithoutTheseCharacters($input, $expected, $characterList) {
+               $this->fixture->setCharacterList($characterList);
+
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/UpperCaseFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/UpperCaseFilterTest.php
new file mode 100644 (file)
index 0000000..92ebd95
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <nd@kaeufli.ch>, kaeufli.ch
+ *
+ *  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
+ *
+ * @author Andreas Lappe <nd@kaeufli.ch>
+ */
+class UpperCaseFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\UpperCaseFilter
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\UpperCaseFilter();
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->csConvObj = new \TYPO3\CMS\Core\Charset\CharsetConverter();
+               $GLOBALS['TSFE']->renderCharset = 'utf-8';
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+               unset($GLOBALS['TSFE']);
+       }
+
+       public function stringProvider() {
+               return array(
+                       'asdf' => array('asdf', 'ASDF'),
+                       'as?df' => array('as?df', 'AS?DF'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider stringProvider
+        */
+       public function filterForStringReturnsUppercasedString($input, $expected) {
+               $this->assertSame(
+                       $expected,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file