3 * Test that basic navigation around the wiki with
4 * internal links is working.
7 package com
.piclab
.wikitest
;
9 import com
.meterware
.httpunit
.*;
11 public class LinkTest
extends WikiTest
{
13 public String
testName() { return "Links"; }
15 protected int initTest() throws Exception
{
16 WebResponse wr
= deletePage( "Talk:Poker" ); /* Will logout */
20 protected int runTest() throws Exception
{
23 if ( 0 != ( c
= part1() ) ) { return fail( c
); }
24 if ( 0 != ( c
= part2() ) ) { return fail( c
); }
25 if ( 0 != ( c
= part3() ) ) { return fail( c
); }
26 if ( 0 != ( c
= part4() ) ) { return fail( c
); }
27 if ( 0 != ( c
= part5() ) ) { return fail( c
); }
31 private int part1() throws Exception
{
33 * Check that we can click through from main page to games,
34 * card games, poker, world series.
36 WebResponse wr
= viewPage( "" ); /* Main page */
37 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Game" );
38 if ( l
== null ) { return 101; }
41 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Card" );
42 if ( l
== null ) { return 102; }
45 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Poker" );
46 if ( l
== null ) { return 103; }
49 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "World Series" );
50 if ( l
== null ) { return 104; }
56 private int part2() throws Exception
{
58 * Poker page should have some standard links on it, and should
59 * _not_ have an upload link or user stat links on it because we
62 WebResponse wr
= viewPage( "Poker" );
63 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Printable version" );
64 if ( l
== null ) { return 201; }
65 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Related changes" );
66 if ( l
== null ) { return 202; }
68 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Upload file" );
69 if ( l
!= null ) { return 203; }
70 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "My watchlist" );
71 if ( l
!= null ) { return 204; }
72 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "My contributions" );
73 if ( l
!= null ) { return 205; }
78 private int part3() throws Exception
{
80 * Talk:Poker was not preloaded, so we should be on an edit form
81 * when we click that link from the Poker page. Add a comment,
82 * then check for some standard links on the new talk page and
83 * the resulting history page.
85 WebResponse wr
= viewPage( "Poker" );
86 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Discuss this page" );
87 if ( l
== null ) { return 301; }
90 WebForm editform
= getFormByName( wr
, "editform" );
91 WebRequest req
= editform
.getRequest( "wpSave" );
92 req
.setParameter( "wpTextbox1", "Great article!" );
93 wr
= getResponse( req
);
95 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "View article" );
96 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Page history" );
97 if ( l
== null ) { return 302; }
100 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Current revision" );
101 if ( l
== null ) { return 303; }
102 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "View discussion" );
103 if ( l
== null ) { return 304; }
104 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "View article" );
105 if ( l
== null ) { return 305; }
111 private int part4() throws Exception
{
113 * Let's log in now and verify that things are changed.
115 WebResponse wr
= viewPage( "Poker" );
116 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Log in" );
117 if ( l
== null ) { return 401; }
120 wr
= loginAs( "Fred", "Fred" );
121 wr
= viewPage( "Poker" );
123 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "My watchlist" );
124 if ( l
== null ) { return 402; }
125 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "My contributions" );
126 if ( l
== null ) { return 403; }
127 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "new messages" );
128 if ( l
!= null ) { return 404; }
129 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Upload file" );
130 if ( l
== null ) { return 405; }
133 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "list of uploaded images" );
134 if ( l
== null ) { return 406; }
135 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "upload log" );
136 if ( l
== null ) { return 407; }
141 private int part5() throws Exception
{
143 * Verify that the user page and user talk page are OK.
145 WebResponse wr
= viewPage( "" );
146 WebLink l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Fred" );
147 if ( l
== null ) { return 501; }
150 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "User contributions" );
151 if ( l
== null ) { return 502; }
154 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Talk" );
155 if ( l
== null ) { return 503; }
159 * Log out, clear cookies, edit talk page, then log back in and
160 * verify "new messages" link.
162 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Log out" );
163 if ( l
== null ) { return 504; }
167 wr
= editPage( "User talk:Fred" );
168 WebForm editform
= getFormByName( wr
, "editform" );
169 WebRequest req
= editform
.getRequest( "wpSave" );
170 req
.setParameter( "wpTextbox1", "Wake up!" );
171 wr
= getResponse( req
);
173 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Main Page" );
174 if ( l
== null ) { return 505; }
177 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Log in" );
178 if ( l
== null ) { return 506; }
181 WebForm loginform
= getFormByName( wr
, "userlogin" );
182 req
= loginform
.getRequest( "wpLoginattempt" );
183 req
.setParameter( "wpName", "Fred" );
184 req
.setParameter( "wpPassword", "Fred" );
185 wr
= getResponse( req
);
187 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "new messages" );
188 if ( l
== null ) { return 507; }
191 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "Main Page" );
192 if ( l
== null ) { return 508; }
195 l
= wr
.getFirstMatchingLink( WebLink
.MATCH_CONTAINED_TEXT
, "new messages" );
196 if ( l
!= null ) { return 509; }
201 public static void main( String
[] params
) {
202 (new LinkTest()).runSingle( params
);