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.";
11 <title
>Unit tests
for UseMod
-to
-PediaWiki import script
</title
>
12 <meta http
-equiv
="Refresh" content
="10;URL=importTests.php">
14 .pass
{ color
: green
}
22 # Unit tests for importUseModWiki
23 # Well, more or less ;)
27 setlocale( LC_ALL
, "C" );
29 include_once( "importUseModWiki.php" );
31 $wgRootDirectory = "./testconvert";
39 && testTransformTitle()
41 && testRemoveTalkLink()
45 echo "\n<h1 class='pass'>** Passed all tests! **</h1>\n";
47 echo "\n<h1 class='fail'>-- FAILED ONE OR MORE TESTS --</h1>\n";
52 function passTest( $testname, $note = "" ) {
53 if( $notes != "" ) $notes = " -- $notes";
54 echo "<span class='pass'>.. passed test $testname $notes</span><br />\n";
58 function failTest( $testname, $notes = "" ) {
59 if ( $notes != "" ) $notes = " -- $notes";
60 echo "<span class='fail'>** FAILED TEST $testname **$notes</span><br />\n";
64 function testTimestamp() {
66 $x = wfUnix2Timestamp( 0 );
67 if( $x != "19700101000000" ) {
68 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
71 $x = wfTimestamp2Unix( "19700101000000" );
73 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
76 return passTest( $tn );
79 function testRecode() {
82 # These functions are dummies for now
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() {
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() {
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() {
142 $x = fetchMediaFile( "???", "magic.gif" );
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" );
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() {
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() {
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";
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";
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 );