root/branches/new-install-process/t/33_search_advanced_search.t

Revision 956, 6.9 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::Plugin::Locator::Grid; # use directly to help debug
3use Wiki::Toolkit::Setup::SQLite;
4use OpenGuides::Config;
5use OpenGuides::Search;
6use OpenGuides::Test;
7use Test::More;
8
9eval { require DBD::SQLite; };
10if ( $@ ) {
11    my ($error) = $@ =~ /^(.*?)\n/;
12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
13}
14
15eval { require Plucene; };
16if ( $@ ) {
17    plan skip_all => "Plucene not installed";
18}
19
20eval { require Geography::NationalGrid::GB; };
21if ( $@ ) {
22    plan skip_all => "Geography::NationalGrid::GB not installed";
23}
24
25plan tests => 8;
26
27# Clear out the database from any previous runs.
28unlink "t/node.db";
29unlink <t/indexes/*>;
30Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
31
32my $config = OpenGuides::Config->new(
33       vars => {
34                 dbtype             => "sqlite",
35                 dbname             => "t/node.db",
36                 indexing_directory => "t/indexes",
37                 script_name        => "wiki.cgi",
38                 script_url         => "http://example.com/",
39                 site_name          => "Test Site",
40                 template_path      => "./templates",
41                 use_plucene        => 1,
42                 geo_handler        => 1,
43           }
44);
45my $search = OpenGuides::Search->new( config => $config );
46my $guide = OpenGuides->new( config => $config );
47
48# Write some data.
49OpenGuides::Test->write_data(
50                              guide      => $guide,
51                              node       => "Crabtree Tavern",
52                              os_x       => 523465,
53                              os_y       => 177490,
54                              categories => "Pubs",
55                            );
56
57OpenGuides::Test->write_data(
58                              guide      => $guide,
59                              node       => "Blue Anchor",
60                              os_x       => 522909,
61                              os_y       => 178232,
62                              categories => "Pubs",
63                            );
64
65OpenGuides::Test->write_data(
66                              guide      => $guide,
67                              node       => "Star Tavern",
68                              os_x       => 528107,
69                              os_y       => 179347,
70                              categories => "Pubs",
71                            );
72
73OpenGuides::Test->write_data(
74                              guide      => $guide,
75                              node       => "Hammersmith Bridge",
76                              os_x       => 522983,
77                              os_y       => 178118,
78                            );
79
80# Sanity check.
81print "# Distances should be:\n";
82my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new(x => "os_x", y => "os_y");
83my $wiki = $guide->wiki;
84$wiki->register_plugin( plugin => $locator );
85foreach my $node ( "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge"){
86    print "# $node: " . $locator->distance( from_x  => 523450,
87                                            from_y  => 177650,
88                                            to_node => $node ) . "\n";
89}
90
91# Check that a lat/long distance search finds them.
92my %tt_vars = $search->run(
93                            return_tt_vars => 1,
94                            vars => {
95                                      latitude     => 51.484320,
96                                      longitude    => -0.223484,
97                                      latlong_dist => 1000,
98                                    },
99                          );
100my @ordered = map { $_->{name} } @{ $tt_vars{results} || [] };
101my @found = sort @ordered;
102is_deeply( \@found,
103           [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ],
104           "distance search finds the right things" );
105is_deeply( \@ordered,
106           [ "Crabtree Tavern", "Hammersmith Bridge", "Blue Anchor" ],
107           "...and returns them in the right order" );
108
109%tt_vars = $search->run(
110                         return_tt_vars => 1,
111                         vars => {
112                                   latitude     => 51.484320,
113                                   longitude    => -0.223484,
114                                   latlong_dist => 1000,
115                                   search       => " ",
116                                 },
117                       );
118@ordered = map { $_->{name} } @{ $tt_vars{results} || [] };
119@found = sort @ordered;
120is_deeply( \@found,
121           [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ],
122           "...still works if whitespace-only search text supplied" );
123
124%tt_vars = $search->run(
125                         return_tt_vars => 1,
126                         vars => {
127                                   os_x    => 523450,
128                                   os_y    => 177650,
129                                   os_dist => 1000,
130                                   search  => " ",
131                                 },
132                       );
133@ordered = map { $_->{name} } @{ $tt_vars{results} || [] };
134@found = sort @ordered;
135is_deeply( \@found,
136       [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ],
137       "...works with OS co-ords" );
138
139%tt_vars = eval {
140       $search->run(
141                     return_tt_vars => 1,
142                     vars => {
143                               os_x      => 523450,
144                               os_y      => 177650,
145                               os_dist   => 1000,
146                               search    => " ",
147                               latitude  => " ",
148                               longitude => " ",
149                             },
150                   );
151};
152is( $@, "", "...works with OS co-ords and whitespace-only lat/long" );
153@ordered = map { $_->{name} } @{ $tt_vars{results} || [] };
154@found = sort @ordered;
155is_deeply( \@found,
156       [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ],
157         "...returns the right stuff" );
158
159%tt_vars = $search->run(
160                     return_tt_vars => 1,
161                     vars => {
162                               latitude     => 51.484320,
163                               longitude    => -0.223484,
164                               latlong_dist => 1000,
165                               search       => "pubs",
166                             },
167                   );
168@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
169is_deeply( \@found, [ "Blue Anchor", "Crabtree Tavern", ],
170       "distance search in combination with text search works" );
171
172%tt_vars = $search->run(
173                     return_tt_vars => 1,
174                     vars => {
175                               os_x    => 523450,
176                               os_y    => 177650,
177                               os_dist => 1000,
178                               search  => "pubs",
179                             },
180                   );
181@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
182is_deeply( \@found, [ "Blue Anchor", "Crabtree Tavern", ],
183       "...works with OS co-ords too" );
Note: See TracBrowser for help on using the browser.