00001 <?php 00002 00003 print "This script is obsolete!"; 00004 print "It is retained in the source here in case some of its 00005 code might be useful for ad-hoc conversion tasks, but it is 00006 not maintained and probably won't even work as is."; 00007 exit(); 00008 00009 ?><html> 00010 <head> 00011 <title>Unit tests for UseMod-to-PediaWiki import script</title> 00012 <meta http-equiv="Refresh" content="10;URL=importTests.php"> 00013 <style> 00014 .pass { color: green } 00015 .fail { color: red } 00016 </style> 00017 </head> 00018 <body> 00019 00020 <?php 00021 00022 # Unit tests for importUseModWiki 00023 # Well, more or less ;) 00024 00025 $testingonly = true; 00026 00027 setlocale( LC_ALL, "C" ); 00028 00029 include( "importUseModWiki.php" ); 00030 00031 $wgRootDirectory = "./testconvert"; 00032 runTests(); 00033 00034 function runTests() { 00035 $success = 00036 testTimestamp() 00037 && testRecode() 00038 && testFreeToNormal() 00039 && testTransformTitle() 00040 && testMediaLinks() 00041 && testRemoveTalkLink() 00042 && testSubPages() 00043 ; 00044 if( $success ) { 00045 echo "\n<h1 class='pass'>** Passed all tests! **</h1>\n"; 00046 } else { 00047 echo "\n<h1 class='fail'>-- FAILED ONE OR MORE TESTS --</h1>\n"; 00048 } 00049 return $success; 00050 } 00051 00052 function passTest( $testname, $note = "" ) { 00053 if( $notes != "" ) $notes = " -- $notes"; 00054 echo "<span class='pass'>.. passed test $testname $notes</span><br />\n"; 00055 return true; 00056 } 00057 00058 function failTest( $testname, $notes = "" ) { 00059 if ( $notes != "" ) $notes = " -- $notes"; 00060 echo "<span class='fail'>** FAILED TEST $testname **$notes</span><br />\n"; 00061 return false; 00062 } 00063 00064 function testTimestamp() { 00065 $tn = "Timestamp"; 00066 $x = wfUnix2Timestamp( 0 ); 00067 if( $x != "19700101000000" ) { 00068 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" ); 00069 } 00070 00071 $x = wfTimestamp2Unix( "19700101000000" ); 00072 if( $x != 0 ) { 00073 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" ); 00074 } 00075 00076 return passTest( $tn ); 00077 } 00078 00079 function testRecode() { 00080 $tn = "Recode"; 00081 00082 # These functions are dummies for now 00083 $a = "abcd"; 00084 $x = recodeInput( $a ); 00085 if( $a != $x ) return failTest( $tn, "eo test returned different value" ); 00086 00087 $a = "ĉeĥa ŝaŭmmanĝaĵo"; 00088 $x = recodeInput( $a ); 00089 if( $a != $x ) return failTest( $tn, "eo test returned different value" ); 00090 00091 return passTest( $tn ); 00092 } 00093 00094 function testFreeToNormal() { 00095 $tn = "FreeToNormal"; 00096 $a = "WikiName"; $x = FreeToNormal( $a ); 00097 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" ); 00098 00099 $a = "With_Underscore"; $x = FreeToNormal( $a ); 00100 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" ); 00101 00102 $a = "With Space"; $x = FreeToNormal( $a ); 00103 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" ); 00104 00105 $a = "Mixed case"; $x = FreeToNormal( $a ); 00106 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" ); 00107 00108 $a = "\xe9cole"; $x = FreeToNormal( $a ); 00109 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" ); 00110 00111 return passTest( $tn ); 00112 } 00113 00114 function testTransformTitle() { 00115 global $talkending; 00116 $oldtalkending = $talkending; 00117 $tn = "TransformTitle"; 00118 00119 $a = "WikiName"; $x = transformTitle( $a ); 00120 if( $x->namespace != 0 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 0, WikiName instead -> $x->namespace , $x->title" ); 00121 00122 $talkending = "Talk"; 00123 $a = "WikiName/Talk"; $x = transformTitle( $a ); 00124 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" ); 00125 00126 $a = "WikiName/talk"; $x = transformTitle( $a ); 00127 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" ); 00128 00129 $talkending = "Diskuto"; 00130 $a = "WikiName/Diskuto"; $x = transformTitle( $a ); 00131 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" ); 00132 00133 $talkending = $oldtalkending; 00134 return passTest( $tn ); 00135 } 00136 00137 function testMediaLinks() { 00138 $tn = "MediaLinks"; 00139 00140 # Fetch 00141 $a = "magic.gif"; 00142 $x = fetchMediaFile( "???", "magic.gif" ); 00143 00144 00145 # Media links 00146 $a = "[http://www.wikipedia.org/upload/magic.gif]"; 00147 $b = "[[Media:Magic.gif]]"; # Or should it? 00148 $x = fixMediaLinks( $a ); 00149 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" ); 00150 00151 $a = "[http://www.wikipedia.org/upload/magic.gif Click image]"; 00152 $b = "[[Media:Magic.gif|Click image]]"; 00153 $x = fixMediaLinks( $a ); 00154 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" ); 00155 00156 # Image links: 00157 $a = "http://www.wikipedia.org/upload/magic.gif"; 00158 $b = "[[Image:Magic.gif]]"; 00159 $x = fixImageLinks( $a ); 00160 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" ); 00161 00162 $a = "http://www.wikipedia.org/upload/a/a4/magic.gif"; 00163 $b = "[[Image:Magic.gif]]"; 00164 $x = fixImageLinks( $a ); 00165 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" ); 00166 00167 return passTest( $tn ); 00168 } 00169 00170 function testRemoveTalkLink() { 00171 global $talkending; 00172 $tn = "RemoveTalkLink"; 00173 $oldtalkending = $talkending; 00174 $talkending = "Talk"; 00175 00176 $a = "Blah blah blah blah\nFoo bar baz.\n/Talk"; 00177 $b = "Blah blah blah blah\nFoo bar baz."; 00178 $x = removeTalkLink( $a ); 00179 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" ); 00180 00181 $a = "Blah blah blah blah\nFoo bar baz.\n[[/Talk]]"; 00182 $b = "Blah blah blah blah\nFoo bar baz."; 00183 $x = removeTalkLink( $a ); 00184 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" ); 00185 00186 $a = "Blah blah blah blah\nFoo bar baz.\n/talk"; # wait... should this not work? 00187 $b = "Blah blah blah blah\nFoo bar baz."; 00188 $x = removeTalkLink( $a ); 00189 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" ); 00190 00191 $talkending = "Priparolu"; 00192 $a = "Blah blah blah blah\nFoo bar baz.\n/Priparolu"; 00193 $b = "Blah blah blah blah\nFoo bar baz."; 00194 $x = removeTalkLink( $a ); 00195 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" ); 00196 00197 $talkending = $oldtalkending; 00198 return passTest( $tn ); 00199 } 00200 00201 function testSubPages() { 00202 $tn = "SubPages"; 00203 00204 $t = "TopPage"; 00205 $a = "Blah /Subpage blah"; 00206 $b = "Blah [[TopPage/Subpage|/Subpage]] blah"; 00207 $x = fixSubPages( $a, $t ); 00208 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00209 00210 $a = "Blah /subpage blah"; 00211 $b = $a; 00212 $x = fixSubPages( $a, $t ); 00213 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00214 00215 $a = "Blah [[/Subpage]] blah"; 00216 $b = "Blah [[TopPage/Subpage|/Subpage]] blah"; 00217 $x = fixSubPages( $a, $t ); 00218 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00219 00220 $a = "Blah [[/subpage]] blah"; 00221 $b = "Blah [[TopPage/Subpage|/subpage]] blah"; 00222 $x = fixSubPages( $a, $t ); 00223 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00224 00225 $a = "Blah [[/Subpage|Fizzle]] blah"; 00226 $b = "Blah [[TopPage/Subpage|Fizzle]] blah"; 00227 $x = fixSubPages( $a, $t ); 00228 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00229 00230 $a = "Blah [[/subpage|Fizzle]] blah"; 00231 $b = "Blah [[TopPage/Subpage|Fizzle]] blah"; 00232 $x = fixSubPages( $a, $t ); 00233 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00234 00235 $a = "Blah /\xc9cole blah"; 00236 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah"; 00237 $x = fixSubPages( $a, $t ); 00238 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00239 00240 $a = "Blah /\xe9cole blah"; 00241 $b = $a; 00242 $x = fixSubPages( $a, $t ); 00243 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00244 00245 $a = "Blah [[/\xc9cole]] blah"; 00246 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah"; 00247 $x = fixSubPages( $a, $t ); 00248 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00249 00250 $a = "Blah [[/\xe9cole]] blah"; 00251 $b = "Blah [[TopPage/\xe9cole|/\xe9cole]] blah"; 00252 $x = fixSubPages( $a, $t ); 00253 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00254 00255 $a = "Blah [[/xe9cole|Fizzle]] blah"; 00256 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah"; 00257 $x = fixSubPages( $a, $t ); 00258 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00259 00260 $a = "Blah [[/subpage|Fizzle]] blah"; 00261 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah"; 00262 $x = fixSubPages( $a, $t ); 00263 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" ); 00264 return passTest( $tn ); 00265 } 00266 00267 ?> 00268 </body> 00269 </html>