3 <title
>Unit tests
for UseMod
-to
-PediaWiki import script
</title
>
4 <meta http
-equiv
="Refresh" content
="10;URL=importTests.php">
14 # Unit tests for importUseModWiki
15 # Well, more or less ;)
19 setlocale( LC_ALL
, "C" );
21 include( "importUseModWiki.php" );
23 $wgRootDirectory = "./testconvert";
31 && testTransformTitle()
33 && testRemoveTalkLink()
37 echo "\n<h1 class='pass'>** Passed all tests! **</h1>\n";
39 echo "\n<h1 class='fail'>-- FAILED ONE OR MORE TESTS --</h1>\n";
44 function passTest( $testname, $note = "" ) {
45 if( $notes != "" ) $notes = " -- $notes";
46 echo "<span class='pass'>.. passed test $testname $notes</span><br />\n";
50 function failTest( $testname, $notes = "" ) {
51 if ( $notes != "" ) $notes = " -- $notes";
52 echo "<span class='fail'>** FAILED TEST $testname **$notes</span><br />\n";
56 function testTimestamp() {
58 $x = wfUnix2Timestamp( 0 );
59 if( $x != "19700101000000" ) {
60 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
63 $x = wfTimestamp2Unix( "19700101000000" );
65 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
68 return passTest( $tn );
71 function testRecode() {
74 # These functions are dummies for now
76 $x = recodeInput( $a );
77 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
79 $a = "ĉeĥa ŝaŭmmanĝaĵo";
80 $x = recodeInput( $a );
81 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
83 return passTest( $tn );
86 function testFreeToNormal() {
88 $a = "WikiName"; $x = FreeToNormal( $a );
89 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
91 $a = "With_Underscore"; $x = FreeToNormal( $a );
92 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
94 $a = "With Space"; $x = FreeToNormal( $a );
95 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" );
97 $a = "Mixed case"; $x = FreeToNormal( $a );
98 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" );
100 $a = "\xe9cole"; $x = FreeToNormal( $a );
101 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" );
103 return passTest( $tn );
106 function testTransformTitle() {
108 $oldtalkending = $talkending;
109 $tn = "TransformTitle";
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" );
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" );
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" );
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" );
125 $talkending = $oldtalkending;
126 return passTest( $tn );
129 function testMediaLinks() {
134 $x = fetchMediaFile( "???", "magic.gif" );
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" );
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" );
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" );
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" );
159 return passTest( $tn );
162 function testRemoveTalkLink() {
164 $tn = "RemoveTalkLink";
165 $oldtalkending = $talkending;
166 $talkending = "Talk";
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'" );
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'" );
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'" );
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'" );
189 $talkending = $oldtalkending;
190 return passTest( $tn );
193 function testSubPages() {
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'" );
202 $a = "Blah /subpage blah";
204 $x = fixSubPages( $a, $t );
205 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
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'" );
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'" );
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'" );
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'" );
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'" );
232 $a = "Blah /\xe9cole blah";
234 $x = fixSubPages( $a, $t );
235 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
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'" );
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'" );
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'" );
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 );