Convert DOS to Unix linebreaks
[Packages/TYPO3.CMS.git] / typo3 / 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
27 /**
28 * Testcase for comparing regular expressions in the TYPO3 core, eg while replacing ereg* to preg*
29 *
30 * @package TYPO3
31 * @subpackage t3lib
32 *
33 * @author Steffen Kamper <info@sk-typo3.de>
34 */
35 class regularexpression_testcase extends tx_phpunit_testcase {
36
37
38 public function setUp() {
39
40 }
41
42 public function tearDown() {
43
44 }
45
46
47 //////////////////////
48 // Utility functions
49 //////////////////////
50
51
52
53
54 ////////////////////////////////////
55 // Tests for regular expressions
56 ////////////////////////////////////
57
58 public function testRemoveLineFeeds() {
59 $thisLine = 'test
60 test
61 test';
62 $test = (ereg_replace("[\n\r]*", '', $thisLine) == preg_replace('/[\n\r]*/', '', $thisLine));
63 $this->assertTrue(
64 $test
65 );
66 }
67
68 public function testRemoveNoneAscii() {
69 $string = 'this is a teststring with Umlauts äöü';
70 $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));
71 $this->assertTrue(
72 $test
73 );
74 }
75
76 public function testClearPath() {
77 $string = './thisDir/subDir/';
78 $test = (ereg_replace('^\./', '', $string) == preg_replace('/^\.\//', '', $string));
79 $this->assertTrue(
80 $test
81 );
82 }
83
84 public function testRemoveTrailingSign() {
85 $string = 'label:';
86 $test = (ereg_replace(':$', '', $string) == preg_replace('/:$/', '', $string));
87 $this->assertTrue(
88 $test
89 );
90 }
91
92
93
94 public function testSplit1() {
95 $string = 'test1, test2|test3;test4';
96 $array1 = split(',|;|'.chr(10),$string);
97 $array2 = preg_split('/[,;'.chr(10).']/',$string);
98 foreach($array1 as $key => $value) {
99 $this->assertTrue(
100 ($array2[$key] === $value)
101 );
102 }
103 }
104
105 public function testSplit2() {
106 $string = 'test1, test2=test3; test4';
107 $array1 = split('[[:space:]=]',$string,2);
108 $array2 = preg_split('/[[:space:]=]/',$string,2);
109 foreach($array1 as $key => $value) {
110 $this->assertTrue(
111 ($array2[$key] === $value)
112 );
113 }
114 }
115
116 public function testSplit3() {
117 $string = 'test1:test2=test3; test4=test5|test6';
118 $array1 = split('=|:',$string,3);
119 $array2 = preg_split('/[=:]/',$string,3);
120 foreach($array1 as $key => $value) {
121 $this->assertTrue(
122 ($array2[$key] === $value)
123 );
124 }
125 }
126
127 public function testSplit4() {
128 $string = 'key => value';
129 $array1 = split("[[:space:]=>]",$string,2);
130 $array2 = preg_split('/[[:space:]=>]/',$string,2);
131 foreach($array1 as $key => $value) {
132 $this->assertTrue(
133 ($array2[$key] === $value)
134 );
135 }
136 }
137
138 public function testSplit5() {
139 $string = 'test[1][2][3][4] test[5] test[6]';
140 $array1 = split('\[|\]',$string);
141 $array2 = preg_split('/\[|\]/',$string);
142 foreach($array1 as $key => $value) {
143 $this->assertTrue(
144 ($array2[$key] === $value)
145 );
146 }
147 }
148
149
150 }
151 ?>