Fixed bug #11985: Optimize disposal of t3lib_PageRenderer
[Packages/TYPO3.CMS.git] / tests / regularexpression_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Steffen Kamper <info@sk-typo3.de>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for comparing regular expressions in the TYPO3 core, eg. while
27 * replacing ereg* to preg*.
28 *
29 * @package TYPO3
30 * @subpackage t3lib
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 */
34 class regularexpression_testcase extends tx_phpunit_testcase {
35 public function setUp() {
36 }
37
38 public function tearDown() {
39 }
40
41
42 //////////////////////////////////
43 // Tests for regular expressions
44 //////////////////////////////////
45
46 /**
47 * @test
48 */
49 public function removeLineFeeds() {
50 $thisLine = 'test
51 test
52 test';
53 $test = (ereg_replace("[\n\r]*", '', $thisLine) == preg_replace('/[\n\r]*/', '', $thisLine));
54 $this->assertTrue(
55 $test
56 );
57 }
58
59 /**
60 * @test
61 */
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));
65 $this->assertTrue(
66 $test
67 );
68 }
69
70 /**
71 * @test
72 */
73 public function clearPath() {
74 $string = './thisDir/subDir/';
75 $test = (ereg_replace('^\./', '', $string) == preg_replace('/^\.\//', '', $string));
76 $this->assertTrue(
77 $test
78 );
79 }
80
81 /**
82 * @test
83 */
84 public function removeTrailingSign() {
85 $string = 'label:';
86 $test = (ereg_replace(':$', '', $string) == preg_replace('/:$/', '', $string));
87 $this->assertTrue(
88 $test
89 );
90 }
91
92
93
94 /**
95 * @test
96 */
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) {
102 $this->assertTrue(
103 ($array2[$key] === $value)
104 );
105 }
106 }
107
108 /**
109 * @test
110 */
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) {
116 $this->assertTrue(
117 ($array2[$key] === $value)
118 );
119 }
120 }
121
122 /**
123 * @test
124 */
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) {
130 $this->assertTrue(
131 ($array2[$key] === $value)
132 );
133 }
134 }
135
136 /**
137 * @test
138 */
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) {
144 $this->assertTrue(
145 ($array2[$key] === $value)
146 );
147 }
148 }
149
150 /**
151 * @test
152 */
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) {
158 $this->assertTrue(
159 ($array2[$key] === $value)
160 );
161 }
162 }
163 }
164 ?>