2 * Test that basic page editing is working.
5 package com
.piclab
.wikitest
;
7 import com
.meterware
.httpunit
.*;
10 public class EditTest
extends WikiTest
{
12 public String
testName() { return "Editing"; }
14 protected int initTest() throws Exception
{
15 WebResponse wr
= deletePage( "Omaha" );
16 wr
= deletePage( "Math" );
17 /* deletePage will always logout */
21 protected int runTest() throws Exception
{
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
); }
32 private int part1() throws Exception
{
34 * Add a line to some pages. See that the change
35 * shows up in Recent Changes, and the new text appears.
37 WebResponse wr
= addText( "Agriculture",
38 "Edited for testing: 85769476243364759655." );
40 wr
= viewPage( "Special:Recentchanges" );
41 String text
= getArticle( wr
);
42 if ( text
.indexOf( "Agriculture" ) < 0 ) { return 101; }
44 wr
= viewPage( "Agriculture" );
45 text
= getArticle( wr
);
46 if ( text
.indexOf( "85769476243364759655" ) < 0 ) { return 102; }
48 wr
= addText( "Talk:Physics", "Edited for testing: 98762415237651243634" );
49 wr
= addText( "User:Fred", "Edited for testing: 54637465888374655394" );
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; }
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; }
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; }
70 private int part2() throws Exception
{
72 * Create a new page, verify it, add to it, replace it.
74 WebResponse wr
= viewPage( "Omaha" );
75 /* Should have been deleted in initTest() */
77 String text
= getArticle( wr
);
78 if ( text
.indexOf( "no text in this page" ) < 0 ) { return 201; }
80 wr
= addText( "Omaha", "'''Omaha''' is a city in [[Florida]]" );
81 wr
= viewPage( "Omaha" );
82 text
= getArticle( wr
);
84 if ( text
.indexOf( "no text in this page" ) >= 0 ) { return 202; }
85 if ( text
.indexOf( "Florida" ) < 0 ) { return 203; }
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; }
93 wr
= viewPage( "Omaha" );
94 text
= getArticle( wr
);
95 if ( text
.indexOf( "Florida" ) < 0 ) { return 206; }
96 if ( text
.indexOf( "poker" ) < 0 ) { return 207; }
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
);
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; }
114 private int part3() throws Exception
{
116 * Log in and make some edits as a user.
118 WebResponse wr
= loginAs( "Fred", "Fred" );
119 wr
= addText( "Talk:Language", "This page sucks!" );
121 wr
= viewPage( "Special:Recentchanges" );
122 String text
= getArticle( wr
);
123 if ( text
.indexOf( "Fred" ) < 0 ) { return 301; }
125 wr
= loginAs( "Barney", "Barney" );
126 wr
= addText( "Talk:Language", "No it doesn't" );
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; }
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; }
138 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Older versions" );
140 text
= getArticle( wr
);
141 if ( text
.indexOf( "Fred" ) < 0 ) { return 306; }
142 if ( text
.indexOf( "Barney" ) < 0 ) { return 307; }
147 private int part4() throws Exception
{
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.
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
);
161 wr
= fredc
.getResponse( viewUrl( "Dance", "action=edit" ) );
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" );
168 loginAs( "Barney", "Barney" );
169 wr
= addText( "Dance", "\nBarney's edit" );
171 wr
= fredc
.getResponse( req
);
172 String text
= getArticle( wr
);
173 String title
= wr
.getTitle();
175 if ( title
.indexOf( "conflict" ) < 0 ) { return 401; }
176 if ( text
.indexOf( "Your changes are shown" ) < 0 ) { return 402; }
181 private int part5() throws Exception
{
183 * Verify page protection, preview, redirect.
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; }
191 wr
= editPage( "Sociology" );
192 WebForm editform
= getFormByName( wr
, "editform" );
193 WebRequest req
= editform
.getRequest( "wpPreview" );
195 String old
= req
.getParameter( "wpTextbox1" );
196 req
.setParameter( "wpTextbox1", old
+ "\n" + "''Preview test''" );
197 wr
= getResponse( req
);
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; }
203 wr
= replacePage( "Math", "#REDIRECT [[Mathematics]]\n" );
204 wr
= viewPage( "Math" );
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; }
215 public static void main( String
[] params
) {
216 (new EditTest()).runSingle( params
);