Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/EditTest.java |
— | — | @@ -15,43 +15,172 @@ |
16 | 16 | public String testName() { return "Editing"; } |
17 | 17 | |
18 | 18 | protected boolean runTest() throws Exception { |
| 19 | + m_suite.clearCookies(); |
| 20 | + if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
| 21 | + if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
| 22 | + if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); } |
| 23 | + if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); } |
| 24 | + if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); } |
| 25 | + |
| 26 | + return true; |
| 27 | +} |
| 28 | + |
| 29 | +private boolean part1() throws Exception { |
| 30 | + /* |
| 31 | + * Add a line to some pages. See that the change |
| 32 | + * shows up in Recent Changes, and the new text appears. |
| 33 | + */ |
19 | 34 | boolean result = true; |
20 | 35 | |
21 | | - WebResponse wr = m_suite.editPage( "Agriculture" ); |
22 | | - WebForm editform = null; |
23 | | - WebRequest req = null; |
| 36 | + WebResponse wr = addText( "Agriculture", |
| 37 | + "Edited for testing: 85769476243364759655." ); |
24 | 38 | |
25 | | - editform = WikiSuite.getFormByName( wr, "editform" ); |
26 | | - req = editform.getRequest( "wpSave" ); |
27 | | - String text = req.getParameter( "wpTextbox1" ); |
28 | | - req.setParameter( "wpTextbox1", text + "\nEdited for testing." ); |
29 | | - wr = m_suite.getResponse( req ); |
| 39 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 40 | + String text = wr.getText(); |
| 41 | + if ( text.indexOf( "Agriculture" ) < 0 ) { result = false; } |
30 | 42 | |
| 43 | + wr = m_suite.viewPage( "Agriculture" ); |
| 44 | + text = wr.getText(); |
| 45 | + if ( text.indexOf( "85769476243364759655" ) < 0 ) { result = false; } |
| 46 | + |
| 47 | + wr = addText( "Physics", "Edited for testing: 98762415237651243634" ); |
| 48 | + wr = addText( "Mathematics", "Edited for testing: 54637465888374655394" ); |
| 49 | + |
31 | 50 | wr = m_suite.viewPage( "Special:Recentchanges" ); |
32 | 51 | text = wr.getText(); |
33 | | - if ( text.indexOf( "Agriculture" ) < 0 ) { result = false; } |
| 52 | + if ( text.indexOf( "Physics" ) < 0 ) { result = false; } |
| 53 | + if ( text.indexOf( "Mathematics" ) < 0 ) { result = false; } |
34 | 54 | |
35 | | - wr = m_suite.viewPage( "Omaha" ); /* Not preloaded */ |
| 55 | + wr = m_suite.viewPage( "Physics" ); |
36 | 56 | text = wr.getText(); |
| 57 | + if ( text.indexOf( "98762415237651243634" ) < 0 ) { result = false; } |
| 58 | + if ( text.indexOf( "54637465888374655394" ) >= 0 ) { result = false; } |
| 59 | + |
| 60 | + wr = m_suite.viewPage( "Mathematics" ); |
| 61 | + text = wr.getText(); |
| 62 | + if ( text.indexOf( "54637465888374655394" ) < 0 ) { result = false; } |
| 63 | + if ( text.indexOf( "98762415237651243634" ) >= 0 ) { result = false; } |
| 64 | + |
| 65 | + return result; |
| 66 | +} |
| 67 | + |
| 68 | +private boolean part2() throws Exception { |
| 69 | + /* |
| 70 | + * Create a new page, verify it, add to it, replace it. |
| 71 | + */ |
| 72 | + boolean result = true; |
| 73 | + |
| 74 | + WebResponse wr = m_suite.viewPage( "Omaha" ); /* Not preloaded */ |
| 75 | + String text = wr.getText(); |
37 | 76 | if ( text.indexOf( "no text in this page" ) < 0 ) { result = false; } |
38 | 77 | |
39 | | - WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, |
40 | | - "Edit this page" ); |
41 | | - wr = l.click(); |
| 78 | + wr = addText( "Omaha", "'''Omaha''' is a city in [[Florida]]" ); |
| 79 | + wr = m_suite.viewPage( "Omaha" ); |
| 80 | + text = wr.getText(); |
42 | 81 | |
43 | | - editform = WikiSuite.getFormByName( wr, "editform" ); |
44 | | - req = editform.getRequest( "wpSave" ); |
45 | | - req.setParameter( "wpTextbox1", "'''Omaha''' is a city in [[Nebraska]]" ); |
46 | | - wr = m_suite.getResponse( req ); |
| 82 | + if ( text.indexOf( "no text in this page" ) >= 0 ) { result = false; } |
| 83 | + if ( text.indexOf( "Florida" ) < 0 ) { result = false; } |
47 | 84 | |
| 85 | + wr = addText( "Omaha", "And a [[poker]] game for masochists." ); |
| 86 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 87 | + text = wr.getText(); |
| 88 | + if ( text.indexOf( "Omaha" ) < 0 ) { result = false; } |
| 89 | + |
48 | 90 | wr = m_suite.viewPage( "Omaha" ); |
49 | 91 | text = wr.getText(); |
50 | | - if ( text.indexOf( "no text in this page" ) >= 0 ) { result = false; } |
| 92 | + if ( text.indexOf( "Florida" ) < 0 ) { result = false; } |
| 93 | + if ( text.indexOf( "poker" ) < 0 ) { result = false; } |
| 94 | + |
| 95 | + wr = m_suite.editPage( "Omaha" ); |
| 96 | + WebForm editform = WikiSuite.getFormByName( wr, "editform" ); |
| 97 | + WebRequest req = editform.getRequest( "wpSave" ); |
| 98 | + req.setParameter( "wpTextbox1", "See: \n" + |
| 99 | + "* [[Omaha, Nebraska]]\n* [[Omaha holdem|Omaha hold'em]]" ); |
| 100 | + wr = m_suite.getResponse( req ); |
| 101 | + |
| 102 | + text = wr.getText(); |
| 103 | + if ( text.indexOf( "Florida" ) >= 0 ) { result = false; } |
| 104 | + if ( text.indexOf( "poker" ) >= 0 ) { result = false; } |
51 | 105 | if ( text.indexOf( "Nebraska" ) < 0 ) { result = false; } |
| 106 | + if ( text.indexOf( "holdem" ) < 0 ) { result = false; } |
52 | 107 | |
53 | 108 | return result; |
54 | 109 | } |
55 | 110 | |
| 111 | +private boolean part3() throws Exception { |
| 112 | + /* |
| 113 | + * Log in and make some edits as a user. |
| 114 | + */ |
| 115 | + boolean result = true; |
| 116 | + |
| 117 | + WebResponse wr = m_suite.loginAs( "Fred", "Fred" ); |
| 118 | + wr = addText( "Talk:Language", "This page sucks!" ); |
| 119 | + |
| 120 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 121 | + String text = wr.getText(); |
| 122 | + if ( text.indexOf( "Fred" ) < 0 ) { result = false; } |
| 123 | + |
| 124 | + wr = m_suite.loginAs( "Barney", "Barney" ); |
| 125 | + wr = addText( "Talk:Language", "No it doesn't" ); |
| 126 | + |
| 127 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 128 | + text = wr.getText(); |
| 129 | + if ( text.indexOf( "Barney" ) < 0 ) { result = false; } |
| 130 | + |
| 131 | + wr = m_suite.viewPage( "Talk:Language" ); |
| 132 | + text = wr.getText(); |
| 133 | + if ( text.indexOf( "sucks" ) < 0 ) { result = false; } |
| 134 | + if ( text.indexOf( "doesn't" ) < 0 ) { result = false; } |
| 135 | + |
| 136 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Older versions" ); |
| 137 | + wr = l.click(); |
| 138 | + text = wr.getText(); |
| 139 | + if ( text.indexOf( "Fred" ) < 0 ) { result = false; } |
| 140 | + if ( text.indexOf( "Barney" ) < 0 ) { result = false; } |
| 141 | + |
| 142 | + return result; |
| 143 | +} |
| 144 | + |
| 145 | +private boolean part4() throws Exception { |
| 146 | + /* |
| 147 | + * Verify edit conflict handling. |
| 148 | + */ |
| 149 | + boolean result = true; |
| 150 | + |
| 151 | + return result; |
| 152 | +} |
| 153 | + |
| 154 | +private boolean part5() throws Exception { |
| 155 | + /* |
| 156 | + * Verify page protection features. |
| 157 | + */ |
| 158 | + boolean result = true; |
| 159 | + |
| 160 | + WebResponse wr = m_suite.viewPage( "Wikipedia:Upload_log" ); |
| 161 | + String text = wr.getText(); |
| 162 | + if ( text.indexOf( "Protected page" ) < 0 ) { result = false; } |
| 163 | + if ( text.indexOf( "Edit this page" ) >= 0 ) { result = false; } |
| 164 | + |
| 165 | + return result; |
| 166 | +} |
| 167 | + |
| 168 | +/* |
| 169 | + * Add a given piece of text to the given page |
| 170 | + */ |
| 171 | + |
| 172 | +private WebResponse addText( String page, String text ) |
| 173 | +throws Exception { |
| 174 | + WebResponse wr = m_suite.editPage( page ); |
| 175 | + |
| 176 | + WebForm editform = WikiSuite.getFormByName( wr, "editform" ); |
| 177 | + WebRequest req = editform.getRequest( "wpSave" ); |
| 178 | + String old = req.getParameter( "wpTextbox1" ); |
| 179 | + req.setParameter( "wpTextbox1", old + "\n" + text ); |
| 180 | + |
| 181 | + return m_suite.getResponse( req ); |
| 182 | +} |
| 183 | + |
| 184 | + |
56 | 185 | public static void main( String[] params ) { |
57 | 186 | WikiSuite ws = new WikiSuite(); |
58 | 187 | EditTest wt = new EditTest( ws ); |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/WikiFetchThread.java |
— | — | @@ -22,24 +22,33 @@ |
23 | 23 | public void run() { |
24 | 24 | int index = 0; |
25 | 25 | |
26 | | - WikiSuite.fine( "Started background page-fetch thread." ); |
| 26 | + WikiSuite.info( "Started background page-fetch thread." ); |
27 | 27 | m_running = true; |
28 | 28 | |
| 29 | + String url; |
| 30 | + double r; |
| 31 | + |
29 | 32 | while ( m_suite.stillRunning() ) { |
30 | | - String url = WikiSuite.editUrl( WikiSuite.preloadedPages[index] ); |
| 33 | + r = Math.random(); |
| 34 | + if ( r < 0.1 ) { |
| 35 | + url = WikiSuite.viewUrl( "" ); /* Main page */ |
| 36 | + } else if ( r < 0.15 ) { |
| 37 | + url = WikiSuite.viewUrl( "Special:Recentchanges" ); |
| 38 | + } else { |
| 39 | + if ( ++index >= WikiSuite.preloadedPages.length ) { index = 0; } |
| 40 | + url = WikiSuite.editUrl( WikiSuite.preloadedPages[index] ); |
| 41 | + } |
31 | 42 | try { |
32 | 43 | WebResponse wr = m_conv.getResponse( url ); |
33 | 44 | } catch (Exception e) { |
34 | | - WikiSuite.warning( "Error (" + e + ") fetching \"" + |
35 | | - WikiSuite.preloadedPages[index] + "\"" ); |
| 45 | + WikiSuite.warning( "Error (" + e + ") fetching \"" + url + "\"" ); |
36 | 46 | } |
37 | | - |
38 | | - WikiSuite.fine( "Fetched \"" + WikiSuite.preloadedPages[index] + "\"" ); |
39 | | - if ( ++index >= WikiSuite.preloadedPages.length ) { index = 0; } |
| 47 | + WikiSuite.fine( "Fetched \"" + url + "\"" ); |
| 48 | + m_suite.incrementFetchcount(); |
40 | 49 | } |
41 | 50 | m_running = false; |
42 | 51 | |
43 | | - WikiSuite.fine( "Terminated background page-fetch thread." ); |
| 52 | + WikiSuite.info( "Terminated background page-fetch thread." ); |
44 | 53 | } |
45 | 54 | |
46 | 55 | |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/Test.template |
— | — | @@ -0,0 +1,42 @@ |
| 2 | + |
| 3 | +/* |
| 4 | + * Template for adding new tests. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.piclab.wikitest; |
| 8 | + |
| 9 | +import com.meterware.httpunit.*; |
| 10 | + |
| 11 | +public class FooTest extends WikiTest { |
| 12 | + |
| 13 | +public FooTest( WikiSuite ws ) { super(ws); } |
| 14 | + |
| 15 | +public String testName() { return "Foo"; } |
| 16 | + |
| 17 | +protected boolean runTest() throws Exception { |
| 18 | + m_suite.clearCookies(); |
| 19 | + if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
| 20 | + if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
| 21 | + |
| 22 | + return true; |
| 23 | +} |
| 24 | + |
| 25 | +private boolean part1() throws Exception { |
| 26 | + boolean result = true; |
| 27 | + |
| 28 | + return result; |
| 29 | +} |
| 30 | + |
| 31 | +private boolean part2() throws Exception { |
| 32 | + boolean result = true; |
| 33 | + |
| 34 | + return result; |
| 35 | +} |
| 36 | + |
| 37 | +public static void main( String[] params ) { |
| 38 | + WikiSuite ws = new WikiSuite(); |
| 39 | + FooTest wt = new FooTest( ws ); |
| 40 | + wt.run(); |
| 41 | +} |
| 42 | + |
| 43 | +} |
Property changes on: trunk/phpwiki/testsuite/src/com/piclab/wikitest/Test.template |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 44 | + native |
Added: svn:keywords |
2 | 45 | + Author Date Id Revision |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/LinkTest.java |
— | — | @@ -15,27 +15,183 @@ |
16 | 16 | public String testName() { return "Links"; } |
17 | 17 | |
18 | 18 | protected boolean runTest() throws Exception { |
19 | | - boolean result = true; |
| 19 | + m_suite.clearCookies(); /* Make sure we aren't logged in */ |
| 20 | + |
| 21 | + if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
| 22 | + if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
| 23 | + if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); } |
| 24 | + if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); } |
| 25 | + if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); } |
| 26 | + |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +private boolean part1() throws Exception { |
| 31 | + /* |
| 32 | + * Check that we can click through from main page to games, |
| 33 | + * card games, poker, world series. |
| 34 | + */ |
20 | 35 | WebResponse wr = m_suite.viewPage( "" ); /* Main page */ |
| 36 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Game" ); |
| 37 | + wr = l.click(); |
| 38 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Card" ); |
| 39 | + wr = l.click(); |
| 40 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Poker" ); |
| 41 | + wr = l.click(); |
| 42 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "World Series" ); |
| 43 | + wr = l.click(); |
21 | 44 | |
22 | | - WebLink l = wr.getFirstMatchingLink( |
23 | | - WebLink.MATCH_CONTAINED_TEXT, "game" ); |
| 45 | + return true; |
| 46 | +} |
| 47 | + |
| 48 | +private boolean part2() throws Exception { |
| 49 | + /* |
| 50 | + * Poker page should have some standard links on it, and should |
| 51 | + * _not_ have an upload link or user stat links on it because we |
| 52 | + * aren't logged in. |
| 53 | + */ |
| 54 | + boolean result = true; |
| 55 | + |
| 56 | + WebResponse wr = m_suite.viewPage( "Poker" ); |
| 57 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Printable version" ); |
| 58 | + result = (l != null); |
| 59 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Related changes" ); |
| 60 | + result = (l != null); |
| 61 | + |
| 62 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Upload file" ); |
| 63 | + result = (l == null); |
| 64 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "My watchlist" ); |
| 65 | + result = (l == null); |
| 66 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "My contributions" ); |
| 67 | + result = (l == null); |
| 68 | + |
| 69 | + return result; |
| 70 | +} |
| 71 | + |
| 72 | +private boolean part3() throws Exception { |
| 73 | + /* |
| 74 | + * Talk:Poker was not preloaded, so we should be on an edit form |
| 75 | + * when we click that link from the Poker page. Add a comment, |
| 76 | + * then check for some standard links on the new talk page and |
| 77 | + * the resulting history page. |
| 78 | + */ |
| 79 | + boolean result = true; |
| 80 | + |
| 81 | + WebResponse wr = m_suite.viewPage( "Poker" ); |
| 82 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Discuss this page" ); |
24 | 83 | wr = l.click(); |
25 | | - WikiSuite.showResponseTitle( wr ); |
26 | 84 | |
27 | | - l = wr.getFirstMatchingLink( |
28 | | - WebLink.MATCH_CONTAINED_TEXT, "card" ); |
| 85 | + WebForm editform = WikiSuite.getFormByName( wr, "editform" ); |
| 86 | + WebRequest req = editform.getRequest( "wpSave" ); |
| 87 | + req.setParameter( "wpTextbox1", "Great article!" ); |
| 88 | + wr = m_suite.getResponse( req ); |
| 89 | + |
| 90 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "View article" ); |
| 91 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Older versions" ); |
29 | 92 | wr = l.click(); |
30 | | - WikiSuite.showResponseTitle( wr ); |
31 | 93 | |
32 | | - l = wr.getFirstMatchingLink( |
33 | | - WebLink.MATCH_CONTAINED_TEXT, "poker" ); |
| 94 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Current revision" ); |
| 95 | + result = (l != null); |
| 96 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "View discussion" ); |
| 97 | + result = (l != null); |
| 98 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "View article" ); |
34 | 99 | wr = l.click(); |
35 | | - WikiSuite.showResponseTitle( wr ); |
36 | 100 | |
37 | 101 | return result; |
38 | 102 | } |
39 | 103 | |
| 104 | +private boolean part4() throws Exception { |
| 105 | + /* |
| 106 | + * Let's log in now and verify that things are changed. |
| 107 | + */ |
| 108 | + boolean result = true; |
| 109 | + |
| 110 | + WebResponse wr = m_suite.viewPage( "Poker" ); |
| 111 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Log in" ); |
| 112 | + wr = l.click(); |
| 113 | + |
| 114 | + WebForm loginform = WikiSuite.getFormByName( wr, "userlogin" ); |
| 115 | + WebRequest req = loginform.getRequest( "wpLoginattempt" ); |
| 116 | + req.setParameter( "wpName", "Fred" ); |
| 117 | + req.setParameter( "wpPassword", "Fred" ); |
| 118 | + wr = m_suite.getResponse( req ); |
| 119 | + |
| 120 | + String text = wr.getText(); |
| 121 | + if ( text.indexOf( "successful" ) < 0 ) { throw new |
| 122 | + WikiSuiteFailureException( "Could not log in" ); } |
| 123 | + |
| 124 | + /* |
| 125 | + * Should have a "return to" link. |
| 126 | + */ |
| 127 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Poker" ); |
| 128 | + wr = l.click(); |
| 129 | + |
| 130 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "My watchlist" ); |
| 131 | + result = (l != null); |
| 132 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "My contributions" ); |
| 133 | + result = (l != null); |
| 134 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "new messages" ); |
| 135 | + result = (l == null); |
| 136 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Upload file" ); |
| 137 | + wr = l.click(); |
| 138 | + |
| 139 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "list of uploaded images" ); |
| 140 | + result = (l != null); |
| 141 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "upload log" ); |
| 142 | + result = (l != null); |
| 143 | + |
| 144 | + return result; |
| 145 | +} |
| 146 | + |
| 147 | +private boolean part5() throws Exception { |
| 148 | + /* |
| 149 | + * Verify that the user page and user talk page are OK. |
| 150 | + */ |
| 151 | + boolean result = true; |
| 152 | + |
| 153 | + WebResponse wr = m_suite.viewPage( "" ); |
| 154 | + WebLink l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Fred" ); |
| 155 | + wr = l.click(); |
| 156 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "User contributions" ); |
| 157 | + wr = l.click(); |
| 158 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Talk" ); |
| 159 | + wr = l.click(); |
| 160 | + |
| 161 | + /* |
| 162 | + * Log out, clear cookies, edit talk page, then log back in and |
| 163 | + * verify "new messages" link. |
| 164 | + */ |
| 165 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Log out" ); |
| 166 | + wr = l.click(); |
| 167 | + m_suite.clearCookies(); |
| 168 | + |
| 169 | + wr = m_suite.editPage( "User talk:Fred" ); |
| 170 | + WebForm editform = WikiSuite.getFormByName( wr, "editform" ); |
| 171 | + WebRequest req = editform.getRequest( "wpSave" ); |
| 172 | + req.setParameter( "wpTextbox1", "Wake up!" ); |
| 173 | + wr = m_suite.getResponse( req ); |
| 174 | + |
| 175 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Main Page" ); |
| 176 | + wr = l.click(); |
| 177 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Log in" ); |
| 178 | + wr = l.click(); |
| 179 | + |
| 180 | + WebForm loginform = WikiSuite.getFormByName( wr, "userlogin" ); |
| 181 | + req = loginform.getRequest( "wpLoginattempt" ); |
| 182 | + req.setParameter( "wpName", "Fred" ); |
| 183 | + req.setParameter( "wpPassword", "Fred" ); |
| 184 | + wr = m_suite.getResponse( req ); |
| 185 | + |
| 186 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "new messages" ); |
| 187 | + wr = l.click(); |
| 188 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "Main Page" ); |
| 189 | + wr = l.click(); |
| 190 | + l = wr.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "new messages" ); |
| 191 | + result = (l == null); |
| 192 | + |
| 193 | + return result; |
| 194 | +} |
| 195 | + |
40 | 196 | public static void main( String[] params ) { |
41 | 197 | WikiSuite ws = new WikiSuite(); |
42 | 198 | LinkTest wt = new LinkTest( ws ); |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/WikiSuite.java |
— | — | @@ -87,6 +87,30 @@ |
88 | 88 | m_conv = new WebConversation(); |
89 | 89 | } |
90 | 90 | |
| 91 | +public void clearCookies() { |
| 92 | + m_conv.clearContents(); |
| 93 | +} |
| 94 | + |
| 95 | +public WebResponse loginAs( String name, String password ) |
| 96 | +throws WikiSuiteFailureException { |
| 97 | + WebResponse wr = null; |
| 98 | + WebRequest req = null; |
| 99 | + |
| 100 | + try { |
| 101 | + wr = viewPage( "Special:Userlogin" ); |
| 102 | + |
| 103 | + WebForm loginform = WikiSuite.getFormByName( wr, "userlogin" ); |
| 104 | + req = loginform.getRequest( "wpLoginattempt" ); |
| 105 | + req.setParameter( "wpName", name ); |
| 106 | + req.setParameter( "wpPassword", password ); |
| 107 | + wr = getResponse( req ); |
| 108 | + } catch (org.xml.sax.SAXException e) { |
| 109 | + throw new WikiSuiteFailureException( "Exception (" + e + |
| 110 | + ") parsing login form." ); |
| 111 | + } |
| 112 | + return wr; |
| 113 | +} |
| 114 | + |
91 | 115 | /* Utility routine to munge page titles into URL form. |
92 | 116 | * Should match the ruotines used by the wiki itself. |
93 | 117 | */ |
— | — | @@ -166,6 +190,7 @@ |
167 | 191 | |
168 | 192 | public static void fine( String msg ) { |
169 | 193 | ms_logger.fine( msg ); |
| 194 | + ms_logger.getHandlers()[0].flush(); |
170 | 195 | } |
171 | 196 | |
172 | 197 | /* |
— | — | @@ -328,11 +353,10 @@ |
329 | 354 | */ |
330 | 355 | private void initializeDatabase() { |
331 | 356 | |
332 | | - WebResponse wr; |
| 357 | + WebResponse wr = null; |
333 | 358 | |
334 | | - fine( "Preloading database with test pages." ); |
| 359 | + info( "Preloading database with test pages." ); |
335 | 360 | for (int i = 0; i < preloadedPages.length; ++i) { |
336 | | - wr = null; |
337 | 361 | try { |
338 | 362 | wr = loadPageFromFile( preloadedPages[i] ); |
339 | 363 | } catch (WikiSuiteFailureException e) { |
— | — | @@ -342,6 +366,27 @@ |
343 | 367 | fine( "Loaded \"" + preloadedPages[i] + "\"" ); |
344 | 368 | } |
345 | 369 | } |
| 370 | + info( "Creating test users." ); |
| 371 | + try { |
| 372 | + wr = viewPage( "Special:Userlogin" ); |
| 373 | + WebForm loginform = WikiSuite.getFormByName( wr, "userlogin" ); |
| 374 | + WebRequest req = loginform.getRequest( "wpCreateaccount" ); |
| 375 | + req.setParameter( "wpName", "Fred" ); |
| 376 | + req.setParameter( "wpPassword", "Fred" ); |
| 377 | + req.setParameter( "wpRetype", "Fred" ); |
| 378 | + wr = getResponse( req ); |
| 379 | + |
| 380 | + wr = viewPage( "Special:Userlogin" ); |
| 381 | + loginform = WikiSuite.getFormByName( wr, "userlogin" ); |
| 382 | + req = loginform.getRequest( "wpCreateaccount" ); |
| 383 | + req.setParameter( "wpName", "Barney" ); |
| 384 | + req.setParameter( "wpPassword", "Barney" ); |
| 385 | + req.setParameter( "wpRetype", "Barney" ); |
| 386 | + wr = getResponse( req ); |
| 387 | + } catch (org.xml.sax.SAXException e) { |
| 388 | + error( "Exception (" + e + ") parsing login form." ); |
| 389 | + } |
| 390 | + clearCookies(); |
346 | 391 | } |
347 | 392 | |
348 | 393 | /* |
— | — | @@ -352,6 +397,7 @@ |
353 | 398 | |
354 | 399 | private boolean m_stillrunning = false; |
355 | 400 | private WikiFetchThread m_wft; |
| 401 | +private int m_fetchcount = 0; |
356 | 402 | |
357 | 403 | private void startBackgroundFetchThread() { |
358 | 404 | m_stillrunning = true; |
— | — | @@ -368,6 +414,10 @@ |
369 | 415 | return m_stillrunning; |
370 | 416 | } |
371 | 417 | |
| 418 | +public void incrementFetchcount() { |
| 419 | + ++m_fetchcount; |
| 420 | +} |
| 421 | + |
372 | 422 | /* |
373 | 423 | * Main suite starts here. Interpret command line, load the |
374 | 424 | * database, then run the individual tests. |
— | — | @@ -406,6 +456,7 @@ |
407 | 457 | sb.append( "Total elapsed time: " ).append( t_hr ).append( " hr, " ) |
408 | 458 | .append( t_min ).append( " min, " ).append( t_sec ).append( " sec." ); |
409 | 459 | info( sb.toString() ); |
| 460 | + info( "Total background page fetches: " + ws.m_fetchcount ); |
410 | 461 | } |
411 | 462 | |
412 | 463 | |