source: trunk/t/35_supersearch_two_searches.t @ 587

Last change on this file since 587 was 587, checked in by kake, 17 years ago

Encapsulate config data in OpenGuides::Config.

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