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