root/tags/rel0_59/t/35_search_two_searches.t

Revision 956, 4.2 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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