allow NULL html/mathml entries in math table
[mediawiki.git] / maintenance / archives / importTests.php
blobec9e6f9bd878f7bb4973a4ec34a1b290adcc0826
1 <?php
2 /**
3 * @deprecated
4 * @package MediaWiki
5 * @subpackage MaintenanceArchive
6 */
8 /** */
9 print "This script is obsolete!";
10 print "It is retained in the source here in case some of its
11 code might be useful for ad-hoc conversion tasks, but it is
12 not maintained and probably won't even work as is.";
13 exit();
15 ?><html>
16 <head>
17 <title>Unit tests for UseMod-to-PediaWiki import script</title>
18 <meta http-equiv="Refresh" content="10;URL=importTests.php">
19 <style>
20 .pass { color: green }
21 .fail { color: red }
22 </style>
23 </head>
24 <body>
26 <?php
28 # Unit tests for importUseModWiki
29 # Well, more or less ;)
31 $testingonly = true;
33 setlocale( LC_ALL, "C" );
35 include_once( "importUseModWiki.php" );
37 $wgRootDirectory = "./testconvert";
38 runTests();
40 function runTests() {
41 $success =
42 testTimestamp()
43 && testRecode()
44 && testFreeToNormal()
45 && testTransformTitle()
46 && testMediaLinks()
47 && testRemoveTalkLink()
48 && testSubPages()
50 if( $success ) {
51 echo "\n<h1 class='pass'>** Passed all tests! **</h1>\n";
52 } else {
53 echo "\n<h1 class='fail'>-- FAILED ONE OR MORE TESTS --</h1>\n";
55 return $success;
58 function passTest( $testname, $note = "" ) {
59 if( $notes != "" ) $notes = " -- $notes";
60 echo "<span class='pass'>.. passed test $testname $notes</span><br />\n";
61 return true;
64 function failTest( $testname, $notes = "" ) {
65 if ( $notes != "" ) $notes = " -- $notes";
66 echo "<span class='fail'>** FAILED TEST $testname **$notes</span><br />\n";
67 return false;
70 function testTimestamp() {
71 $tn = "Timestamp";
72 $x = wfUnix2Timestamp( 0 );
73 if( $x != "19700101000000" ) {
74 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
77 $x = wfTimestamp2Unix( "19700101000000" );
78 if( $x != 0 ) {
79 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
82 return passTest( $tn );
85 function testRecode() {
86 $tn = "Recode";
88 # These functions are dummies for now
89 $a = "abcd";
90 $x = recodeInput( $a );
91 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
93 $a = "ĉeĥa ŝaŭmmanĝaĵo";
94 $x = recodeInput( $a );
95 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
97 return passTest( $tn );
100 function testFreeToNormal() {
101 $tn = "FreeToNormal";
102 $a = "WikiName"; $x = FreeToNormal( $a );
103 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
105 $a = "With_Underscore"; $x = FreeToNormal( $a );
106 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
108 $a = "With Space"; $x = FreeToNormal( $a );
109 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" );
111 $a = "Mixed case"; $x = FreeToNormal( $a );
112 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" );
114 $a = "\xe9cole"; $x = FreeToNormal( $a );
115 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" );
117 return passTest( $tn );
120 function testTransformTitle() {
121 global $talkending;
122 $oldtalkending = $talkending;
123 $tn = "TransformTitle";
125 $a = "WikiName"; $x = transformTitle( $a );
126 if( $x->namespace != 0 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 0, WikiName instead -> $x->namespace , $x->title" );
128 $talkending = "Talk";
129 $a = "WikiName/Talk"; $x = transformTitle( $a );
130 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
132 $a = "WikiName/talk"; $x = transformTitle( $a );
133 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
135 $talkending = "Diskuto";
136 $a = "WikiName/Diskuto"; $x = transformTitle( $a );
137 if( $x->namespace != 1 or $x->title != "WikiName" ) return failTest( $tn, "$a -> 1, WikiName instead -> $x->namespace , $x->title" );
139 $talkending = $oldtalkending;
140 return passTest( $tn );
143 function testMediaLinks() {
144 $tn = "MediaLinks";
146 # Fetch
147 $a = "magic.gif";
148 $x = fetchMediaFile( "???", "magic.gif" );
151 # Media links
152 $a = "[http://www.wikipedia.org/upload/magic.gif]";
153 $b = "[[Media:Magic.gif]]"; # Or should it?
154 $x = fixMediaLinks( $a );
155 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
157 $a = "[http://www.wikipedia.org/upload/magic.gif Click image]";
158 $b = "[[Media:Magic.gif|Click image]]";
159 $x = fixMediaLinks( $a );
160 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
162 # Image links:
163 $a = "http://www.wikipedia.org/upload/magic.gif";
164 $b = "[[Image:Magic.gif]]";
165 $x = fixImageLinks( $a );
166 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
168 $a = "http://www.wikipedia.org/upload/a/a4/magic.gif";
169 $b = "[[Image:Magic.gif]]";
170 $x = fixImageLinks( $a );
171 if( $x != $b ) return failTest( $tn, "$a should be $b, is $x" );
173 return passTest( $tn );
176 function testRemoveTalkLink() {
177 global $talkending;
178 $tn = "RemoveTalkLink";
179 $oldtalkending = $talkending;
180 $talkending = "Talk";
182 $a = "Blah blah blah blah\nFoo bar baz.\n/Talk";
183 $b = "Blah blah blah blah\nFoo bar baz.";
184 $x = removeTalkLink( $a );
185 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
187 $a = "Blah blah blah blah\nFoo bar baz.\n[[/Talk]]";
188 $b = "Blah blah blah blah\nFoo bar baz.";
189 $x = removeTalkLink( $a );
190 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
192 $a = "Blah blah blah blah\nFoo bar baz.\n/talk"; # wait... should this not work?
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 = "Priparolu";
198 $a = "Blah blah blah blah\nFoo bar baz.\n/Priparolu";
199 $b = "Blah blah blah blah\nFoo bar baz.";
200 $x = removeTalkLink( $a );
201 if( $x != $b ) return failTest( $tn, "removing talk link: '$a' -> '$x', should be '$b'" );
203 $talkending = $oldtalkending;
204 return passTest( $tn );
207 function testSubPages() {
208 $tn = "SubPages";
210 $t = "TopPage";
211 $a = "Blah /Subpage blah";
212 $b = "Blah [[TopPage/Subpage|/Subpage]] blah";
213 $x = fixSubPages( $a, $t );
214 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
216 $a = "Blah /subpage blah";
217 $b = $a;
218 $x = fixSubPages( $a, $t );
219 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
221 $a = "Blah [[/Subpage]] blah";
222 $b = "Blah [[TopPage/Subpage|/Subpage]] blah";
223 $x = fixSubPages( $a, $t );
224 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
226 $a = "Blah [[/subpage]] blah";
227 $b = "Blah [[TopPage/Subpage|/subpage]] blah";
228 $x = fixSubPages( $a, $t );
229 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
231 $a = "Blah [[/Subpage|Fizzle]] blah";
232 $b = "Blah [[TopPage/Subpage|Fizzle]] blah";
233 $x = fixSubPages( $a, $t );
234 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
236 $a = "Blah [[/subpage|Fizzle]] blah";
237 $b = "Blah [[TopPage/Subpage|Fizzle]] blah";
238 $x = fixSubPages( $a, $t );
239 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
241 $a = "Blah /\xc9cole blah";
242 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah";
243 $x = fixSubPages( $a, $t );
244 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
246 $a = "Blah /\xe9cole blah";
247 $b = $a;
248 $x = fixSubPages( $a, $t );
249 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
251 $a = "Blah [[/\xc9cole]] blah";
252 $b = "Blah [[TopPage/\xc9cole|/\xc9cole]] blah";
253 $x = fixSubPages( $a, $t );
254 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
256 $a = "Blah [[/\xe9cole]] blah";
257 $b = "Blah [[TopPage/\xe9cole|/\xe9cole]] blah";
258 $x = fixSubPages( $a, $t );
259 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
261 $a = "Blah [[/xe9cole|Fizzle]] blah";
262 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah";
263 $x = fixSubPages( $a, $t );
264 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
266 $a = "Blah [[/subpage|Fizzle]] blah";
267 $b = "Blah [[TopPage/\xe9cole|Fizzle]] blah";
268 $x = fixSubPages( $a, $t );
269 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
270 return passTest( $tn );
274 </body>
275 </html>