source: trunk/t/38_supersearch_params.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: 6.8 KB
Line 
1use strict;
2use CGI;
3use CGI::Wiki::Setup::SQLite;
4use Config::Tiny;
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 = Config::Tiny->new;
41$config->{_} = {
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# 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::SuperSearch->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::SuperSearch->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::SuperSearch->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; # Irish National Grid
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::SuperSearch->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::SuperSearch->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::SuperSearch->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; # UTM
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::SuperSearch->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::SuperSearch->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::SuperSearch->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 repository browser.