Initial revision
[lhc/web/wiklou.git] / testsuite / src / com / piclab / wikitest / SpecialTest.java
1 /*
2 * Test functioning of various special pages. Does not bother with
3 * some pages like Recentchanges and Userlogin that are adequately
4 * exercised by other test, or with developer-only stuff.
5 */
6
7 package com.piclab.wikitest;
8 import com.meterware.httpunit.*;
9 import java.util.regex.*;
10
11 public class SpecialTest extends WikiTest {
12
13 public String testName() { return "Special"; }
14
15 protected int initTest() throws Exception {
16 WebResponse wr = deletePage( "Newly created test page" );
17 wr = deletePage( "Nonsense" );
18 wr = deletePage( "Religion" );
19
20 String text = WikiSuite.loadText( "data/Religion.txt" );
21 wr = replacePage( "Religion", text );
22 return 0;
23 }
24
25 protected int runTest() throws Exception {
26 int c = 0;
27
28 if ( 0 != ( c = part1() ) ) { return fail( c ); }
29 if ( 0 != ( c = part2() ) ) { return fail( c ); }
30 if ( 0 != ( c = part3() ) ) { return fail( c ); }
31 if ( 0 != ( c = part4() ) ) { return fail( c ); }
32 if ( 0 != ( c = part5() ) ) { return fail( c ); }
33 if ( 0 != ( c = part6() ) ) { return fail( c ); }
34 if ( 0 != ( c = part7() ) ) { return fail( c ); }
35 if ( 0 != ( c = part8() ) ) { return fail( c ); }
36 if ( 0 != ( c = part9() ) ) { return fail( c ); }
37 if ( 0 != ( c = part10() ) ) { return fail( c ); }
38 if ( 0 != ( c = part11() ) ) { return fail( c ); }
39 if ( 0 != ( c = part12() ) ) { return fail( c ); }
40 if ( 0 != ( c = part13() ) ) { return fail( c ); }
41 if ( 0 != ( c = part14() ) ) { return fail( c ); }
42 if ( 0 != ( c = part15() ) ) { return fail( c ); }
43 if ( 0 != ( c = part16() ) ) { return fail( c ); }
44 if ( 0 != ( c = part17() ) ) { return fail( c ); }
45 if ( 0 != ( c = part18() ) ) { return fail( c ); }
46 if ( 0 != ( c = part19() ) ) { return fail( c ); }
47 if ( 0 != ( c = part20() ) ) { return fail( c ); }
48 return 0;
49 }
50
51 private String[] listHeadings = {
52 "Showing below.*results starting with",
53 "View \\(previous[^(]*\\(<a\\s[^>]*>next",
54 "\\(<a [^>]*>20</a> | <a [^>]*>50</a> | <a [^>]*>100</a>"
55 };
56
57 private int part1() throws Exception {
58 /*
59 * This one is in the process of changing.
60 */
61 WebResponse wr = viewPage( "Special:Allpages" );
62 return 0;
63 }
64
65 private int part2() throws Exception {
66 WebResponse wr = viewPage( "Special:Booksources", "isbn=0123456789" );
67
68 WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "AddALL" );
69 if ( l == null ) return 201;
70 l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "PriceSCAN" );
71 if ( l == null ) return 202;
72 l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Barnes" );
73 if ( l == null ) return 203;
74 l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Amazon" );
75 if ( l == null ) return 204;
76
77 return 0;
78 }
79
80 private int part3() throws Exception {
81 WebResponse wr = loginAs( "Fred", "Fred" );
82 wr = editPage( "Painting" );
83
84 WebForm editform = getFormByName( wr, "editform" );
85 WebRequest req = editform.getRequest( "wpSave" );
86
87 String old = req.getParameter( "wpTextbox1" );
88 req.setParameter( "wpTextbox1", old + "\n" + "Fred's edit." );
89 req.setParameter( "wpSummary", "Wikitest addition" );
90 wr = getResponse( req );
91
92 wr = viewPage( "Special:Contributions", "target=Fred" );
93 String text = getArticle( wr );
94
95 String[] pats = {
96 "<p\\s[^>]*subtitle[^>]*>\\s*For\\s*<a\\s[^>]*User:Fred[^>]*>\\s*Fred",
97 "<ul>\\s*<li>[^<]*<a\\s[^>]*>Painting</a>\\s*<em>\\s*\\(Wikitest"
98 };
99
100 int ret = 0;
101 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
102 return 300 + ret;
103 }
104 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
105 return 310 + ret;
106 }
107 wr = logout();
108 return 0;
109 }
110
111 private int part4() throws Exception {
112 WebResponse wr = loginAs( "Fred", "Fred" );
113 WebRequest req = openPrefs();
114 req.setParameter( "wpEmail", "fred@nowhere.invalid" );
115 wr = getResponse( req );
116
117 wr = loginAs( "Barney", "Barney" );
118 req = openPrefs();
119 req.setParameter( "wpEmail", "barney@nowhere.invalid" );
120 wr = getResponse( req );
121
122 wr = viewPage( "Special:Emailuser", "target=Fred" );
123 String text = getArticle( wr );
124 WebForm emailform = getFormByName( wr, "emailuser" );
125
126 if ( ! emailform.hasParameterNamed( "wpSubject" ) ) {
127 return 401;
128 }
129 /*
130 * Actual addresses should not appear on form anywhere
131 */
132 String[] badpats = {
133 "fred@nowhere.invalid", "barney@nowhere.invalid"
134 };
135 int ret = 0;
136 if ( 0 != ( ret = checkBadPatterns( text, badpats ) ) ) {
137 return 401 + ret;
138 }
139 wr = logout();
140 return 0;
141 }
142
143 private int part5() throws Exception {
144 WebResponse wr = viewPage( "Special:Listusers" );
145 String text = getArticle( wr );
146
147 String[] pats = {
148 "<ol [^>]*start[^>]*>\\s*<li>\\s*<a [^>]*User:([^ ]+)[^>]*>\\s*\\1"
149 };
150
151 int ret = 0;
152 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
153 return 500 + ret;
154 }
155 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
156 return 510 + ret;
157 }
158 return 0;
159 }
160
161 private int part6() throws Exception {
162 WebResponse wr = viewPage( "Special:Lonelypages" );
163 String text = getArticle( wr );
164
165 String[] pats = {
166 "<ol [^>]*start[^>]*>\\s*<li>\\s*<a [^>]*\\?title=([^ ]+)[^>]*>\\s*\\1"
167 };
168
169 int ret = 0;
170 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
171 return 600 + ret;
172 }
173 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
174 return 610 + ret;
175 }
176 return 0;
177 }
178
179 private int part7() throws Exception {
180 WebResponse wr = viewPage( "Special:Longpages" );
181 String text = getArticle( wr );
182
183 String[] pats = {
184 "<ol [^>]*start[^>]*>\\s*<li>\\s*<a [^>]*\\?title=([^\"])[^\"]*\"[^>]*>" +
185 "\\s*\\1[^<]*</a>\\s*\\(\\d+\\s+bytes\\)"
186 };
187
188 int ret = 0;
189 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
190 return 600 + ret;
191 }
192 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
193 return 610 + ret;
194 }
195 return 0;
196 }
197
198 private int part8() throws Exception {
199 WebResponse wr = loginAs( "Fred", "Fred" );
200 wr = viewPage( "Religion" );
201 String text = getArticle( wr );
202
203 if ( text.indexOf( "<strong>religion</strong>" ) < 0 ) {
204 return 801;
205 }
206 wr = viewPage( "Special:Movepage", "target=Religion" );
207 text = getArticle( wr );
208 if ( text.indexOf( "WARNING" ) < 0 ) { return 802; }
209
210 WebForm moveform = getFormByName( wr, "movepage" );
211 WebRequest req = moveform.getRequest( "wpMove" );
212 req.setParameter( "wpNewTitle", "Nonsense" );
213 wr = getResponse( req );
214
215 text = getArticle( wr );
216 if ( text.indexOf( ">Religion<" ) < 0 ||
217 text.indexOf( "moved to" ) < 0 ||
218 text.indexOf( ">Nonsense<" ) < 0 ) {
219 return 803;
220 }
221 wr = viewPage( "Nonsense" );
222 text = getArticle( wr );
223 if ( text.indexOf( "<strong>religion</strong>" ) < 0 ) {
224 return 804;
225 }
226 wr = viewPage( "Religion" );
227 text = getArticle( wr );
228 if ( text.indexOf( "<strong>religion</strong>" ) < 0 ||
229 text.indexOf( "(Redirected from" ) < 0 ) {
230 return 805;
231 }
232 wr = viewPage( "Religion", "action=edit&redirect=no" );
233 text = getArticle( wr );
234 if ( text.indexOf( "#REDIRECT [[Nonsense]]" ) < 0 ) {
235 return 806;
236 }
237 wr = logout();
238 return 0;
239 }
240
241 private int part9() throws Exception {
242 /*
243 * Not yet implemented
244 *
245 WebResponse wr = viewPage( "Special:Neglectedpages" );
246 */
247
248 return 0;
249 }
250
251 private int part10() throws Exception {
252 WebResponse wr = loginAs( "Barney", "Barney" );
253 wr = addText( "Newly created test page", "New stuff..." );
254
255 wr = viewPage( "Special:Newpages" );
256 String text = getArticle( wr );
257
258 String[] pats = {
259 "<ol [^>]*start[^>]*>\\s*<li>\\s*\\d\\d:\\d\\d[^<]*<a [^>]*>Newly" +
260 "[^<]*</a> \\. \\. <a [^>]*>Barney</a>"
261 };
262
263 int ret = 0;
264 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
265 return 1000 + ret;
266 }
267 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
268 return 1010 + ret;
269 }
270 return 0;
271 }
272
273 private int part11() throws Exception {
274 WebResponse wr = viewPage( "Special:Popularpages" );
275 String text = getArticle( wr );
276
277 String[] pats = {
278 "<ol [^>]*start[^>]*>\\s*<li>\\s*<a [^>]*\\?title=([^\"])[^\"]*\"[^>]*>" +
279 "\\s*\\1[^<]*</a>\\s*\\(\\d+\\s+views\\)"
280 };
281
282 int ret = 0;
283 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
284 return 1100 + ret;
285 }
286 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
287 return 1110 + ret;
288 }
289 return 0;
290 }
291
292 private int part12() throws Exception {
293 WebResponse wr = viewPage( "Special:Randompage" );
294 return 0;
295 }
296
297 private int part13() throws Exception {
298 /* WebResponse wr = viewPage( "Special:Recentchangeslinked" ); */
299 return 0;
300 }
301
302 private int part14() throws Exception {
303 WebResponse wr = viewPage( "Special:Shortpages" );
304 String text = getArticle( wr );
305
306 String[] pats = {
307 "<ol [^>]*start[^>]*>\\s*<li>\\s*<a [^>]*\\?title=([^\"])[^\"]*\"[^>]*>" +
308 "\\s*\\1[^<]*</a>\\s*\\(\\d+\\s+bytes\\)"
309 };
310
311 int ret = 0;
312 if ( 0 != ( ret = checkGoodPatterns( text, pats ) ) ) {
313 return 1400 + ret;
314 }
315 if ( 0 != ( ret = checkGoodPatterns( text, listHeadings ) ) ) {
316 return 1410 + ret;
317 }
318 return 0;
319 }
320
321 private int part15() throws Exception {
322 viewPage( "Special:Specialpages" );
323 return 0;
324 }
325
326 private int part16() throws Exception {
327 WebResponse wr = viewPage( "Special:Statistics" );
328 String text = getArticle( wr );
329 return 0;
330 }
331
332 private int part17() throws Exception {
333 WebResponse wr = viewPage( "Special:Unusedimages" );
334 String text = getArticle( wr );
335 return 0;
336 }
337
338 private int part18() throws Exception {
339 WebResponse wr = viewPage( "Special:Wantedpages" );
340 String text = getArticle( wr );
341 return 0;
342 }
343
344 private int part19() throws Exception {
345 /* WebResponse wr = viewPage( "Special:Watchlist" ); */
346 return 0;
347 }
348
349 private int part20() throws Exception {
350 /* WebResponse wr = viewPage( "Special:Whatlinkshere" ); */
351 return 0;
352 }
353
354 public static void main( String[] params ) {
355 (new SpecialTest()).runSingle( params );
356 }
357
358 }