[BUGFIX] EXT:form tests and unicode fix
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 19 Sep 2012 17:45:15 +0000 (19:45 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 19 Sep 2012 18:14:15 +0000 (20:14 +0200)
This cleans up the existing EXT:form tests and
adds them to the travis testsuite.

The two filter test cases fail on systems like debian with
PHP 5.3.3 due to a broken PCRE environment. This issue is
identical to #39123 and the fix is very similar.

Change-Id: I18d806d795a40ff6aed8dbe388a3ddfb91d15fe3
Resolves: #41074
Related: #39123
Related: #35296
Related: #35284
Releases: 6.0
Reviewed-on: http://review.typo3.org/14738
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Build/UnitTests.xml
typo3/sysext/form/Classes/Filter/AlphabeticFilter.php
typo3/sysext/form/Classes/Filter/AlphanumericFilter.php
typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterFilterTest.php [deleted file]
typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterTest.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Filter/AlphanumericFilterTest.php
typo3/sysext/form/Tests/Unit/PostProcess/PostProcessorTest.php
typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php [deleted file]
typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php [deleted file]
typo3/sysext/form/Tests/Unit/System/Postprocessor/PostprocessorTest.php [deleted file]

index cfd583a..22a3aa7 100644 (file)
@@ -43,6 +43,9 @@
                <testsuite name="EXT:fluid tests">
                        <directory>../../../../typo3/sysext/fluid/Tests/Unit/</directory>
                </testsuite>
+               <testsuite name="EXT:form tests">
+                       <directory>../../../../typo3/sysext/form/Tests/Unit/</directory>
+               </testsuite>
                <testsuite name="EXT:scheduler tests">
                        <directory>../../../../typo3/sysext/scheduler/Tests/Unit/</directory>
                </testsuite>
index 6723bea..c9e3364 100644 (file)
@@ -68,7 +68,7 @@ class AlphabeticFilter implements \TYPO3\CMS\Form\Filter\FilterInterface {
         */
        public function filter($value) {
                $whiteSpace = $this->allowWhiteSpace ? '\\s' : '';
-               $pattern = '/[^[:alpha:]' . $whiteSpace . ']/u';
+               $pattern = '/[^\pL' . $whiteSpace . ']/u';
                return preg_replace($pattern, '', (string) $value);
        }
 
index ad9d81b..af7fe2f 100644 (file)
@@ -68,7 +68,7 @@ class AlphanumericFilter implements \TYPO3\CMS\Form\Filter\FilterInterface {
         */
        public function filter($value) {
                $whiteSpace = $this->allowWhiteSpace ? '\\s' : '';
-               $pattern = '/[^[:alnum:]' . $whiteSpace . ']/u';
+               $pattern = '/[^\pL\d' . $whiteSpace . ']/u';
                return preg_replace($pattern, '', (string) $value);
        }
 
diff --git a/typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterFilterTest.php
deleted file mode 100644 (file)
index 0539b97..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-namespace TYPO3\CMS\Form\Tests\Unit\Filter;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
- *
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Test case for class tx_form_System_Filter_Alphabetic.
- *
- * @author Andreas Lappe <a.lappe@kuehlhaus.com>
- * @package TYPO3
- * @subpackage form
- */
-class AlphabeticFilterFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @var \TYPO3\CMS\Form\Filter\AlphabeticFilter
-        */
-       protected $fixture;
-
-       public function setUp() {
-               $this->fixture = new \TYPO3\CMS\Form\Filter\AlphabeticFilter();
-       }
-
-       public function tearDown() {
-               unset($this->fixture);
-       }
-
-       /**
-        * @test
-        */
-       public function filterForStringWithUnicodeCharactersAndSpacesReturnsInputString() {
-               $input = 'My name contains äøüößØœ';
-               // This is default, but let's be explicit:
-               $this->fixture->setAllowWhiteSpace(TRUE);
-               $this->assertSame($input, $this->fixture->filter($input));
-       }
-
-       /**
-        * @test
-        */
-       public function filterForStringWithUnicodeCharactersAndSpacesWithAllowWhitespaceSetToFalseReturnsInputStringWithoutSpaces() {
-               $input = 'My name contains äøüößØœ';
-               $inputWithoutSpaces = 'MynamecontainsäøüößØœ';
-               $this->fixture->setAllowWhiteSpace(FALSE);
-               $this->assertSame($inputWithoutSpaces, $this->fixture->filter($input));
-       }
-
-}
-
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterTest.php
new file mode 100644 (file)
index 0000000..ffbea94
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace TYPO3\CMS\Form\Tests\Unit\Filter;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Testcase for AlphabeticFilter
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class AlphabeticFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Form\Filter\AlphabeticFilter
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Form\Filter\AlphabeticFilter();
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       /**
+        * @test
+        */
+       public function filterForStringWithUnicodeCharactersAndSpacesReturnsInputString() {
+               $input = 'My name contains äøüößØœ';
+               // This is default, but let's be explicit:
+               $this->fixture->setAllowWhiteSpace(TRUE);
+               $this->assertSame($input, $this->fixture->filter($input));
+       }
+
+       /**
+        * @test
+        */
+       public function filterForStringWithUnicodeCharactersAndSpacesWithAllowWhitespaceSetToFalseReturnsInputStringWithoutSpaces() {
+               $input = 'My name contains äøüößØœ';
+               $expected = 'MynamecontainsäøüößØœ';
+               $this->fixture->setAllowWhiteSpace(FALSE);
+               $this->assertSame($expected, $this->fixture->filter($input));
+       }
+
+}
+
+
+?>
\ No newline at end of file
index b935597..d7165ca 100644 (file)
@@ -36,14 +36,20 @@ class AlphanumericFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
        /**
         * @var \TYPO3\CMS\Form\Filter\AlphanumericFilter
         */
-       protected $fixture;
+       protected $fixture = NULL;
 
+       /**
+        * Set up
+        */
        public function setUp() {
                $this->fixture = new \TYPO3\CMS\Form\Filter\AlphanumericFilter();
        }
 
+       /**
+        * Tear down
+        */
        public function tearDown() {
-               unset($this->fixture);
+               $this->fixture = NULL;
        }
 
        /**
@@ -61,9 +67,16 @@ class AlphanumericFilterTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
         */
        public function filterForStringWithUnicodeCharactersAndSpacesWithAllowWhitespaceSetToFalseReturnsInputStringWithoutSpaces() {
                $input = 'My name contains äøüößØœ';
-               $inputWithoutSpaces = 'MynamecontainsäøüößØœ';
+               $expected = 'MynamecontainsäøüößØœ';
                $this->fixture->setAllowWhiteSpace(FALSE);
-               $this->assertSame($inputWithoutSpaces, $this->fixture->filter($input));
+               $this->assertSame($expected, $this->fixture->filter($input));
+       }
+
+       /**
+        * @test
+        */
+       public function filterAllowsNumericCharacters() {
+               $this->assertSame('foo23bar', $this->fixture->filter('foo23bar'));
        }
 
 }
index 5100589..d6c0201 100644 (file)
@@ -25,7 +25,7 @@ namespace TYPO3\CMS\Form\Tests\Unit\PostProcess;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Test case for class tx_form_System_Postprocessor
+ * Testcase for PostProcessor
  *
  * @author Susanne Moog, <typo3@susannemoog.de>
  * @package TYPO3
@@ -34,85 +34,44 @@ namespace TYPO3\CMS\Form\Tests\Unit\PostProcess;
 class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * @var \PHPUnit_Framework_MockObject_MockObject
+        * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Form\PostProcess\PostProcessor
         */
-       public $postprocessor;
+       public $fixture;
 
        /**
-        * @var string
-        */
-       public $classNameWithoutPrefix;
-
-       /**
-        * @var string
-        */
-       public $classNameWithPrefix;
-
-       /**
-        * @var string
-        */
-       public $classNameWithoutInterface;
-
-       /**
-        * @var \TYPO3\CMS\Form\Domain\Model\Form
-        */
-       public $form;
-
-       /**
-        * set up
+        * Set up
         */
        public function setUp() {
-               $this->form = new \TYPO3\CMS\Form\Domain\Model\Form();
-               $this->postprocessor = $this->getMock('TYPO3\CMS\Form\PostProcess\PostProcessor', array('sortTypoScriptKeyList'), array(
-                       $this->form,
-                       array()
-               ));
-               $this->classNameWithoutPrefix = uniqid('postprocess');
-               $this->classNameWithPrefix = uniqid('postprocess');
-               $this->classNameWithoutInterface = uniqid('postprocess');
-               eval('
-                       namespace TYPO3\CMS\Form\PostProcess;
-                       class ' . $this->classNameWithoutPrefix . 'PostProcessor implements PostProcessorInterface {
-
-                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
-
-                               }
-
-                               public function process() {
-                                       return \'processedWithoutPrefix\';
-                               }
-                       }' . 'class ' . $this->classNameWithPrefix . 'PostProcessor implements PostProcessorInterface {
-
-                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
-
-                               }
-
-                               public function process() {
-                                       return \'processedWithPrefix\';
-                               }
-                       }' . 'class ' . $this->classNameWithoutInterface . 'PostProcessor{
-
-                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
-
-                               }
-
-                               public function process() {
-                                       return \'withoutInterface\';
-                               }
-                       }');
+               $form = $this->getMock('TYPO3\\CMS\\Form\\Domain\\Model\\Form', array(), array(), '', FALSE);
+               $this->fixture = $this->getMock(
+                       'TYPO3\CMS\Form\PostProcess\PostProcessor',
+                       array('sortTypoScriptKeyList'),
+                       array($form, array())
+               );
        }
 
        /**
         * @test
         */
        public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
+               $classNameWithoutPrefix = uniqid('postprocess');
+               eval(
+                       'namespace TYPO3\CMS\Form\PostProcess;' .
+                       'class ' . $classNameWithoutPrefix . 'PostProcessor implements PostProcessorInterface {' .
+                       '  public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
+                       '  }' .
+                       '  public function process() {' .
+                       '    return \'processedWithoutPrefix\';' .
+                       '  }' .
+                       '}'
+               );
                $typoScript = array(
                        10 => uniqid('postprocess'),
-                       20 => $this->classNameWithoutPrefix
+                       20 => $classNameWithoutPrefix
                );
-               $this->postprocessor->typoScript = $typoScript;
-               $this->postprocessor->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
-               $returnValue = $this->postprocessor->process();
+               $this->fixture->typoScript = $typoScript;
+               $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
+               $returnValue = $this->fixture->process();
                $this->assertEquals('processedWithoutPrefix', $returnValue);
        }
 
@@ -120,13 +79,24 @@ class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
+               $classNameWithPrefix = uniqid('postprocess');
+               eval(
+                       'namespace TYPO3\CMS\Form\PostProcess;' .
+                       'class ' . $classNameWithPrefix . 'PostProcessor implements PostProcessorInterface {' .
+                       '  public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
+                       '  }' .
+                       '  public function process() {' .
+                       '    return \'processedWithPrefix\';' .
+                       '  }' .
+                       '}'
+               );
                $typoScript = array(
                        10 => uniqid('postprocess'),
-                       20 => $this->classNameWithPrefix
+                       20 => $classNameWithPrefix
                );
-               $this->postprocessor->typoScript = $typoScript;
-               $this->postprocessor->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
-               $returnValue = $this->postprocessor->process();
+               $this->fixture->typoScript = $typoScript;
+               $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
+               $returnValue = $this->fixture->process();
                $this->assertEquals('processedWithPrefix', $returnValue);
        }
 
@@ -134,13 +104,24 @@ class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
+               $classNameWithoutInterface = uniqid('postprocess');
+               eval(
+                       'namespace TYPO3\CMS\Form\PostProcess;' .
+                       'class ' . $classNameWithoutInterface . 'PostProcessor {' .
+                       '  public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
+                       '  }' .
+                       '  public function process() {' .
+                       '    return \'withoutInterface\';' .
+                       '  }' .
+                       '}'
+               );
                $typoScript = array(
                        10 => uniqid('postprocess'),
-                       20 => $this->classNameWithoutInterface
+                       20 => $classNameWithoutInterface
                );
-               $this->postprocessor->typoScript = $typoScript;
-               $this->postprocessor->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
-               $returnValue = $this->postprocessor->process();
+               $this->fixture->typoScript = $typoScript;
+               $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
+               $returnValue = $this->fixture->process();
                $this->assertEquals('', $returnValue);
        }
 
diff --git a/typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php b/typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php
deleted file mode 100644 (file)
index 2fab3bc..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-/*
- * @deprecated since 6.0, the classname tx_form_System_Filter_AlphabeticTest and this file is obsolete
- * and will be removed by 7.0. The class was renamed and is now located at:
- * typo3/sysext/form/Tests/Unit/Filter/AlphabeticFilterFilterTest.php
- */
-require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('form') . 'Tests/Unit/Filter/AlphabeticFilterFilterTest.php';
-?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php b/typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php
deleted file mode 100644 (file)
index 10e6c66..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-/*
- * @deprecated since 6.0, the classname tx_form_System_Filter_AlphanumericTest and this file is obsolete
- * and will be removed by 7.0. The class was renamed and is now located at:
- * typo3/sysext/form/Tests/Unit/Filter/AlphanumericFilterTest.php
- */
-require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('form') . 'Tests/Unit/Filter/AlphanumericFilterTest.php';
-?>
\ No newline at end of file
diff --git a/typo3/sysext/form/Tests/Unit/System/Postprocessor/PostprocessorTest.php b/typo3/sysext/form/Tests/Unit/System/Postprocessor/PostprocessorTest.php
deleted file mode 100644 (file)
index d1ad063..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-/*
- * @deprecated since 6.0, the classname tx_form_System_Postprocessor_PostprocessorTest and this file is obsolete
- * and will be removed by 7.0. The class was renamed and is now located at:
- * typo3/sysext/form/Tests/Unit/PostProcess/PostProcessorTest.php
- */
-require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('form') . 'Tests/Unit/PostProcess/PostProcessorTest.php';
-?>
\ No newline at end of file