source: trunk/t/35_search_two_searches.t @ 716

Last change on this file since 716 was 716, checked in by Earle Martin, 16 years ago

Renaming OpenGuides::SuperSearch? to OpenGuides::Search and supersearch.cgi to search.cgi - bug #17.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1use strict;
2use CGI::Wiki::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides::SuperSearch;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    plan skip_all => "DBD::SQLite not installed";
10}
11
12eval { require Plucene; };
13if ( $@ ) {
14    plan skip_all => "Plucene not installed";
15}
16
17# Strictly speaking we don't need to skip _all_ tests if we don't have
18# the modules below.  Revisit this when not in a hurry.
19# We only actually need the former for the National Grid tests and the
20# latter for the UTM tests.
21eval { require Geography::NationalGrid; };
22if ( $@ ) {
23    plan skip_all => "Geography::NationalGrid not installed";
24}
25
26eval { require Geo::Coordinates::UTM; };
27if ( $@ ) {
28    plan skip_all => "Geo::Coordinates::UTM not installed";
29}
30
31plan tests => 10;
32
33# Clear out the database from any previous runs.
34unlink "t/node.db";
35unlink <t/indexes/*>;
36
37CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
38my $config = OpenGuides::Config->new(
39       vars => {
40                 dbtype             => "sqlite",
41                 dbname             => "t/node.db",
42                 indexing_directory => "t/indexes",
43                 script_name        => "wiki.cgi",
44                 script_url         => "http://example.com/",
45                 site_name          => "Test Site",
46                 template_path      => "./templates",
47                 geo_handler        => 1,
48               }
49);
50
51# Plucene is the recommended searcher now.
52eval { require CGI::Wiki::Search::Plucene; };
53if ( $@ ) { $config->use_plucene( 0 ) };
54
55my $search = OpenGuides::SuperSearch->new( config => $config );
56
57# Write some data.
58my $wiki = $search->{wiki};
59$wiki->write_node( "Wandsworth Common", "A common.", undef,
60                   { category => "Parks" } )
61    or die "Can't write node";
62$wiki->write_node( "Hammersmith", "A page about Hammersmith." )
63    or die "Can't write node";
64
65# Check that the search forgets input search term between invocations.
66$search->run(
67              return_output => 1,
68              vars          => { search => "parks" },
69            );
70ok( $search->{search_string}, "search_string set" );
71$search->run(
72              return_output => 1,
73            );
74ok( !$search->{search_string}, "...and forgotten" );
75
76# Sanity check.
77my (@results, %tt_vars);
78%tt_vars = $search->run(
79                         return_tt_vars => 1,
80                         vars           => { search => "parks" },
81                       );
82@results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
83is_deeply( \@results, [ "Wandsworth Common" ],
84           "first search returns expected results" );
85%tt_vars = $search->run(
86                         return_tt_vars => 1,
87                         vars           => { search => "hammersmith" },
88                       );
89@results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
90is_deeply( \@results, [ "Hammersmith" ],
91           "so does second" );
92
93# Check that the search forgets input geodata between invocations.
94# First with British National Grid.
95$search->run(
96              return_output => 1,
97              vars => { os_x => 500000, os_y => 100000, os_dist => 1000 },
98            );
99ok( $search->{x}, "x-coord set" );
100$search->run(
101              return_output => 1,
102              vars => { search => "foo" },
103            );
104ok( !$search->{x}, "...and forgotten" );
105
106# Now with Irish National Grid.
107$config->geo_handler( 2 );
108$search = OpenGuides::SuperSearch->new( config => $config );
109$search->run(
110              return_output => 1,
111              vars => { osie_x => 100000, osie_y => 200000, osie_dist => 100 },
112            );
113ok( $search->{x}, "x-coord set" );
114$search->run(
115              return_output => 1,
116              vars => { search => "foo" },
117            );
118ok( !$search->{x}, "...and forgotten" );
119
120# Now with UTM.
121$config->geo_handler( 3 );
122$config->ellipsoid( "Airy" );
123$search = OpenGuides::SuperSearch->new( config => $config );
124$search->run(
125              return_output => 1,
126              vars => { latitude => 10, longitude => 0, latlong_dist => 1000 },
127            );
128ok( $search->{x}, "x-coord set" );
129$search->run(
130              return_output => 1,
131              vars => { search => "foo" },
132            );
133ok( !$search->{x}, "...and forgotten" );
134
135
Note: See TracBrowser for help on using the repository browser.