3 * Test basic searching functions.
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
{
18 protected int runTest() throws Exception
{
21 if ( 0 != ( c
= part1() ) ) { return fail( c
); }
22 if ( 0 != ( c
= part2() ) ) { return fail( c
); }
23 if ( 0 != ( c
= part3() ) ) { return fail( c
); }
27 private int part1() throws Exception
{
29 "<h2>Article title matches</h2>\\s*<ol [^>]*>",
30 "<li><a [^>]+Cooking[^>]+>Cooking</a> \\(\\d+ bytes\\)\\s*<br>\\s*" +
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"
42 "<input [^>]*name\\s*=\\s*.ns1[^>]*checked[^>]*>"
45 WebResponse wr
= searchFor( "cooking" );
46 String text
= getArticle( wr
);
49 if ( 0 != ( ret
= checkGoodPatterns( text
, goodpats
) ) ) {
52 if ( 0 != ( ret
= checkBadPatterns( text
, badpats
) ) ) {
56 String
[] goodpats2
= {
57 "<h2>No article title matches</h2>",
58 "<h2>No article text matches</h2>",
60 "<form [^>]*id\\s*=\\s*.?powersearch",
61 "<input [^>]*name\\s*=\\s*.?ns0[^>]*checked[^>]*>\\s*\\("
64 "<font [^>]*color\\s*=\\s*.red"
66 wr
= searchFor( "oyaABiJxTWMISmfE" );
67 text
= getArticle( wr
);
69 if ( 0 != ( ret
= checkGoodPatterns( text
, goodpats2
) ) ) {
72 if ( 0 != ( ret
= checkBadPatterns( text
, badpats2
) ) ) {
76 wr
= searchFor( "cooking OR sewing" );
77 text
= getArticle( wr
);
79 if ( 0 != ( ret
= checkGoodPatterns( text
, goodpats
) ) ) {
82 if ( 0 != ( ret
= checkBadPatterns( text
, badpats
) ) ) {
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
) ) ) {
96 if ( 0 != ( ret
= checkBadPatterns( text
, badpats2
) ) ) {
100 wr
= searchFor( "cooking OR oyaABiJxTWMISmfE" );
101 text
= getArticle( wr
);
103 if ( 0 != ( ret
= checkGoodPatterns( text
, goodpats
) ) ) {
106 if ( 0 != ( ret
= checkBadPatterns( text
, badpats
) ) ) {
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"
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
);
134 if ( 0 != ( ret
= checkGoodPatterns( text
, goodpats
) ) ) {
137 if ( 0 != ( ret
= checkBadPatterns( text
, badpats
) ) ) {
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
) ) ) {
163 if ( 0 != ( ret
= checkBadPatterns( text
, badpats2
) ) ) {
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
);
181 if ( 0 != ( ret
= checkGoodPatterns( text
, pagepat
) ) ) {
184 if ( 0 != ( ret
= checkBadPatterns( text
, srpat
) ) ) {
188 wr
= searchFor( "oyaABiJxTWMISmfE", "go=Go" );
189 text
= getArticle( wr
);
191 if ( 0 != ( ret
= checkGoodPatterns( text
, srpat
) ) ) {
194 if ( 0 != ( ret
= checkBadPatterns( text
, pagepat
) ) ) {
200 public static void main( String
[] params
) {
201 (new SearchTest()).runSingle( params
);