Initial revision
[lhc/web/wiklou.git] / testsuite / src / com / piclab / wikitest / EditTest.java
1 /*
2 * Test that basic page editing is working.
3 */
4
5 package com.piclab.wikitest;
6
7 import com.meterware.httpunit.*;
8 import java.io.*;
9
10 public class EditTest extends WikiTest {
11
12 public String testName() { return "Editing"; }
13
14 protected int initTest() throws Exception {
15 WebResponse wr = deletePage( "Omaha" );
16 wr = deletePage( "Math" );
17 /* deletePage will always logout */
18 return 0;
19 }
20
21 protected int runTest() throws Exception {
22 int c = 0;
23
24 if ( 0 != ( c = part1() ) ) { return fail( c ); }
25 if ( 0 != ( c = part2() ) ) { return fail( c ); }
26 if ( 0 != ( c = part3() ) ) { return fail( c ); }
27 if ( 0 != ( c = part4() ) ) { return fail( c ); }
28 if ( 0 != ( c = part5() ) ) { return fail( c ); }
29 return 0;
30 }
31
32 private int part1() throws Exception {
33 /*
34 * Add a line to some pages. See that the change
35 * shows up in Recent Changes, and the new text appears.
36 */
37 WebResponse wr = addText( "Agriculture",
38 "Edited for testing: 85769476243364759655." );
39
40 wr = viewPage( "Special:Recentchanges" );
41 String text = getArticle( wr );
42 if ( text.indexOf( "Agriculture" ) < 0 ) { return 101; }
43
44 wr = viewPage( "Agriculture" );
45 text = getArticle( wr );
46 if ( text.indexOf( "85769476243364759655" ) < 0 ) { return 102; }
47
48 wr = addText( "Talk:Physics", "Edited for testing: 98762415237651243634" );
49 wr = addText( "User:Fred", "Edited for testing: 54637465888374655394" );
50
51 wr = viewPage( "Special:Recentchanges" );
52 text = getArticle( wr );
53 if ( text.indexOf( "Talk:Physics" ) < 0 ) { return 103; }
54 if ( text.indexOf( "User:Fred" ) < 0 ) { return 104; }
55 if ( text.indexOf( "Wikitest addition" ) < 0 ) { return 105; }
56
57 wr = viewPage( "Talk:Physics" );
58 text = getArticle( wr );
59 if ( text.indexOf( "98762415237651243634" ) < 0 ) { return 106; }
60 if ( text.indexOf( "54637465888374655394" ) >= 0 ) { return 107; }
61
62 wr = viewPage( "User:Fred" );
63 text = getArticle( wr );
64 if ( text.indexOf( "54637465888374655394" ) < 0 ) { return 108; }
65 if ( text.indexOf( "98762415237651243634" ) >= 0 ) { return 109; }
66
67 return 0;
68 }
69
70 private int part2() throws Exception {
71 /*
72 * Create a new page, verify it, add to it, replace it.
73 */
74 WebResponse wr = viewPage( "Omaha" );
75 /* Should have been deleted in initTest() */
76
77 String text = getArticle( wr );
78 if ( text.indexOf( "no text in this page" ) < 0 ) { return 201; }
79
80 wr = addText( "Omaha", "'''Omaha''' is a city in [[Florida]]" );
81 wr = viewPage( "Omaha" );
82 text = getArticle( wr );
83
84 if ( text.indexOf( "no text in this page" ) >= 0 ) { return 202; }
85 if ( text.indexOf( "Florida" ) < 0 ) { return 203; }
86
87 wr = addText( "Omaha", "And a [[poker]] game for masochists." );
88 wr = viewPage( "Special:Recentchanges" );
89 text = getArticle( wr );
90 if ( text.indexOf( "Omaha" ) < 0 ) { return 204; }
91 if ( text.indexOf( "Wikitest addition to Omaha" ) < 0 ) { return 205; }
92
93 wr = viewPage( "Omaha" );
94 text = getArticle( wr );
95 if ( text.indexOf( "Florida" ) < 0 ) { return 206; }
96 if ( text.indexOf( "poker" ) < 0 ) { return 207; }
97
98 wr = editPage( "Omaha" );
99 WebForm editform = getFormByName( wr, "editform" );
100 WebRequest req = editform.getRequest( "wpSave" );
101 req.setParameter( "wpTextbox1", "See: \n" +
102 "* [[Omaha, Nebraska]]\n* [[Omaha holdem|Omaha hold'em]]" );
103 wr = getResponse( req );
104
105 text = getArticle( wr );
106 if ( text.indexOf( "Florida" ) >= 0 ) { return 208; }
107 if ( text.indexOf( "poker" ) >= 0 ) { return 209; }
108 if ( text.indexOf( "Nebraska" ) < 0 ) { return 210; }
109 if ( text.indexOf( "holdem" ) < 0 ) { return 211; }
110
111 return 0;
112 }
113
114 private int part3() throws Exception {
115 /*
116 * Log in and make some edits as a user.
117 */
118 WebResponse wr = loginAs( "Fred", "Fred" );
119 wr = addText( "Talk:Language", "This page sucks!" );
120
121 wr = viewPage( "Special:Recentchanges" );
122 String text = getArticle( wr );
123 if ( text.indexOf( "Fred" ) < 0 ) { return 301; }
124
125 wr = loginAs( "Barney", "Barney" );
126 wr = addText( "Talk:Language", "No it doesn't" );
127
128 wr = viewPage( "Special:Recentchanges" );
129 text = getArticle( wr );
130 if ( text.indexOf( "Barney" ) < 0 ) { return 302; }
131 if ( text.indexOf( "Wikitest addition to Talk:Language" ) < 0 ) { return 303; }
132
133 wr = viewPage( "Talk:Language" );
134 text = getArticle( wr );
135 if ( text.indexOf( "sucks" ) < 0 ) { return 304; }
136 if ( text.indexOf( "doesn't" ) < 0 ) { return 305; }
137
138 WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Older versions" );
139 wr = l.click();
140 text = getArticle( wr );
141 if ( text.indexOf( "Fred" ) < 0 ) { return 306; }
142 if ( text.indexOf( "Barney" ) < 0 ) { return 307; }
143
144 return 0;
145 }
146
147 private int part4() throws Exception {
148 /*
149 * Verify edit conflict handling. We have to create a separate
150 * conversation here and handle the forms manually rather than
151 * relying on the WikiSuite stuff.
152 */
153 WebConversation fredc = new WebConversation();
154 WebResponse wr = fredc.getResponse( viewUrl( "Special:Userlogin" ) );
155 WebForm loginform = getFormByName( wr, "userlogin" );
156 WebRequest req = loginform.getRequest( "wpLoginattempt" );
157 req.setParameter( "wpName", "Fred" );
158 req.setParameter( "wpPassword", "Fred" );
159 wr = fredc.getResponse( req );
160
161 wr = fredc.getResponse( viewUrl( "Dance", "action=edit" ) );
162
163 WebForm editform = getFormByName( wr, "editform" );
164 req = editform.getRequest( "wpSave" );
165 String old = req.getParameter( "wpTextbox1" );
166 req.setParameter( "wpTextbox1", old + "\nFred's edit" );
167
168 loginAs( "Barney", "Barney" );
169 wr = addText( "Dance", "\nBarney's edit" );
170
171 wr = fredc.getResponse( req );
172 String text = getArticle( wr );
173 String title = wr.getTitle();
174
175 if ( title.indexOf( "conflict" ) < 0 ) { return 401; }
176 if ( text.indexOf( "Your changes are shown" ) < 0 ) { return 402; }
177
178 return 0;
179 }
180
181 private int part5() throws Exception {
182 /*
183 * Verify page protection, preview, redirect.
184 */
185 WebResponse wr = logout();
186 wr = viewPage( "Wikipedia:Upload_log" );
187 String text = wr.getText();
188 if ( text.indexOf( "Protected page" ) < 0 ) { return 501; }
189 if ( text.indexOf( "Edit this page" ) >= 0 ) { return 502; }
190
191 wr = editPage( "Sociology" );
192 WebForm editform = getFormByName( wr, "editform" );
193 WebRequest req = editform.getRequest( "wpPreview" );
194
195 String old = req.getParameter( "wpTextbox1" );
196 req.setParameter( "wpTextbox1", old + "\n" + "''Preview test''" );
197 wr = getResponse( req );
198
199 text = getArticle( wr );
200 if ( text.indexOf( "<h2>Preview</h2>" ) < 0 ) { return 503; }
201 if ( text.indexOf( "<em>Preview test</em>" ) < 0 ) { return 504; }
202
203 wr = replacePage( "Math", "#REDIRECT [[Mathematics]]\n" );
204 wr = viewPage( "Math" );
205
206 text = wr.getTitle();
207 if ( text.indexOf( "Mathematics" ) < 0 ) { return 505; }
208 text = getArticle( wr );
209 if ( text.indexOf( "(Redirected from" ) < 0 ) { return 506; }
210 if ( text.indexOf( "<strong>Mathematics</strong>" ) < 0 ) { return 507; }
211
212 return 0;
213 }
214
215 public static void main( String[] params ) {
216 (new EditTest()).runSingle( params );
217 }
218
219 }