Modification to moveCustomMessages.php to create redirects, related modifications...
[lhc/web/wiklou.git] / maintenance / archives / importTests.php
1 <?php
2
3 print "This script is obsolete!";
4 print "It is retained in the source here in case some of its
5 code might be useful for ad-hoc conversion tasks, but it is
6 not maintained and probably won't even work as is.";
7 exit();
8
9 ?><html>
10 <head>
11 <title>Unit tests for UseMod-to-PediaWiki import script</title>
12 <meta http-equiv="Refresh" content="10;URL=importTests.php">
13 <style>
14 .pass { color: green }
15 .fail { color: red }
16 </style>
17 </head>
18 <body>
19
20 <?php
21
22 # Unit tests for importUseModWiki
23 # Well, more or less ;)
24
25 $testingonly = true;
26
27 setlocale( LC_ALL, "C" );
28
29 include( "importUseModWiki.php" );
30
31 $wgRootDirectory = "./testconvert";
32 runTests();
33
34 function runTests() {
35 $success =
36 testTimestamp()
37 && testRecode()
38 && testFreeToNormal()
39 && testTransformTitle()
40 && testMediaLinks()
41 && testRemoveTalkLink()
42 && testSubPages()
43 ;
44 if( $success ) {
45 echo "\n<h1 class='pass'>** Passed all tests! **</h1>\n";
46 } else {
47 echo "\n<h1 class='fail'>-- FAILED ONE OR MORE TESTS --</h1>\n";
48 }
49 return $success;
50 }
51
52 function passTest( $testname, $note = "" ) {
53 if( $notes != "" ) $notes = " -- $notes";
54 echo "<span class='pass'>.. passed test $testname $notes</span><br />\n";
55 return true;
56 }
57
58 function failTest( $testname, $notes = "" ) {
59 if ( $notes != "" ) $notes = " -- $notes";
60 echo "<span class='fail'>** FAILED TEST $testname **$notes</span><br />\n";
61 return false;
62 }
63
64 function testTimestamp() {
65 $tn = "Timestamp";
66 $x = wfUnix2Timestamp( 0 );
67 if( $x != "19700101000000" ) {
68 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
69 }
70
71 $x = wfTimestamp2Unix( "19700101000000" );
72 if( $x != 0 ) {
73 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
74 }
75
76 return passTest( $tn );
77 }
78
79 function testRecode() {
80 $tn = "Recode";
81
82 # These functions are dummies for now
83 $a = "abcd";
84 $x = recodeInput( $a );
85 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
86
87 $a = "ĉeĥa ŝaŭmmanĝaĵo";
88 $x = recodeInput( $a );
89 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
90
91 return passTest( $tn );
92 }
93
94 function testFreeToNormal() {
95 $tn = "FreeToNormal";
96 $a = "WikiName"; $x = FreeToNormal( $a );
97 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
98
99 $a = "With_Underscore"; $x = FreeToNormal( $a );
100 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
101
102 $a = "With Space"; $x = FreeToNormal( $a );
103 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" );
104
105 $a = "Mixed case"; $x = FreeToNormal( $a );
106 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" );
107
108 $a = "\xe9cole"; $x = FreeToNormal( $a );
109 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" );
110
111 return passTest( $tn );
112 }
113
114 function testTransformTitle() {
115 global $talkending;
116 $oldtalkending = $talkending;
117 $tn = "TransformTitle";
118
119 $a = "WikiName"; $x = transformTitle( $a );
120 if( $x->namespace != 0 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 0, WikiName instead -> $x->namespace , $x->title" );
121
122 $talkending = "Talk";
123 $a = "WikiName/Talk"; $x = transformTitle( $a );
124 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
125
126 $a = "WikiName/talk"; $x = transformTitle( $a );
127 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
128
129 $talkending = "Diskuto";
130 $a = "WikiName/Diskuto"; $x = transformTitle( $a );
131 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
132
133 $talkending = $oldtalkending;
134 return passTest( $tn );
135 }
136
137 function testMediaLinks() {
138 $tn = "MediaLinks";
139
140 # Fetch
141 $a = "magic.gif";
142 $x = fetchMediaFile( "???", "magic.gif" );
143
144
145 # Media links
146 $a = "[http://www.wikipedia.org/upload/magic.gif]";
147 $b = "[[Media:Magic.gif]]"; # Or should it?
148 $x = fixMediaLinks( $a );
149 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
150
151 $a = "[http://www.wikipedia.org/upload/magic.gif Click image]";
152 $b = "[[Media:Magic.gif|Click image]]";
153 $x = fixMediaLinks( $a );
154 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
155
156 # Image links:
157 $a = "http://www.wikipedia.org/upload/magic.gif";
158 $b = "[[Image:Magic.gif]]";
159 $x = fixImageLinks( $a );
160 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
161
162 $a = "http://www.wikipedia.org/upload/a/a4/magic.gif";
163 $b = "[[Image:Magic.gif]]";
164 $x = fixImageLinks( $a );
165 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
166
167 return passTest( $tn );
168 }
169
170 function testRemoveTalkLink() {
171 global $talkending;
172 $tn = "RemoveTalkLink";
173 $oldtalkending = $talkending;
174 $talkending = "Talk";
175
176 $a = "Blah blah blah blah\nFoo bar baz.\n/Talk";
177 $b = "Blah blah blah blah\nFoo bar baz.";
178 $x = removeTalkLink( $a );
179 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
180
181 $a = "Blah blah blah blah\nFoo bar baz.\n[[/Talk]]";
182 $b = "Blah blah blah blah\nFoo bar baz.";
183 $x = removeTalkLink( $a );
184 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
185
186 $a = "Blah blah blah blah\nFoo bar baz.\n/talk"; # wait... should this not work?
187 $b = "Blah blah blah blah\nFoo bar baz.";
188 $x = removeTalkLink( $a );
189 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
190
191 $talkending = "Priparolu";
192 $a = "Blah blah blah blah\nFoo bar baz.\n/Priparolu";
193 $b = "Blah blah blah blah\nFoo bar baz.";
194 $x = removeTalkLink( $a );
195 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
196
197 $talkending = $oldtalkending;
198 return passTest( $tn );
199 }
200
201 function testSubPages() {
202 $tn = "SubPages";
203
204 $t = "TopPage";
205 $a = "Blah /Subpage blah";
206 $b = "Blah [[TopPage/Subpage|/Subpage]] blah";
207 $x = fixSubPages( $a, $t );
208 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
209
210 $a = "Blah /subpage blah";
211 $b = $a;
212 $x = fixSubPages( $a, $t );
213 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
214
215 $a = "Blah [[/Subpage]] blah";
216 $b = "Blah [[TopPage/Subpage|/Subpage]] blah";
217 $x = fixSubPages( $a, $t );
218 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
219
220 $a = "Blah [[/subpage]] blah";
221 $b = "Blah [[TopPage/Subpage|/subpage]] blah";
222 $x = fixSubPages( $a, $t );
223 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
224
225 $a = "Blah [[/Subpage|Fizzle]] blah";
226 $b = "Blah [[TopPage/Subpage|Fizzle]] blah";
227 $x = fixSubPages( $a, $t );
228 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
229
230 $a = "Blah [[/subpage|Fizzle]] blah";
231 $b = "Blah [[TopPage/Subpage|Fizzle]] blah";
232 $x = fixSubPages( $a, $t );
233 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
234
235 $a = "Blah /\xc9cole blah";
236 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah";
237 $x = fixSubPages( $a, $t );
238 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
239
240 $a = "Blah /\xe9cole blah";
241 $b = $a;
242 $x = fixSubPages( $a, $t );
243 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
244
245 $a = "Blah [[/\xc9cole]] blah";
246 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah";
247 $x = fixSubPages( $a, $t );
248 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
249
250 $a = "Blah [[/\xe9cole]] blah";
251 $b = "Blah [[TopPage/\xe9cole|/\xe9cole]] blah";
252 $x = fixSubPages( $a, $t );
253 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
254
255 $a = "Blah [[/xe9cole|Fizzle]] blah";
256 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah";
257 $x = fixSubPages( $a, $t );
258 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
259
260 $a = "Blah [[/subpage|Fizzle]] blah";
261 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah";
262 $x = fixSubPages( $a, $t );
263 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
264 return passTest( $tn );
265 }
266
267 ?>
268 </body>
269 </html>