De-Wikipedia-ization backported from stable
[mediawiki.git] / testsuite / src / com / piclab / wikitest / SearchTest.java
blobe4701fd8978080cca17968ddc4eb1b11bfcd4b1f
2 /*
3 * Test basic searching functions.
4 */
6 package com.piclab.wikitest;
7 import com.meterware.httpunit.*;
9 public class SearchTest extends WikiTest {
11 public String testName() { return "Search"; }
13 protected int initTest() throws Exception {
14 logout();
15 return 0;
18 protected int runTest() throws Exception {
19 int c = 0;
21 if ( 0 != ( c = part1() ) ) { return fail( c ); }
22 if ( 0 != ( c = part2() ) ) { return fail( c ); }
23 if ( 0 != ( c = part3() ) ) { return fail( c ); }
24 return 0;
27 private int part1() throws Exception {
28 String[] goodpats = {
29 "<h2>Article title matches</h2>\\s*<ol [^>]*>",
30 "<li><a [^>]+Cooking[^>]+>Cooking</a> \\(\\d+ bytes\\)\\s*<br>\\s*" +
31 "<small>\\d+:",
32 "<h2>Article text matches</h2>\\s*<ol [^>]*>\\s*<li><a " +
33 "[^>]*>[^<]+</a> \\(\\d+ bytes\\)\\s*<br>\\s*<small>\\d+:",
34 "<font [^>]*color\\s*=\\s*.red",
35 "<form [^>]*id\\s*=\\s*.?powersearch",
36 "<input [^>]*name\\s*=\\s*.?ns0[^>]*checked[^>]*>\\s*\\(",
37 "<input [^>]*type\\s*=\\s*.?checkbox",
38 "<input [^>]*name\\s*=\\s*.?redirs[^>]*checked[^>]*>",
39 "<input [^>]*name\\s*=\\s*.?searchx"
41 String[] badpats = {
42 "<input [^>]*name\\s*=\\s*.ns1[^>]*checked[^>]*>"
45 WebResponse wr = searchFor( "cooking" );
46 String text = getArticle( wr );
48 int ret = 0;
49 if ( 0 != ( ret = checkGoodPatterns( text, goodpats ) ) ) {
50 return 100 + ret;
52 if ( 0 != ( ret = checkBadPatterns( text, badpats ) ) ) {
53 return 110 + ret;
56 String[] goodpats2 = {
57 "<h2>No article title matches</h2>",
58 "<h2>No article text matches</h2>",
59 "<strong>\\s*Note",
60 "<form [^>]*id\\s*=\\s*.?powersearch",
61 "<input [^>]*name\\s*=\\s*.?ns0[^>]*checked[^>]*>\\s*\\("
63 String[] badpats2 = {
64 "<font [^>]*color\\s*=\\s*.red"
66 wr = searchFor( "oyaABiJxTWMISmfE" );
67 text = getArticle( wr );
69 if ( 0 != ( ret = checkGoodPatterns( text, goodpats2 ) ) ) {
70 return 120 + ret;
72 if ( 0 != ( ret = checkBadPatterns( text, badpats2 ) ) ) {
73 return 130 + ret;
76 wr = searchFor( "cooking OR sewing" );
77 text = getArticle( wr );
79 if ( 0 != ( ret = checkGoodPatterns( text, goodpats ) ) ) {
80 return 140 + ret;
82 if ( 0 != ( ret = checkBadPatterns( text, badpats ) ) ) {
83 return 150 + ret;
87 * If boolean searches are disabled, the following will
88 * fail, so comment it out.
90 wr = searchFor( "cooking AND oyaABiJxTWMISmfE" );
91 text = getArticle( wr );
93 if ( 0 != ( ret = checkGoodPatterns( text, goodpats2 ) ) ) {
94 return 160 + ret;
96 if ( 0 != ( ret = checkBadPatterns( text, badpats2 ) ) ) {
97 return 170 + ret;
100 wr = searchFor( "cooking OR oyaABiJxTWMISmfE" );
101 text = getArticle( wr );
103 if ( 0 != ( ret = checkGoodPatterns( text, goodpats ) ) ) {
104 return 180 + ret;
106 if ( 0 != ( ret = checkBadPatterns( text, badpats ) ) ) {
107 return 190 + ret;
109 return 0;
113 * Test "powersearch" in other namespaces.
116 private int part2() throws Exception {
117 String[] goodpats = {
118 "<h2>No article title matches</h2>",
119 "<form [^>]*id\\s*=\\s*.powersearch",
120 "<input [^>]*name\\s*=\\s*.ns0[^>]*checked[^>]*>\\s*\\(",
121 "<input [^>]*value\\s*=\\s*.?Barney",
122 "<input [^>]*name\\s*=\\s*.searchx"
124 String[] badpats = {
125 "<input [^>]*name\\s*=\\s*.ns1[^>]*checked[^>]*>"
128 WebResponse wr = addText( "User:Barney",
129 "Some text added just to make sure page exists..." );
130 wr = searchFor( "Barney" );
131 String text = getArticle( wr );
133 int ret = 0;
134 if ( 0 != ( ret = checkGoodPatterns( text, goodpats ) ) ) {
135 return 200 + ret;
137 if ( 0 != ( ret = checkBadPatterns( text, badpats ) ) ) {
138 return 210 + ret;
141 WebForm psform = getFormByName( wr, "powersearch" );
142 WebRequest req = psform.getRequest( "searchx" );
144 req.setParameter( "ns2", "1" );
145 wr = getResponse( req );
146 text = getArticle( wr );
148 String[] goodpats2 = {
149 "<h2>Article title matches</h2>",
150 "<form [^>]*id\\s*=\\s*.?powersearch",
151 "<input [^>]*name\\s*=\\s*.?ns0[^>]*checked[^>]*>\\s*\\(",
152 "<input [^>]*name\\s*=\\s*.?ns2[^>]*checked[^>]*>",
153 "<input [^>]*value\\s*=\\s*.?Barney",
154 "<input [^>]*name\\s*=\\s*.?searchx"
156 String[] badpats2 = {
157 "<input [^>]*name\\s*=\\s*.ns1[^>]*checked[^>]*>"
160 if ( 0 != ( ret = checkGoodPatterns( text, goodpats2 ) ) ) {
161 return 220 + ret;
163 if ( 0 != ( ret = checkBadPatterns( text, badpats2 ) ) ) {
164 return 230 + ret;
166 return 0;
170 * Test "Go" search.
173 private int part3() throws Exception {
174 String[] pagepat = { "<h1\\s[^>]*>\\s*Geography\\s*</h1>" };
175 String[] srpat = { "<h1\\s[^>]*>\\s*Search results\\s*</h1>" };
177 WebResponse wr = searchFor( "Geography", "go=Go" );
178 String text = getArticle( wr );
180 int ret = 0;
181 if ( 0 != ( ret = checkGoodPatterns( text, pagepat ) ) ) {
182 return 300 + ret;
184 if ( 0 != ( ret = checkBadPatterns( text, srpat ) ) ) {
185 return 310 + ret;
188 wr = searchFor( "oyaABiJxTWMISmfE", "go=Go" );
189 text = getArticle( wr );
191 if ( 0 != ( ret = checkGoodPatterns( text, srpat ) ) ) {
192 return 320 + ret;
194 if ( 0 != ( ret = checkBadPatterns( text, pagepat ) ) ) {
195 return 330 + ret;
197 return 0;
200 public static void main( String[] params ) {
201 (new SearchTest()).runSingle( params );