added testcase (unittest) for regular expressions
authorSteffen Kamper <info@sk-typo3.de>
Thu, 22 Jan 2009 20:51:12 +0000 (20:51 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Thu, 22 Jan 2009 20:51:12 +0000 (20:51 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4823 709f56b5-9817-0410-a4d7-c38de5d9e867

typo3/tests/regularexpression_testcase.php [new file with mode: 0644]

diff --git a/typo3/tests/regularexpression_testcase.php b/typo3/tests/regularexpression_testcase.php
new file mode 100644 (file)
index 0000000..1f3f145
--- /dev/null
@@ -0,0 +1,151 @@
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2009 Steffen Kamper <info@sk-typo3.de> \r
+* All rights reserved\r
+*\r
+* This script is part of the TYPO3 project. The TYPO3 project is\r
+* free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* The GNU General Public License can be found at\r
+* http://www.gnu.org/copyleft/gpl.html.\r
+*\r
+* This script is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+\r
+\r
+/**\r
+ * Testcase for comparing regular expressions in the TYPO3 core, eg while replacing ereg* to preg*\r
+ *\r
+ * @package TYPO3\r
+ * @subpackage t3lib\r
+ *\r
+ * @author Steffen Kamper <info@sk-typo3.de>\r
+ */\r
+class regularexpression_testcase extends tx_phpunit_testcase {\r
+       \r
+\r
+       public function setUp() {\r
+               \r
+       }\r
+\r
+       public function tearDown() {\r
+               \r
+       }\r
+\r
+\r
+       //////////////////////\r
+       // Utility functions\r
+       //////////////////////\r
+\r
+       \r
+\r
+\r
+       ////////////////////////////////////\r
+       // Tests for regular expressions\r
+       ////////////////////////////////////\r
+\r
+       public function testRemoveLineFeeds() {\r
+           $thisLine = 'test\r
+           test\r
+           test';      \r
+           $test = (ereg_replace("[\n\r]*", '', $thisLine) == preg_replace('/[\n\r]*/', '', $thisLine));\r
+               $this->assertTrue(\r
+                       $test\r
+               );\r
+       }\r
+\r
+       public function testRemoveNoneAscii() {\r
+               $string = 'this is a teststring with Umlauts äöü';\r
+           $test = (substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($string))),0,30) == substr(preg_replace('/[^a-zA-Z0-9_]/', '', str_replace(' ', '_', trim($string))), 0, 30));\r
+               $this->assertTrue(\r
+                       $test\r
+               );\r
+       }\r
+\r
+       public function testClearPath() {\r
+               $string = './thisDir/subDir/';\r
+           $test = (ereg_replace('^\./', '', $string) == preg_replace('/^\.\//', '', $string));\r
+               $this->assertTrue(\r
+                       $test\r
+               );\r
+       }\r
+\r
+       public function testRemoveTrailingSign() {\r
+               $string = 'label:';\r
+           $test = (ereg_replace(':$', '', $string) == preg_replace('/:$/', '', $string));\r
+               $this->assertTrue(\r
+                       $test\r
+               );\r
+       }\r
+\r
+       \r
+       \r
+       public function testSplit1() {\r
+               $string = 'test1, test2|test3;test4';\r
+               $array1 = split(',|;|'.chr(10),$string);\r
+               $array2 = preg_split('/[,;'.chr(10).']/',$string);\r
+               foreach($array1 as $key => $value) {\r
+                       $this->assertTrue(\r
+                               ($array2[$key] === $value)\r
+                       );\r
+               }\r
+       }\r
+\r
+       public function testSplit2() {\r
+               $string = 'test1, test2=test3; test4';\r
+               $array1 = split('[[:space:]=]',$string,2);\r
+               $array2 = preg_split('/[[:space:]=]/',$string,2);\r
+               foreach($array1 as $key => $value) {\r
+                       $this->assertTrue(\r
+                               ($array2[$key] === $value)\r
+                       );\r
+               }\r
+       }\r
+\r
+       public function testSplit3() {\r
+               $string = 'test1:test2=test3; test4=test5|test6';\r
+               $array1 = split('=|:',$string,3);\r
+               $array2 = preg_split('/[=:]/',$string,3);\r
+               foreach($array1 as $key => $value) {\r
+                       $this->assertTrue(\r
+                               ($array2[$key] === $value)\r
+                       );\r
+               }\r
+       }\r
+\r
+       public function testSplit4() {\r
+               $string = 'key => value';\r
+               $array1 = split("[[:space:]=>]",$string,2);\r
+               $array2 = preg_split('/[[:space:]=>]/',$string,2);\r
+               foreach($array1 as $key => $value) {\r
+                       $this->assertTrue(\r
+                               ($array2[$key] === $value)\r
+                       );\r
+               }\r
+       }\r
+\r
+       public function testSplit5() {\r
+               $string = 'test[1][2][3][4] test[5] test[6]';\r
+               $array1 = split('\[|\]',$string);\r
+               $array2 = preg_split('/\[|\]/',$string);\r
+               foreach($array1 as $key => $value) {\r
+                       $this->assertTrue(\r
+                               ($array2[$key] === $value)\r
+                       );\r
+               }\r
+       }\r
+\r
+       \r
+}\r
+?>
\ No newline at end of file