Phpdoc comments and place holder. Part of the subpackage "maintenance", archives...
[lhc/web/wiklou.git] / maintenance / archives / importTests.php
1 <?php
2 /**
3 * @deprecated
4 * @package MediaWiki
5 * @subpackage MaintenanceArchive
6 */
7
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();
14
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>
25
26 <?php
27
28 # Unit tests for importUseModWiki
29 # Well, more or less ;)
30
31 $testingonly = true;
32
33 setlocale( LC_ALL, "C" );
34
35 include_once( "importUseModWiki.php" );
36
37 $wgRootDirectory = "./testconvert";
38 runTests();
39
40 function runTests() {
41 $success =
42 testTimestamp()
43 && testRecode()
44 && testFreeToNormal()
45 && testTransformTitle()
46 && testMediaLinks()
47 && testRemoveTalkLink()
48 && testSubPages()
49 ;
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";
54 }
55 return $success;
56 }
57
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;
62 }
63
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;
68 }
69
70 function testTimestamp() {
71 $tn = "Timestamp";
72 $x = wfUnix2Timestamp( 0 );
73 if( $x != "19700101000000" ) {
74 return failTest( $tn, "wfUnix2Timestamp for epoch returned unexpected $x" );
75 }
76
77 $x = wfTimestamp2Unix( "19700101000000" );
78 if( $x != 0 ) {
79 return failTest( $tn, "wfTimestamp2Unix for epoch returned unexpected $x" );
80 }
81
82 return passTest( $tn );
83 }
84
85 function testRecode() {
86 $tn = "Recode";
87
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" );
92
93 $a = "ĉeĥa ŝaŭmmanĝaĵo";
94 $x = recodeInput( $a );
95 if( $a != $x ) return failTest( $tn, "eo test returned different value" );
96
97 return passTest( $tn );
98 }
99
100 function testFreeToNormal() {
101 $tn = "FreeToNormal";
102 $a = "WikiName"; $x = FreeToNormal( $a );
103 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
104
105 $a = "With_Underscore"; $x = FreeToNormal( $a );
106 if( $a != $x ) return failTest( $tn, "$a -> $a != $x" );
107
108 $a = "With Space"; $x = FreeToNormal( $a );
109 if( "With_Space" != $x ) return failTest( $tn, "$a -> With_Space != $x" );
110
111 $a = "Mixed case"; $x = FreeToNormal( $a );
112 if( "Mixed_Case" != $x ) return failTest( $tn, "$a -> Mixed_Case != $x" );
113
114 $a = "\xe9cole"; $x = FreeToNormal( $a );
115 if( $a != $x ) return failTest( $tn, "$a -> $a != $x (must replicate high caps bug)" );
116
117 return passTest( $tn );
118 }
119
120 function testTransformTitle() {
121 global $talkending;
122 $oldtalkending = $talkending;
123 $tn = "TransformTitle";
124
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" );
127
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" );
131
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" );
134
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" );
138
139 $talkending = $oldtalkending;
140 return passTest( $tn );
141 }
142
143 function testMediaLinks() {
144 $tn = "MediaLinks";
145
146 # Fetch
147 $a = "magic.gif";
148 $x = fetchMediaFile( "???", "magic.gif" );
149
150
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" );
156
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" );
161
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" );
167
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" );
172
173 return passTest( $tn );
174 }
175
176 function testRemoveTalkLink() {
177 global $talkending;
178 $tn = "RemoveTalkLink";
179 $oldtalkending = $talkending;
180 $talkending = "Talk";
181
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'" );
186
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'" );
191
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'" );
196
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'" );
202
203 $talkending = $oldtalkending;
204 return passTest( $tn );
205 }
206
207 function testSubPages() {
208 $tn = "SubPages";
209
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'" );
215
216 $a = "Blah /subpage blah";
217 $b = $a;
218 $x = fixSubPages( $a, $t );
219 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
220
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'" );
225
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'" );
230
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'" );
235
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'" );
240
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'" );
245
246 $a = "Blah /\xe9cole blah";
247 $b = $a;
248 $x = fixSubPages( $a, $t );
249 if ( $x != $b ) return failTest( "'$a' -> '$x', should be '$b'" );
250
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'" );
255
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'" );
260
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'" );
265
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 );
271 }
272
273 ?>
274 </body>
275 </html>