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

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

Huge-ass pile of changes to make geo stuff work worldwide.

  • 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 Config::Tiny;
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 = Config::Tiny->new;
34$config->{_} = {
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# Plucene is the recommended searcher now.
46eval { require CGI::Wiki::Search::Plucene; };
47unless ( $@ ) {
48    $config->{_}{use_plucene} = 1;
49}
50
51my $search = OpenGuides::SuperSearch->new( config => $config );
52
53# Write some data.
54my $wiki = $search->{wiki};
55$wiki->write_node( "Wandsworth Common", "A common.", undef,
56                   { category => "Parks" } )
57    or die "Can't write node";
58$wiki->write_node( "Hammersmith", "A page about Hammersmith." )
59    or die "Can't write node";
60
61# Check that the search forgets input search term between invocations.
62$search->run(
63              return_output => 1,
64              vars          => { search => "parks" },
65            );
66ok( $search->{search_string}, "search_string set" );
67$search->run(
68              return_output => 1,
69            );
70ok( !$search->{search_string}, "...and forgotten" );
71
72# Sanity check.
73my (@results, %tt_vars);
74%tt_vars = $search->run(
75                         return_tt_vars => 1,
76                         vars           => { search => "parks" },
77                       );
78@results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
79is_deeply( \@results, [ "Wandsworth Common" ],
80           "first search returns expected results" );
81%tt_vars = $search->run(
82                         return_tt_vars => 1,
83                         vars           => { search => "hammersmith" },
84                       );
85@results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
86is_deeply( \@results, [ "Hammersmith" ],
87           "so does second" );
88
89# Check that the search forgets input geodata between invocations.
90# First with British National Grid.
91$search->run(
92              return_output => 1,
93              vars => { os_x => 500000, os_y => 100000, os_dist => 1000 },
94            );
95ok( $search->{x}, "x-coord set" );
96$search->run(
97              return_output => 1,
98              vars => { search => "foo" },
99            );
100ok( !$search->{x}, "...and forgotten" );
101
102# Now with Irish National Grid.
103$config->{_}{geo_handler} = 2;
104$search = OpenGuides::SuperSearch->new( config => $config );
105$search->run(
106              return_output => 1,
107              vars => { osie_x => 100000, osie_y => 200000, osie_dist => 100 },
108            );
109ok( $search->{x}, "x-coord set" );
110$search->run(
111              return_output => 1,
112              vars => { search => "foo" },
113            );
114ok( !$search->{x}, "...and forgotten" );
115
116# Now with UTM.
117$config->{_}{geo_handler} = 3;
118$config->{_}{ellipsoid} = "Airy";
119$search = OpenGuides::SuperSearch->new( config => $config );
120$search->run(
121              return_output => 1,
122              vars => { latitude => 10, longitude => 0, latlong_dist => 1000 },
123            );
124ok( $search->{x}, "x-coord set" );
125$search->run(
126              return_output => 1,
127              vars => { search => "foo" },
128            );
129ok( !$search->{x}, "...and forgotten" );
130
131
Note: See TracBrowser for help on using the repository browser.