source: trunk/t/38_supersearch_params.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: 6.8 KB
Line 
1use strict;
2use CGI;
3use CGI::Wiki::Setup::SQLite;
4use OpenGuides::Config;
5use OpenGuides::SuperSearch;
6use Test::More;
7
8eval { require DBD::SQLite; };
9if ( $@ ) {
10    plan skip_all => "DBD::SQLite not installed";
11    exit 0;
12}
13
14eval { require CGI::Wiki::Search::Plucene; };
15if ( $@ ) {
16    plan skip_all => "Plucene not installed";
17    exit 0;
18}
19
20# Strictly speaking we don't need to skip _all_ tests if we don't have
21# the modules below.  Revisit this when not in a hurry.
22# We only actually need them for the tests where lat/long are converted.
23eval { require Geography::NationalGrid; };
24if ( $@ ) {
25    plan skip_all => "Geography::NationalGrid not installed";
26}
27
28eval { require Geo::Coordinates::UTM; };
29if ( $@ ) {
30    plan skip_all => "Geo::Coordinates::UTM not installed";
31}
32
33plan tests => 19;
34
35# Clear out the database from any previous runs.
36unlink "t/node.db";
37unlink <t/indexes/*>;
38
39CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
40my $config = OpenGuides::Config->new(
41       vars => {
42                 dbtype             => "sqlite",
43                 dbname             => "t/node.db",
44                 indexing_directory => "t/indexes",
45                 script_name        => "wiki.cgi",
46                 script_url         => "http://example.com/",
47                 site_name          => "Test Site",
48                 template_path      => "./templates",
49                 use_plucene        => 1,
50                 geo_handler        => 1, # British National Grid
51               }
52);
53
54# Check the British National Grid case.
55my $q = CGI->new( "" );
56$q->param( -name => "os_x",         -value => 500000 );
57$q->param( -name => "os_y",         -value => 200000 );
58$q->param( -name => "os_dist",      -value => 500    );
59$q->param( -name => "osie_dist",    -value => 600    );
60$q->param( -name => "latlong_dist", -value => 700    );
61my %vars = $q->Vars();
62my $search = OpenGuides::SuperSearch->new( config => $config );
63$search->run( vars => \%vars, return_output => 1 );
64is( $search->{distance_in_metres}, 500,
65    "os_dist picked up when OS co-ords given and using British grid" );
66is( $search->{x}, 500000, "...x set from os_x" );
67is( $search->{y}, 200000, "...y set from os_y" );
68
69$q = CGI->new( "" );
70$q->param( -name => "osie_x",       -value => 500000 );
71$q->param( -name => "osie_y",       -value => 200000 );
72$q->param( -name => "os_dist",      -value => 500    );
73$q->param( -name => "osie_dist",    -value => 600    );
74$q->param( -name => "latlong_dist", -value => 700    );
75%vars = $q->Vars();
76$search = OpenGuides::SuperSearch->new( config => $config );
77$search->run( vars => \%vars, return_output => 1 );
78ok( !defined $search->{distance_in_metres},
79    "OSIE co-ords ignored when using British grid" );
80
81$q = CGI->new( "" );
82$q->param( -name => "latitude",     -value => 51  );
83$q->param( -name => "longitude",    -value => 1   );
84$q->param( -name => "os_dist",      -value => 500 );
85$q->param( -name => "osie_dist",    -value => 600 );
86$q->param( -name => "latlong_dist", -value => 700 );
87%vars = $q->Vars();
88$search = OpenGuides::SuperSearch->new( config => $config );
89$search->run( vars => \%vars, return_output => 1 );
90is( $search->{distance_in_metres}, 700,
91    "latlong_dist picked up when lat/long given and using British grid" );
92ok( defined $search->{x}, "...x set" );
93ok( defined $search->{y}, "...y set" );
94
95
96# Check the Irish National Grid case.
97$config->geo_handler( 2 );
98
99$q = CGI->new( "" );
100$q->param( -name => "osie_x",       -value => 500000 );
101$q->param( -name => "osie_y",       -value => 200000 );
102$q->param( -name => "os_dist",      -value => 500    );
103$q->param( -name => "osie_dist",    -value => 600    );
104$q->param( -name => "latlong_dist", -value => 700    );
105%vars = $q->Vars();
106$search = OpenGuides::SuperSearch->new( config => $config );
107$search->run( vars => \%vars, return_output => 1 );
108is( $search->{distance_in_metres}, 600,
109    "osie_dist picked up when OS co-ords given and using Irish grid" );
110is( $search->{x}, 500000, "...x set from osie_x" );
111is( $search->{y}, 200000, "...y set from osie_y" );
112
113$q = CGI->new( "" );
114$q->param( -name => "os_x",         -value => 500000 );
115$q->param( -name => "os_y",         -value => 200000 );
116$q->param( -name => "os_dist",      -value => 500    );
117$q->param( -name => "osie_dist",    -value => 600    );
118$q->param( -name => "latlong_dist", -value => 700    );
119%vars = $q->Vars();
120$search = OpenGuides::SuperSearch->new( config => $config );
121$search->run( vars => \%vars, return_output => 1 );
122ok( !defined $search->{distance_in_metres},
123    "OS co-ords ignored when using Irish grid" );
124
125$q = CGI->new( "" );
126$q->param( -name => "latitude",     -value => 55  );
127$q->param( -name => "longitude",    -value => -5  );
128$q->param( -name => "os_dist",      -value => 500 );
129$q->param( -name => "osie_dist",    -value => 600 );
130$q->param( -name => "latlong_dist", -value => 700 );
131%vars = $q->Vars();
132$search = OpenGuides::SuperSearch->new( config => $config );
133$search->run( vars => \%vars, return_output => 1 );
134is( $search->{distance_in_metres}, 700,
135    "latlong_dist picked up when lat/long given and using Irish grid" );
136ok( defined $search->{x}, "...x set" );
137ok( defined $search->{y}, "...y set" );
138
139
140# Check the UTM case.
141$config->geo_handler( 3 );
142$config->ellipsoid( "Airy" );
143
144$q = CGI->new( "" );
145$q->param( -name => "os_x",         -value => 500000 );
146$q->param( -name => "os_y",         -value => 200000 );
147$q->param( -name => "os_dist",      -value => 500    );
148$q->param( -name => "osie_dist",    -value => 600    );
149$q->param( -name => "latlong_dist", -value => 700    );
150%vars = $q->Vars();
151$search = OpenGuides::SuperSearch->new( config => $config );
152$search->run( vars => \%vars, return_output => 1 );
153ok( !defined $search->{distance_in_metres},
154    "OS co-ords ignored when using UTM" );
155
156$q = CGI->new( "" );
157$q->param( -name => "osie_x",       -value => 500000 );
158$q->param( -name => "osie_y",       -value => 200000 );
159$q->param( -name => "os_dist",      -value => 500    );
160$q->param( -name => "osie_dist",    -value => 600    );
161$q->param( -name => "latlong_dist", -value => 700    );
162%vars = $q->Vars();
163$search = OpenGuides::SuperSearch->new( config => $config );
164$search->run( vars => \%vars, return_output => 1 );
165ok( !defined $search->{distance_in_metres},
166    "OSIE co-ords ignored when using UTM" );
167
168$q = CGI->new( "" );
169$q->param( -name => "latitude",     -value => 51  );
170$q->param( -name => "longitude",    -value => 1   );
171$q->param( -name => "os_dist",      -value => 500 );
172$q->param( -name => "osie_dist",    -value => 600 );
173$q->param( -name => "latlong_dist", -value => 700 );
174%vars = $q->Vars();
175$search = OpenGuides::SuperSearch->new( config => $config );
176$search->run( vars => \%vars, return_output => 1 );
177is( $search->{distance_in_metres}, 700,
178    "latlong_dist picked up when lat/long given and using UTM" );
179ok( defined $search->{x}, "...x set" );
180ok( defined $search->{y}, "...y set" );
Note: See TracBrowser for help on using the repository browser.