2 /***************************************************************
5 * (c) 2009 Steffen Kamper <info@sk-typo3.de>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * Testcase for comparing regular expressions in the TYPO3 core, eg. while
27 * replacing ereg* to preg*.
32 * @author Steffen Kamper <info@sk-typo3.de>
34 class regularexpression_testcase
extends tx_phpunit_testcase
{
35 public function setUp() {
38 public function tearDown() {
42 //////////////////////////////////
43 // Tests for regular expressions
44 //////////////////////////////////
49 public function removeLineFeeds() {
53 $test = (ereg_replace("[\n\r]*", '', $thisLine) == preg_replace('/[\n\r]*/', '', $thisLine));
62 public function removeNoneAscii() {
63 $string = 'this is a teststring with Umlauts äöü';
64 $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));
73 public function clearPath() {
74 $string = './thisDir/subDir/';
75 $test = (ereg_replace('^\./', '', $string) == preg_replace('/^\.\//', '', $string));
84 public function removeTrailingSign() {
86 $test = (ereg_replace(':$', '', $string) == preg_replace('/:$/', '', $string));
97 public function split1() {
98 $string = 'test1, test2|test3;test4';
99 $array1 = split(',|;|'.chr(10),$string);
100 $array2 = preg_split('/[,;'.chr(10).']/',$string);
101 foreach($array1 as $key => $value) {
103 ($array2[$key] === $value)
111 public function split2() {
112 $string = 'test1, test2=test3; test4';
113 $array1 = split('[[:space:]=]',$string,2);
114 $array2 = preg_split('/[[:space:]=]/',$string,2);
115 foreach($array1 as $key => $value) {
117 ($array2[$key] === $value)
125 public function split3() {
126 $string = 'test1:test2=test3; test4=test5|test6';
127 $array1 = split('=|:',$string,3);
128 $array2 = preg_split('/[=:]/',$string,3);
129 foreach($array1 as $key => $value) {
131 ($array2[$key] === $value)
139 public function split4() {
140 $string = 'key => value';
141 $array1 = split("[[:space:]=>]",$string,2);
142 $array2 = preg_split('/[[:space:]=>]/',$string,2);
143 foreach($array1 as $key => $value) {
145 ($array2[$key] === $value)
153 public function split5() {
154 $string = 'test[1][2][3][4] test[5] test[6]';
155 $array1 = split('\[|\]',$string);
156 $array2 = preg_split('/\[|\]/',$string);
157 foreach($array1 as $key => $value) {
159 ($array2[$key] === $value)