Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/HTMLTest.java |
— | — | @@ -0,0 +1,177 @@ |
| 2 | + |
| 3 | +/* |
| 4 | + * View pages with various skins and make sure they're basically |
| 5 | + * valid HTML structured the way we expect. For now we're just |
| 6 | + * using regexes, which should be fine for the sample pages. They |
| 7 | + * would probably fail on pages about HTML markup and such, though. |
| 8 | + * Eventualy, we should be scanning the DOM for these tests. |
| 9 | + */ |
| 10 | + |
| 11 | +package com.piclab.wikitest; |
| 12 | + |
| 13 | +import com.meterware.httpunit.*; |
| 14 | +import java.util.regex.*; |
| 15 | +import org.w3c.dom.*; |
| 16 | + |
| 17 | +public class HTMLTest extends WikiTest { |
| 18 | + |
| 19 | +private String[] m_goodpats = { |
| 20 | + "\\A\\s*<!doctype html", "<meta\\s+[^>]*name\\s*=\\s*.robots", |
| 21 | + "<link\\s+[^>]*rel\\s*=\\s*.stylesheet", "<h1\\s+[^>]*class\\s*=.pagetitle", |
| 22 | + "<form\\s+[^>]*name\\s*=\\s*.search", |
| 23 | + "<div\\s+[^>]*id\\s*=.content.*<div\\s+[^>]*id\\s*=.article", |
| 24 | +}; |
| 25 | +private Pattern[] m_cgoodpats; |
| 26 | + |
| 27 | +private String[] m_badpats = { |
| 28 | + "<[^>]*onclick\\s*=", |
| 29 | +}; |
| 30 | +private Pattern[] m_cbadpats; |
| 31 | + |
| 32 | +public HTMLTest( WikiSuite ws ) { super(ws); } |
| 33 | + |
| 34 | +public String testName() { return "HTML"; } |
| 35 | + |
| 36 | +protected boolean runTest() throws Exception { |
| 37 | + m_suite.clearCookies(); |
| 38 | + |
| 39 | + /* |
| 40 | + * Pre-compile the regexes. |
| 41 | + */ |
| 42 | + m_cgoodpats = new Pattern[m_goodpats.length]; |
| 43 | + for (int i = 0; i < m_goodpats.length; ++i) { |
| 44 | + m_cgoodpats[i] = Pattern.compile( m_goodpats[i], |
| 45 | + Pattern.CASE_INSENSITIVE | Pattern.DOTALL ); |
| 46 | + } |
| 47 | + m_cbadpats = new Pattern[m_badpats.length]; |
| 48 | + for (int i = 0; i < m_badpats.length; ++i) { |
| 49 | + m_cbadpats[i] = Pattern.compile( m_badpats[i], |
| 50 | + Pattern.CASE_INSENSITIVE | Pattern.DOTALL ); |
| 51 | + } |
| 52 | + /* |
| 53 | + * Then run the tests. |
| 54 | + */ |
| 55 | + /* java.util.logging.Level l = WikiSuite.setLoggingLevel( |
| 56 | + java.util.logging.Level.ALL ); */ |
| 57 | + |
| 58 | + if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
| 59 | + if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
| 60 | + |
| 61 | + /* WikiSuite.setLoggingLevel( l ); */ |
| 62 | + return true; |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +private boolean part1() throws Exception { |
| 67 | + boolean result = true; |
| 68 | + |
| 69 | + WebResponse wr = m_suite.viewPage( "" ); |
| 70 | + /* |
| 71 | + * Will throw exception if not parseable: |
| 72 | + */ |
| 73 | + Document doc = wr.getDOM(); |
| 74 | + result = matchesAll( wr.getText() ); |
| 75 | + |
| 76 | + wr = m_suite.viewPage( "Opera" ); |
| 77 | + doc = wr.getDOM(); |
| 78 | + result = matchesAll( wr.getText() ); |
| 79 | + |
| 80 | + wr = m_suite.viewPage( "User:Fred" ); |
| 81 | + doc = wr.getDOM(); |
| 82 | + result = matchesAll( wr.getText() ); |
| 83 | + |
| 84 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 85 | + doc = wr.getDOM(); |
| 86 | + result = matchesAll( wr.getText() ); |
| 87 | + |
| 88 | + wr = m_suite.viewPage( "Talk:Poker" ); |
| 89 | + doc = wr.getDOM(); |
| 90 | + result = matchesAll( wr.getText() ); |
| 91 | + |
| 92 | + wr = m_suite.viewPage( "Wikipedia:Upload_log" ); |
| 93 | + doc = wr.getDOM(); |
| 94 | + result = matchesAll( wr.getText() ); |
| 95 | + |
| 96 | + return result; |
| 97 | +} |
| 98 | + |
| 99 | +private boolean part2() throws Exception { |
| 100 | + boolean result = true; |
| 101 | + |
| 102 | + WebResponse wr = m_suite.loginAs( "Barney", "Barney" ); |
| 103 | + Document doc = wr.getDOM(); |
| 104 | + result = matchesAll( wr.getText() ); |
| 105 | + |
| 106 | + for (int q = 0; q < 4; ++q) { |
| 107 | + wr = setPref( "wpQuickbar", String.valueOf( q ) ); |
| 108 | + doc = wr.getDOM(); |
| 109 | + result = matchesAll( wr.getText() ); |
| 110 | + WikiSuite.fine( "Set quickbar to " + q ); |
| 111 | + |
| 112 | + for (int s = 0; s < 3; ++s) { |
| 113 | + wr = setPref( "wpSkin", String.valueOf( s ) ); |
| 114 | + doc = wr.getDOM(); |
| 115 | + result = matchesAll( wr.getText() ); |
| 116 | + WikiSuite.fine( "Set skin to " + s ); |
| 117 | + |
| 118 | + double r = Math.random(); |
| 119 | + if ( r < .5 ) { |
| 120 | + wr = m_suite.viewPage( WikiSuite.preloadedPages[ |
| 121 | + (int)(r * 100.0)] ); |
| 122 | + } else if ( r < .6 ) { |
| 123 | + wr = m_suite.viewPage( "User:Fred" ); |
| 124 | + } else if ( r < .7 ) { |
| 125 | + wr = m_suite.viewPage( "Special:Recentchanges" ); |
| 126 | + } else if ( r < .8 ) { |
| 127 | + wr = m_suite.editPage( "Talk:Sport" ); |
| 128 | + } else if ( r < .9 ) { |
| 129 | + wr = m_suite.editPage( "Wikipedia:Upload_log" ); |
| 130 | + } else { |
| 131 | + wr = m_suite.viewPage( "" ); |
| 132 | + } |
| 133 | + doc = wr.getDOM(); |
| 134 | + result = matchesAll( wr.getText() ); |
| 135 | + } |
| 136 | + } |
| 137 | + return result; |
| 138 | +} |
| 139 | + |
| 140 | +private boolean matchesAll( String text ) { |
| 141 | + if ( m_cgoodpats[0] == null ) { |
| 142 | + WikiSuite.error( "Patterns not compiled." ); |
| 143 | + return false; |
| 144 | + } |
| 145 | + for (int i = 0; i < m_goodpats.length; ++i) { |
| 146 | + Matcher m = m_cgoodpats[i].matcher( text ); |
| 147 | + if ( ! m.find() ) { |
| 148 | + WikiSuite.error( "Failed to match pattern \"" + m_goodpats[i] + "\"" ); |
| 149 | + return false; |
| 150 | + } |
| 151 | + } |
| 152 | + for (int i = 0; i < m_badpats.length; ++i) { |
| 153 | + Matcher m = m_cbadpats[i].matcher( text ); |
| 154 | + if ( m.find() ) { |
| 155 | + WikiSuite.error( "Matched pattern \"" + m_badpats[i] + "\"" ); |
| 156 | + return false; |
| 157 | + } |
| 158 | + } |
| 159 | + return true; |
| 160 | +} |
| 161 | + |
| 162 | +private WebResponse setPref( String name, String value ) |
| 163 | +throws Exception { |
| 164 | + WebResponse wr = m_suite.viewPage( "Special:Preferences" ); |
| 165 | + WebForm pform = WikiSuite.getFormByName( wr, "preferences" ); |
| 166 | + WebRequest req = pform.getRequest( "wpSaveprefs" ); |
| 167 | + |
| 168 | + req.setParameter( name, value ); |
| 169 | + return m_suite.getResponse( req ); |
| 170 | +} |
| 171 | + |
| 172 | +public static void main( String[] params ) { |
| 173 | + WikiSuite ws = new WikiSuite(); |
| 174 | + HTMLTest wt = new HTMLTest( ws ); |
| 175 | + wt.run(); |
| 176 | +} |
| 177 | + |
| 178 | +} |
Property changes on: trunk/phpwiki/testsuite/src/com/piclab/wikitest/HTMLTest.java |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 179 | + native |
Added: svn:keywords |
2 | 180 | + Author Date Id Revision |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/EditTest.java |
— | — | @@ -16,12 +16,17 @@ |
17 | 17 | |
18 | 18 | protected boolean runTest() throws Exception { |
19 | 19 | m_suite.clearCookies(); |
| 20 | + |
| 21 | + /* java.util.logging.Level l = WikiSuite.setLoggingLevel( |
| 22 | + java.util.logging.Level.ALL ); */ |
| 23 | + |
20 | 24 | if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
21 | 25 | if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
22 | 26 | if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); } |
23 | 27 | if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); } |
24 | 28 | if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); } |
25 | 29 | |
| 30 | + /* WikiSuite.setLoggingLevel( l ); */ |
26 | 31 | return true; |
27 | 32 | } |
28 | 33 | |
— | — | @@ -43,20 +48,20 @@ |
44 | 49 | text = wr.getText(); |
45 | 50 | if ( text.indexOf( "85769476243364759655" ) < 0 ) { result = false; } |
46 | 51 | |
47 | | - wr = addText( "Physics", "Edited for testing: 98762415237651243634" ); |
48 | | - wr = addText( "Mathematics", "Edited for testing: 54637465888374655394" ); |
| 52 | + wr = addText( "Talk:Physics", "Edited for testing: 98762415237651243634" ); |
| 53 | + wr = addText( "User:Fred", "Edited for testing: 54637465888374655394" ); |
49 | 54 | |
50 | 55 | wr = m_suite.viewPage( "Special:Recentchanges" ); |
51 | 56 | text = wr.getText(); |
52 | 57 | if ( text.indexOf( "Physics" ) < 0 ) { result = false; } |
53 | 58 | if ( text.indexOf( "Mathematics" ) < 0 ) { result = false; } |
54 | 59 | |
55 | | - wr = m_suite.viewPage( "Physics" ); |
| 60 | + wr = m_suite.viewPage( "Talk:Physics" ); |
56 | 61 | text = wr.getText(); |
57 | 62 | if ( text.indexOf( "98762415237651243634" ) < 0 ) { result = false; } |
58 | 63 | if ( text.indexOf( "54637465888374655394" ) >= 0 ) { result = false; } |
59 | 64 | |
60 | | - wr = m_suite.viewPage( "Mathematics" ); |
| 65 | + wr = m_suite.viewPage( "User:Fred" ); |
61 | 66 | text = wr.getText(); |
62 | 67 | if ( text.indexOf( "54637465888374655394" ) < 0 ) { result = false; } |
63 | 68 | if ( text.indexOf( "98762415237651243634" ) >= 0 ) { result = false; } |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/LinkTest.java |
— | — | @@ -17,12 +17,16 @@ |
18 | 18 | protected boolean runTest() throws Exception { |
19 | 19 | m_suite.clearCookies(); /* Make sure we aren't logged in */ |
20 | 20 | |
| 21 | + /* java.util.logging.Level l = WikiSuite.setLoggingLevel( |
| 22 | + java.util.logging.Level.ALL ); */ |
| 23 | + |
21 | 24 | if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); } |
22 | 25 | if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); } |
23 | 26 | if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); } |
24 | 27 | if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); } |
25 | 28 | if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); } |
26 | 29 | |
| 30 | + /* WikiSuite.setLoggingLevel( l ); */ |
27 | 31 | return true; |
28 | 32 | } |
29 | 33 | |
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/WikiSuite.java |
— | — | @@ -108,6 +108,7 @@ |
109 | 109 | throw new WikiSuiteFailureException( "Exception (" + e + |
110 | 110 | ") parsing login form." ); |
111 | 111 | } |
| 112 | + fine( "Logged in as " + name ); |
112 | 113 | return wr; |
113 | 114 | } |
114 | 115 | |
— | — | @@ -193,6 +194,14 @@ |
194 | 195 | ms_logger.getHandlers()[0].flush(); |
195 | 196 | } |
196 | 197 | |
| 198 | +public static Level setLoggingLevel( Level newl ) { |
| 199 | + Level oldl = ms_logger.getLevel(); |
| 200 | + |
| 201 | + ms_logger.getHandlers()[0].setLevel( newl ); |
| 202 | + ms_logger.setLevel( newl ); |
| 203 | + return oldl; |
| 204 | +} |
| 205 | + |
197 | 206 | /* |
198 | 207 | * Utility functions to interact with the wiki: |
199 | 208 | */ |
— | — | @@ -425,11 +434,10 @@ |
426 | 435 | |
427 | 436 | public static void main( String[] params ) { |
428 | 437 | WikiSuite ws = new WikiSuite(); |
| 438 | + ws.initializeDatabase(); |
429 | 439 | |
| 440 | + info( "Started Wikipedia Test Suite" ); |
430 | 441 | long start_time = System.currentTimeMillis(); |
431 | | - info( "Started Wikipedia Test Suite" ); |
432 | | - |
433 | | - ws.initializeDatabase(); |
434 | 442 | ws.startBackgroundFetchThread(); |
435 | 443 | |
436 | 444 | /* |
— | — | @@ -437,6 +445,7 @@ |
438 | 446 | */ |
439 | 447 | |
440 | 448 | (new LinkTest(ws)).run(); |
| 449 | + (new HTMLTest(ws)).run(); |
441 | 450 | (new EditTest(ws)).run(); |
442 | 451 | |
443 | 452 | /* |