r1240 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1239‎ | r1240 | r1241 >
Date:00:42, 18 March 2003
Author:lcrocker
Status:old
Tags:
Comment:
Added HTMLTest, some logging options.
Modified paths:
  • /trunk/phpwiki/testsuite/src/com/piclab/wikitest/EditTest.java (modified) (history)
  • /trunk/phpwiki/testsuite/src/com/piclab/wikitest/HTMLTest.java (added) (history)
  • /trunk/phpwiki/testsuite/src/com/piclab/wikitest/LinkTest.java (modified) (history)
  • /trunk/phpwiki/testsuite/src/com/piclab/wikitest/WikiSuite.java (modified) (history)

Diff [purge]

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
1179 + native
Added: svn:keywords
2180 + Author Date Id Revision
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/EditTest.java
@@ -16,12 +16,17 @@
1717
1818 protected boolean runTest() throws Exception {
1919 m_suite.clearCookies();
 20+
 21+ /* java.util.logging.Level l = WikiSuite.setLoggingLevel(
 22+ java.util.logging.Level.ALL ); */
 23+
2024 if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); }
2125 if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); }
2226 if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); }
2327 if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); }
2428 if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); }
2529
 30+ /* WikiSuite.setLoggingLevel( l ); */
2631 return true;
2732 }
2833
@@ -43,20 +48,20 @@
4449 text = wr.getText();
4550 if ( text.indexOf( "85769476243364759655" ) < 0 ) { result = false; }
4651
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" );
4954
5055 wr = m_suite.viewPage( "Special:Recentchanges" );
5156 text = wr.getText();
5257 if ( text.indexOf( "Physics" ) < 0 ) { result = false; }
5358 if ( text.indexOf( "Mathematics" ) < 0 ) { result = false; }
5459
55 - wr = m_suite.viewPage( "Physics" );
 60+ wr = m_suite.viewPage( "Talk:Physics" );
5661 text = wr.getText();
5762 if ( text.indexOf( "98762415237651243634" ) < 0 ) { result = false; }
5863 if ( text.indexOf( "54637465888374655394" ) >= 0 ) { result = false; }
5964
60 - wr = m_suite.viewPage( "Mathematics" );
 65+ wr = m_suite.viewPage( "User:Fred" );
6166 text = wr.getText();
6267 if ( text.indexOf( "54637465888374655394" ) < 0 ) { result = false; }
6368 if ( text.indexOf( "98762415237651243634" ) >= 0 ) { result = false; }
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/LinkTest.java
@@ -17,12 +17,16 @@
1818 protected boolean runTest() throws Exception {
1919 m_suite.clearCookies(); /* Make sure we aren't logged in */
2020
 21+ /* java.util.logging.Level l = WikiSuite.setLoggingLevel(
 22+ java.util.logging.Level.ALL ); */
 23+
2124 if ( ! part1() ) { throw new WikiSuiteFailureException( "Part 1" ); }
2225 if ( ! part2() ) { throw new WikiSuiteFailureException( "Part 2" ); }
2326 if ( ! part3() ) { throw new WikiSuiteFailureException( "Part 3" ); }
2427 if ( ! part4() ) { throw new WikiSuiteFailureException( "Part 4" ); }
2528 if ( ! part5() ) { throw new WikiSuiteFailureException( "Part 5" ); }
2629
 30+ /* WikiSuite.setLoggingLevel( l ); */
2731 return true;
2832 }
2933
Index: trunk/phpwiki/testsuite/src/com/piclab/wikitest/WikiSuite.java
@@ -108,6 +108,7 @@
109109 throw new WikiSuiteFailureException( "Exception (" + e +
110110 ") parsing login form." );
111111 }
 112+ fine( "Logged in as " + name );
112113 return wr;
113114 }
114115
@@ -193,6 +194,14 @@
194195 ms_logger.getHandlers()[0].flush();
195196 }
196197
 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+
197206 /*
198207 * Utility functions to interact with the wiki:
199208 */
@@ -425,11 +434,10 @@
426435
427436 public static void main( String[] params ) {
428437 WikiSuite ws = new WikiSuite();
 438+ ws.initializeDatabase();
429439
 440+ info( "Started Wikipedia Test Suite" );
430441 long start_time = System.currentTimeMillis();
431 - info( "Started Wikipedia Test Suite" );
432 -
433 - ws.initializeDatabase();
434442 ws.startBackgroundFetchThread();
435443
436444 /*
@@ -437,6 +445,7 @@
438446 */
439447
440448 (new LinkTest(ws)).run();
 449+ (new HTMLTest(ws)).run();
441450 (new EditTest(ws)).run();
442451
443452 /*

Status & tagging log