root/trunk/t/38_search_params.t

Revision 956, 6.8 kB (checked in by earle, 20 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 CGI;
3use Wiki::Toolkit::Setup::SQLite;
4use OpenGuides::Config;
5use OpenGuides::Search;
6use Test::More;
7
8eval { require DBD::SQLite; };
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
12}
13
14eval { require Wiki::Toolkit::Search::Plucene; };
15if ( $@ ) {
16    plan skip_all => "Plucene not installed";
17}
18
19# Strictly speaking we don't need to skip _all_ tests if we don't have
20# the modules below.  Revisit this when not in a hurry.
21# We only actually need them for the tests where lat/long are converted.
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 => 19;
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                 use_plucene        => 1,
49                 geo_handler        => 1, # British National Grid
50               }
51);
52
53# Check the British National Grid case.
54my $q = CGI->new( "" );
55$q->param( -name => "os_x",         -value => 500000 );
56$q->param( -name => "os_y",         -value => 200000 );
57$q->param( -name => "os_dist",      -value => 500    );
58$q->param( -name => "osie_dist",    -value => 600    );
59$q->param( -name => "latlong_dist", -value => 700    );
60my %vars = $q->Vars();
61my $search = OpenGuides::Search->new( config => $config );
62$search->run( vars => \%vars, return_output => 1 );
63is( $search->{distance_in_metres}, 500,
64    "os_dist picked up when OS co-ords given and using British grid" );
65is( $search->{x}, 500000, "...x set from os_x" );
66is( $search->{y}, 200000, "...y set from os_y" );
67
68$q = CGI->new( "" );
69$q->param( -name => "osie_x",       -value => 500000 );
70$q->param( -name => "osie_y",       -value => 200000 );
71$q->param( -name => "os_dist",      -value => 500    );
72$q->param( -name => "osie_dist",    -value => 600    );
73$q->param( -name => "latlong_dist", -value => 700    );
74%vars = $q->Vars();
75$search = OpenGuides::Search->new( config => $config );
76$search->run( vars => \%vars, return_output => 1 );
77ok( !defined $search->{distance_in_metres},
78    "OSIE co-ords ignored when using British grid" );
79
80$q = CGI->new( "" );
81$q->param( -name => "latitude",     -value => 51  );
82$q->param( -name => "longitude",    -value => 1   );
83$q->param( -name => "os_dist",      -value => 500 );
84$q->param( -name => "osie_dist",    -value => 600 );
85$q->param( -name => "latlong_dist", -value => 700 );
86%vars = $q->Vars();
87$search = OpenGuides::Search->new( config => $config );
88$search->run( vars => \%vars, return_output => 1 );
89is( $search->{distance_in_metres}, 700,
90    "latlong_dist picked up when lat/long given and using British grid" );
91ok( defined $search->{x}, "...x set" );
92ok( defined $search->{y}, "...y set" );
93
94
95# Check the Irish National Grid case.
96$config->geo_handler( 2 );
97
98$q = CGI->new( "" );
99$q->param( -name => "osie_x",       -value => 500000 );
100$q->param( -name => "osie_y",       -value => 200000 );
101$q->param( -name => "os_dist",      -value => 500    );
102$q->param( -name => "osie_dist",    -value => 600    );
103$q->param( -name => "latlong_dist", -value => 700    );
104%vars = $q->Vars();
105$search = OpenGuides::Search->new( config => $config );
106$search->run( vars => \%vars, return_output => 1 );
107is( $search->{distance_in_metres}, 600,
108    "osie_dist picked up when OS co-ords given and using Irish grid" );
109is( $search->{x}, 500000, "...x set from osie_x" );
110is( $search->{y}, 200000, "...y set from osie_y" );
111
112$q = CGI->new( "" );
113$q->param( -name => "os_x",         -value => 500000 );
114$q->param( -name => "os_y",         -value => 200000 );
115$q->param( -name => "os_dist",      -value => 500    );
116$q->param( -name => "osie_dist",    -value => 600    );
117$q->param( -name => "latlong_dist", -value => 700    );
118%vars = $q->Vars();
119$search = OpenGuides::Search->new( config => $config );
120$search->run( vars => \%vars, return_output => 1 );
121ok( !defined $search->{distance_in_metres},
122    "OS co-ords ignored when using Irish grid" );
123
124$q = CGI->new( "" );
125$q->param( -name => "latitude",     -value => 55  );
126$q->param( -name => "longitude",    -value => -5  );
127$q->param( -name => "os_dist",      -value => 500 );
128$q->param( -name => "osie_dist",    -value => 600 );
129$q->param( -name => "latlong_dist", -value => 700 );
130%vars = $q->Vars();
131$search = OpenGuides::Search->new( config => $config );
132$search->run( vars => \%vars, return_output => 1 );
133is( $search->{distance_in_metres}, 700,
134    "latlong_dist picked up when lat/long given and using Irish grid" );
135ok( defined $search->{x}, "...x set" );
136ok( defined $search->{y}, "...y set" );
137
138
139# Check the UTM case.
140$config->geo_handler( 3 );
141$config->ellipsoid( "Airy" );
142
143$q = CGI->new( "" );
144$q->param( -name => "os_x",         -value => 500000 );
145$q->param( -name => "os_y",         -value => 200000 );
146$q->param( -name => "os_dist",      -value => 500    );
147$q->param( -name => "osie_dist",    -value => 600    );
148$q->param( -name => "latlong_dist", -value => 700    );
149%vars = $q->Vars();
150$search = OpenGuides::Search->new( config => $config );
151$search->run( vars => \%vars, return_output => 1 );
152ok( !defined $search->{distance_in_metres},
153    "OS co-ords ignored when using UTM" );
154
155$q = CGI->new( "" );
156$q->param( -name => "osie_x",       -value => 500000 );
157$q->param( -name => "osie_y",       -value => 200000 );
158$q->param( -name => "os_dist",      -value => 500    );
159$q->param( -name => "osie_dist",    -value => 600    );
160$q->param( -name => "latlong_dist", -value => 700    );
161%vars = $q->Vars();
162$search = OpenGuides::Search->new( config => $config );
163$search->run( vars => \%vars, return_output => 1 );
164ok( !defined $search->{distance_in_metres},
165    "OSIE co-ords ignored when using UTM" );
166
167$q = CGI->new( "" );
168$q->param( -name => "latitude",     -value => 51  );
169$q->param( -name => "longitude",    -value => 1   );
170$q->param( -name => "os_dist",      -value => 500 );
171$q->param( -name => "osie_dist",    -value => 600 );
172$q->param( -name => "latlong_dist", -value => 700 );
173%vars = $q->Vars();
174$search = OpenGuides::Search->new( config => $config );
175$search->run( vars => \%vars, return_output => 1 );
176is( $search->{distance_in_metres}, 700,
177    "latlong_dist picked up when lat/long given and using UTM" );
178ok( defined $search->{x}, "...x set" );
179ok( defined $search->{y}, "...y set" );
Note: See TracBrowser for help on using the browser.