dirty hack to work around the one-space-at-beginning-required problem
[mediawiki.git] / maintenance / archives / importTests.php
blobef751a759eaf8ed785e9d03bc060c215e9a5628e
1 <?php
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();
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>
20 <?php
22 # Unit tests for importUseModWiki
23 # Well, more or less ;)
25 $testingonly = true;
27 setlocale( LC_ALL, "C" );
29 include( "importUseModWiki.php" );
31 $wgRootDirectory = "./testconvert";
32 runTests();
34 function runTests() {
35 $success =
36 testTimestamp()
37 && testRecode()
38 && testFreeToNormal()
39 && testTransformTitle()
40 && testMediaLinks()
41 && testRemoveTalkLink()
42 && testSubPages()
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";
49 return $success;
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;
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;
64 function testTimestamp() {
65 $tn = "Timestamp";
66 $x = wfUnix2Timestamp( 0 );
67 if( $x != "19700101000000" ) {
68 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
71 $x = wfTimestamp2Unix( "19700101000000" );
72 if( $x != 0 ) {
73 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
76 return passTest( $tn );
79 function testRecode() {
80 $tn = "Recode";
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" );
87 $a = "ĉeĥa ŝaŭmmanĝaĵo";
88 $x = recodeInput( $a );
89 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
91 return passTest( $tn );
94 function testFreeToNormal() {
95 $tn = "FreeToNormal";
96 $a = "WikiName"; $x = FreeToNormal( $a );
97 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
99 $a = "With_Underscore"; $x = FreeToNormal( $a );
100 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
102 $a = "With Space"; $x = FreeToNormal( $a );
103 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" );
105 $a = "Mixed case"; $x = FreeToNormal( $a );
106 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" );
108 $a = "\xe9cole"; $x = FreeToNormal( $a );
109 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" );
111 return passTest( $tn );
114 function testTransformTitle() {
115 global $talkending;
116 $oldtalkending = $talkending;
117 $tn = "TransformTitle";
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" );
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" );
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" );
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" );
133 $talkending = $oldtalkending;
134 return passTest( $tn );
137 function testMediaLinks() {
138 $tn = "MediaLinks";
140 # Fetch
141 $a = "magic.gif";
142 $x = fetchMediaFile( "???", "magic.gif" );
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" );
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" );
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" );
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" );
167 return passTest( $tn );
170 function testRemoveTalkLink() {
171 global $talkending;
172 $tn = "RemoveTalkLink";
173 $oldtalkending = $talkending;
174 $talkending = "Talk";
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'" );
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'" );
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'" );
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'" );
197 $talkending = $oldtalkending;
198 return passTest( $tn );
201 function testSubPages() {
202 $tn = "SubPages";
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'" );
210 $a = "Blah /subpage blah";
211 $b = $a;
212 $x = fixSubPages( $a, $t );
213 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
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'" );
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'" );
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'" );
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'" );
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'" );
240 $a = "Blah /\xe9cole blah";
241 $b = $a;
242 $x = fixSubPages( $a, $t );
243 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
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'" );
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'" );
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'" );
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 );
268 </body>
269 </html>