| 1 |
#!/bin/sh |
| •2 |
# Part of the ht://Dig package <https://htdig.sourceforge.net/> |
| 3 |
# Copyright (c) 1999-2004 The ht://Dig Group |
| 4 |
# For copyright details, see the file COPYING in your distribution |
| 5 |
# or the GNU Library General Public License (LGPL) version 2 or later |
| 6 |
# <http://www.gnu.org/copyleft/lgpl.html> |
| 7 |
# |
| 8 |
# $Id: t_templates,v 1.4 2004/05/28 13:15:30 lha Exp $ |
| 9 |
# |
| 10 |
|
| 11 |
# Tests the following config attributes: |
| 12 |
# add_anchors_to_excerpt |
| 13 |
# allow_in_form |
| 14 |
# anchor_target |
| 15 |
# any_keywords |
| 16 |
# build_select_lists |
| 17 |
# date_format |
| 18 |
# end_ellipses |
| 19 |
# end_highlight |
| 20 |
# excerpt_show_top |
| 21 |
# image_url_prefix |
| 22 |
# iso_8601 |
| 23 |
# matches_per_page |
| 24 |
# matches_per_page_list |
| 25 |
# max_excerpts |
| 26 |
# max_descriptions |
| 27 |
# max_description_length |
| 28 |
# max_stars |
| 29 |
# maximum_page_buttons |
| 30 |
# maximum_pages |
| 31 |
# method_names |
| 32 |
# next_page_text |
| 33 |
# no_excerpt_show_top |
| 34 |
# no_excerpt_text |
| 35 |
# no_page_list_header |
| 36 |
# no_page_number_text |
| 37 |
# no_next_page_text |
| 38 |
# no_prev_page_text |
| 39 |
# no_title_text |
| 40 |
# nothing_found_file |
| 41 |
# page_list_header |
| 42 |
# page_number_separator |
| 43 |
# page_number_text |
| 44 |
# prev_page_text |
| 45 |
# plural_suffix |
| 46 |
# search_results_contenttype |
| 47 |
# search_results_wrapper |
| 48 |
# sort_names |
| 49 |
# star_blank |
| 50 |
# star_image |
| 51 |
# star_patterns |
| 52 |
# start_ellipses |
| 53 |
# start_highlight |
| 54 |
# syntax_error_file |
| 55 |
# use_star_image |
| 56 |
|
| 57 |
|
| 58 |
try() { |
| 59 |
comment="$1" |
| 60 |
shift |
| 61 |
query="$1" |
| 62 |
shift |
| 63 |
$htsearch -c $config "$query" > $tmp 2> /dev/null |
| 64 |
for pattern |
| 65 |
do |
| 66 |
if grep "$pattern" $tmp > /dev/null |
| 67 |
then : |
| 68 |
else |
| 69 |
$htsearch -vv -c $config "$query" > /dev/null |
| 70 |
echo "Output doesn't match \"$pattern\"" |
| 71 |
fail "$htsearch -c $config '$query' >> $tmp -- |
| 72 |
$comment" |
| 73 |
fi |
| 74 |
done |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
test_functions_action=--start-apache |
| 81 |
. ./test_functions |
| 82 |
|
| 83 |
config=$testdir/conf/htdig.conf.tmp |
| 84 |
tmp=/tmp/t_htsearch$$ |
| 85 |
|
| 86 |
# set up config file with chosen non-default values |
| 87 |
cp $testdir/conf/htdig.conf $config |
| 88 |
|
| 89 |
$htdig "$@" -t -i -c $config || fail "Couldn't dig" |
| 90 |
|
| 91 |
$htpurge -vv -c $config > tmp1 || fail "Couldn't purge" |
| 92 |
|
| 93 |
# How can I check that unretrieved urls have been removed, but bad ones haven't? |
| 94 |
|
| 95 |
|
| 96 |
set_attr search_results_wrapper "$testdir/conf/main-template" |
| 97 |
set_attr any_keywords "true" |
| 98 |
set_attr image_url_prefix "image-prefix" |
| 99 |
|
| 100 |
try ". Single page of results" \ |
| 101 |
"words=also;config=hello;exclude=site2;format=builtin-short;keywords=subject+please+node;matchesperpage=10;method=and;page=1;restrict=http;sort=score;startyear=1999;startmonth=8;startday=1;endyear=2005;endmonth=9;endday=30" \ |
| 102 |
'MATCHES *=3' 'bad_local.htm' 'script.html' 'site4.html' \ |
| 103 |
'CGI *=-' 'CONFIG *=hello' 'EXCLUDE *=site2' 'FIRSTDISPLAYED *=1' \ |
| 104 |
'builtin-short" selected>Short' 'KEYWORDS *=subject please node' \ |
| 105 |
'LASTDISPLAYED *=3' 'LOGICAL_WORDS *=also' \ |
| 106 |
'MATCHES_PER_PAGE *=10' 'MATCH_MESSAGE *=All' 'MAX_STARS *=4' \ |
| 107 |
'METADESCRIPTION *=-' 'selected>All' 'MODIFIED *=-' \ |
| 108 |
'NEXTPAGE *=-' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=-' \ |
| 109 |
'PAGELIST *=-' 'PAGES *=1' 'PLURAL_MATCHES *=s' \ |
| 110 |
'PREVPAGE *=-' 'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-short' \ |
| 111 |
'SELECTED_METHOD *=and' 'SELECTED_SORT *=score' \ |
| 112 |
'selected>Score' 'VERSION *=3.2' 'WORDS *=also' \ |
| 113 |
'image-prefix/star.gif' |
| 114 |
|
| 115 |
|
| 116 |
set_attr plural_suffix "es" |
| 117 |
set_attr allow_in_form "script_name" |
| 118 |
set_attr page_list_header "head" |
| 119 |
set_attr add_anchors_to_excerpt "true" |
| 120 |
# make sure "script" is the page returned... |
| 121 |
set_attr search_results_order "bad_local script *" |
| 122 |
# set_attr iso_8601 FALSE # no point -- format set by locale |
| 123 |
|
| 124 |
# (Ensure keyword 'moderate' for script.html occurs after 'also', as anchors |
| 125 |
# are broken if keyword preceeds anchor, but search term follows it.) |
| 126 |
try "2nd page, 1 match per page, no excludes" \ |
| 127 |
"words=also;script_name=qtest;format=builtin-long;keywords=subject+please+moderate;matchesperpage=1;method=or;page=2;restrict=http;sort=revtime;startyear=1999;startmonth=8;startday=1;endyear=2005;endmonth=9;endday=30" \ |
| 128 |
'MATCHES *=3' 'script.html' \ |
| 129 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' 'FIRSTDISPLAYED *=2' \ |
| 130 |
'builtin-long" selected>Long' 'KEYWORDS *=subject please moderate' \ |
| 131 |
'LASTDISPLAYED *=2' 'LOGICAL_WORDS *=also' \ |
| 132 |
'MATCHES_PER_PAGE *=1' 'MATCH_MESSAGE *=Any' 'MAX_STARS *=4' \ |
| 133 |
'METADESCRIPTION *=-' 'selected>Any' 'MODIFIED *=-' \ |
| 134 |
'NEXTPAGE *=.*;page=3' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=head' \ |
| 135 |
'PAGELIST *=.*;page=1.*;page=3' 'PAGES *=3' 'PLURAL_MATCHES *=es' \ |
| 136 |
'PREVPAGE *=.*;page=1' 'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-long' \ |
| 137 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revtime' \ |
| 138 |
'selected>Reverse Time' 'VERSION *=3.2' 'WORDS *=also' \ |
| 139 |
'<strong><code>\.\.\. </code></strong>' '<strong><a href="[^"]*">also</a></strong>' \ |
| 140 |
|
| 141 |
set_attr method_names "or Or and And boolean Logical" |
| 142 |
set_attr page_list_header 'multiple' |
| 143 |
set_attr no_page_list_header 'single' |
| 144 |
set_attr anchor_target "body" |
| 145 |
set_attr maximum_page_buttons "2" |
| 146 |
set_attr no_next_page_text "none" |
| 147 |
set_attr no_prev_page_text "none" |
| 148 |
set_attr next_page_text "following" |
| 149 |
set_attr prev_page_text "preceeding" |
| 150 |
set_attr iso_8601 true |
| 151 |
|
| 152 |
try "2nd page, 1 match per page, no excludes, no keywords" \ |
| 153 |
"words=also;script_name=qtest;format=builtin-long;matchesperpage=1;method=or;page=2;restrict=http;sort=revtime;startyear=1999;startmonth=8;startday=1;endyear=2005;endmonth=9;endday=30" \ |
| 154 |
'MATCHES *=4' \ |
| 155 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' 'FIRSTDISPLAYED *=2' \ |
| 156 |
'builtin-long" selected>Long' 'KEYWORDS *=-' \ |
| 157 |
'LASTDISPLAYED *=2' 'LOGICAL_WORDS *=also' \ |
| 158 |
'MATCHES_PER_PAGE *=1' 'MATCH_MESSAGE *=Or' 'MAX_STARS *=4' \ |
| 159 |
'METADESCRIPTION *=-' 'selected>Or' 'MODIFIED *=-' \ |
| 160 |
'NEXTPAGE *=.*;page=3.*following' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=multiple' \ |
| 161 |
'PAGELIST *=.*;page=1.*2[^0-9]*-' 'PAGES *=4' 'PLURAL_MATCHES *=es' \ |
| 162 |
'PREVPAGE *=.*;page=1.*preceeding' 'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-long' \ |
| 163 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revtime' \ |
| 164 |
'selected>Reverse Time' 'VERSION *=3.2' 'WORDS *=also' \ |
| 165 |
'<strong><code>\.\.\. </code></strong>' '<strong><a target="body" href="[^"]*">also</a></strong>' \ |
| 166 |
'20[0-9][0-9]-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]* [a-zA-Z]*' # iso date |
| 167 |
|
| 168 |
# ('\\\\' because original line in htdig.conf has a continuation '\' ) |
| 169 |
set_attr page_number_text "first second third fourth \\\\" |
| 170 |
set_attr no_page_number_text "FIRST SECOND THIRD FOURTH \\\\" |
| 171 |
set_attr page_number_separator "PAGE_SEP" |
| 172 |
set_attr maximum_pages 2 |
| 173 |
set_attr date_format "%Y-date-%m-date-%d-" # overrides iso_8601 |
| 174 |
|
| 175 |
try "2nd page, 1 match per page, changed page numbers" \ |
| 176 |
"words=also;script_name=qtest;format=builtin-long;matchesperpage=1;method=or;page=2;restrict=http;sort=revtime;startyear=1999;startmonth=8;startday=1;endyear=2005;endmonth=9;endday=30" \ |
| 177 |
'MATCHES *=4' \ |
| 178 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' 'FIRSTDISPLAYED *=2' \ |
| 179 |
'builtin-long" selected>Long' 'KEYWORDS *=-' \ |
| 180 |
'LASTDISPLAYED *=2' 'LOGICAL_WORDS *=also' \ |
| 181 |
'MATCHES_PER_PAGE *=1' 'MATCH_MESSAGE *=Or' 'MAX_STARS *=4' \ |
| 182 |
'METADESCRIPTION *=-' 'selected>Or' 'MODIFIED *=-' \ |
| 183 |
'NEXTPAGE *=none' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=multiple' \ |
| 184 |
'PAGELIST *=.*first.*PAGE_SEP.*SECOND' 'PAGES *=2' 'PLURAL_MATCHES *=es' \ |
| 185 |
'PREVPAGE *=.*;page=1' 'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-long' \ |
| 186 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revtime' \ |
| 187 |
'selected>Reverse Time' 'VERSION *=3.2' 'WORDS *=also' \ |
| 188 |
'<strong><code>\.\.\. </code></strong>' '<strong><a target="body" href="[^"]*">also</a></strong>' \ |
| 189 |
'20[0-9][0-9]-date-[0-9]*-date-[0-9]*-' |
| 190 |
|
| 191 |
#'MATCHES *=4' 'bad_local.htm' 'script.html' 'site2.html' 'site4.html' |
| 192 |
|
| 193 |
set_attr any_keywords "false" |
| 194 |
set_attr nothing_found_file "$testdir/conf/main-template" |
| 195 |
set_attr add_anchors_to_excerpt "false" |
| 196 |
try "fails keyword match" \ |
| 197 |
"words=also;script_name=qtest;format=builtin-long;keywords=subject+please+node;matchesperpage=1;method=or;page=2;restrict=http;sort=revtime;startyear=1999;startmonth=8;startday=1;endyear=2005;endmonth=9;endday=30" \ |
| 198 |
'MATCHES *=0' \ |
| 199 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' \ |
| 200 |
'builtin-long" selected>Long' 'KEYWORDS *=subject please node' \ |
| 201 |
'LOGICAL_WORDS *=also' \ |
| 202 |
'MATCHES_PER_PAGE *=1' 'MATCH_MESSAGE *=Or' 'MAX_STARS *=4' \ |
| 203 |
'METADESCRIPTION *=-' 'selected>Or' 'MODIFIED *=-' \ |
| 204 |
'NSTARS *=-' 'PAGELIST *=-' 'PAGES *=1' \ |
| 205 |
'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-long' \ |
| 206 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revtime' \ |
| 207 |
'selected>Reverse Time' 'VERSION *=3.2' 'WORDS *=also' \ |
| 208 |
'starting date =1999/8/1-' \ |
| 209 |
'ending date =2005/9/30-' |
| 210 |
|
| 211 |
set_attr start_ellipses "START_ELLIPSES" |
| 212 |
set_attr end_ellipses "END_ELLIPSES" |
| 213 |
set_attr star_blank "NIL" |
| 214 |
set_attr star_image "STAR" |
| 215 |
set_attr matches_per_page 8 |
| 216 |
|
| 217 |
try "test highlighting" \ |
| 218 |
"words=also;script_name=qtest;format=builtin-long;method=or;restrict=http;sort=revscore" \ |
| 219 |
'MATCHES *=4' \ |
| 220 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' 'FIRSTDISPLAYED *=1' \ |
| 221 |
'LASTDISPLAYED *=4' 'LOGICAL_WORDS *=also' \ |
| 222 |
'MATCHES_PER_PAGE *=8' 'MATCH_MESSAGE *=Or' 'MAX_STARS *=4' \ |
| 223 |
'METADESCRIPTION *=-' 'selected>Or' 'MODIFIED *=-' \ |
| 224 |
'NEXTPAGE *=-' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=single' \ |
| 225 |
'PAGELIST *=-' 'PAGES *=1' 'PLURAL_MATCHES *=es' \ |
| 226 |
'PREVPAGE *=-' 'RESTRICT *=http' 'SELECTED_FORMAT *=builtin-long' \ |
| 227 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revscore' \ |
| 228 |
'selected>Reverse Score' 'VERSION *=3.2' 'WORDS *=also' \ |
| 229 |
'START_ELLIPSES' 'END_ELLIPSES' '<strong>also</strong>' \ |
| 230 |
'^[^S]*"STAR".*"NIL".*"NIL".*"NIL"' |
| 231 |
|
| 232 |
set_attr max_stars 5 |
| 233 |
set_attr start_highlight "START" |
| 234 |
set_attr end_highlight "STOP" |
| 235 |
set_attr max_excerpts 2 |
| 236 |
set_attr template_map "Long builtin-long builtin-long Short builtin-short builtin-short Very-long user-long $PWD/conf/entry-template" |
| 237 |
try "test max_stars. Also needs max_descriptions >= 2" \ |
| 238 |
"words=also;script_name=qtest;format=user-long;method=or;restrict=http;sort=revscore" \ |
| 239 |
'MATCHES *=4' \ |
| 240 |
'CGI *=qtest' 'CONFIG *=-' 'EXCLUDE *=-' 'FIRSTDISPLAYED *=1' \ |
| 241 |
'LASTDISPLAYED *=4' 'LOGICAL_WORDS *=also' \ |
| 242 |
'MATCHES_PER_PAGE *=8' 'MATCH_MESSAGE *=Or' 'MAX_STARS *=5' \ |
| 243 |
'METADESCRIPTION *=-' 'selected>Or' 'MODIFIED *=-' \ |
| 244 |
'NEXTPAGE *=-' 'NSTARS *=-' 'PAGE *=1' 'PAGEHEADER *=single' \ |
| 245 |
'PAGELIST *=-' 'PAGES *=1' 'PLURAL_MATCHES *=es' \ |
| 246 |
'PREVPAGE *=-' 'RESTRICT *=http' 'SELECTED_FORMAT *=user-long' \ |
| 247 |
'SELECTED_METHOD *=or' 'SELECTED_SORT *=revscore' \ |
| 248 |
'selected>Reverse Score' 'VERSION *=3.2' 'WORDS *=also' \ |
| 249 |
'START_ELLIPSES.*START_ELLIPSES.*END_ELLIPSES' 'STARTalsoSTOP' \ |
| 250 |
'^[^N]*"STAR".*"NIL".*"NIL".*"NIL".*"NIL"' \ |
| 251 |
'DESCRIPTIONS=JavaScript test<br>top<br><br>' |
| 252 |
|
| 253 |
try "Search for 'empty'" \ |
| 254 |
"words=empty;format=builtin-long" \ |
| 255 |
'MATCHES *=2' \ |
| 256 |
'empty%20file.html' 'empty file.html' 'sub%2520dir' 'INDEX OF /SET1/SUB%20DIR' |
| 257 |
set_attr no_title_text "Empty-Title" |
| 258 |
try "Search for 'empty'" \ |
| 259 |
"words=empty;format=builtin-long" \ |
| 260 |
'MATCHES *=2' \ |
| 261 |
'empty%20file.html' 'Empty-Title' 'sub%2520dir' |
| 262 |
|
| 263 |
set_attr star_patterns "site foo bad_local bar" |
| 264 |
try "test star_patterns" \ |
| 265 |
"words=also;format=builtin-long" \ |
| 266 |
'MATCHES *=4' '"foo"' '"bar"' |
| 267 |
|
| 268 |
set_attr star_patterns "site foo bad_local" |
| 269 |
try "test star_patterns syntax error" \ |
| 270 |
"words=also;format=builtin-long" \ |
| 271 |
'MATCHES *=4' '"foo"' '""' |
| 272 |
|
| 273 |
set_attr search_results_contenttype "foo" |
| 274 |
set_attr use_star_image "false" |
| 275 |
try "Checking use_star_image" \ |
| 276 |
"words=bad_local;format=builtin-short" \ |
| 277 |
"^[^*]*bad_local" "Content-type: foo" |
| 278 |
|
| 279 |
set_attr search_results_contenttype "" |
| 280 |
set_attr no_excerpt_text "No-excerpt-found" |
| 281 |
try "Checking no_excerpt_show_top true" \ |
| 282 |
"words=Yuki" \ |
| 283 |
"a#bcd" |
| 284 |
|
| 285 |
set_attr no_excerpt_show_top "false" |
| 286 |
try "Checking no_excerpt_show_top false" \ |
| 287 |
"words=Yuki" \ |
| 288 |
"No-excerpt-found" |
| 289 |
|
| 290 |
try "Checking excerpt_show_top false" \ |
| 291 |
"words=also" \ |
| 292 |
"STARTalsoSTOP" |
| 293 |
|
| 294 |
set_attr build_select_lists 'MATCH_LIST,multiple matchesperpage matches_per_page_list 2 2 1 matches_per_page "Previous Amount"' |
| 295 |
set_attr matches_per_page_list 'one 1 five 5 ten 10 twenty 20 "one hundred" 100 "two hundred" 200' |
| 296 |
set_attr sort_names "score 'Best Match' time Newest title A-Z revscore 'Worst Match' revtime Oldest revtitle Z-A" |
| 297 |
set_attr excerpt_show_top "true" |
| 298 |
|
| 299 |
try "Checking excerpt_show_top true" \ |
| 300 |
"words=also;matchesperpage=40" \ |
| 301 |
"Copyright" \ |
| 302 |
"MATCH_LIST *=<" "selected>Previous Amount" '<option value="1">one' \ |
| 303 |
'SORT *=<select name="sort">' \ |
| 304 |
'<option value="score" selected>Best Match' \ |
| 305 |
'<option value="time">Newest' \ |
| 306 |
'<option value="title">A-Z' \ |
| 307 |
'<option value="revscore">Worst Match' \ |
| 308 |
'<option value="revtime">Oldest' \ |
| 309 |
'<option value="revtitle">Z-A' \ |
| 310 |
'</select>' |
| 311 |
|
| 312 |
set_attr syntax_error_file "$testdir/conf/main-template" |
| 313 |
try "Checking syntax error file" \ |
| 314 |
"words=also+and;method=boolean" \ |
| 315 |
'MATCHES *=0' 'LOGICAL_WORDS *=also and' \ |
| 316 |
'MATCH_MESSAGE *=Logical' 'METADESCRIPTION *=-' 'selected>Logical' \ |
| 317 |
'PAGELIST *=-' 'PAGES *=1' 'SELECTED_METHOD *=boolean' \ |
| 318 |
'VERSION *=3.2' 'WORDS *=also and' |
| 319 |
|
| 320 |
|
| 321 |
set_attr max_descriptions 1 |
| 322 |
set_attr max_description_length 5 |
| 323 |
$htdig "$@" -t -i -c $config || fail "Couldn't dig" |
| 324 |
$htpurge -c $config || fail "Couldn't purge" |
| 325 |
try "Check anchor descriptions" \ |
| 326 |
"words=also;script_name=qtest;format=user-long;method=or;restrict=http;sort=revscore" \ |
| 327 |
'DESCRIPTIONS=JavaScript ...<br><br>' |
| 328 |
# Why does it end with "..." when START/END_ELLIPSES aren't ...? |
| 329 |
|
| 330 |
test_functions_action=--stop-apache |
| 331 |
. ./test_functions |