source: trunk/t/26_geo_data_search_form.t @ 956

Last change on this file since 956 was 956, checked in by Earle Martin, 15 years 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
File size: 5.5 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
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
18eval { require Test::HTML::Content; };
19if ( $@ ) {
20    plan skip_all => "Test::HTML::Content not installed";
21}
22
23# Strictly speaking we don't need to skip _all_ tests if we don't have
24# the modules below.  Revisit this when not in a hurry.
25# We only actually need the former for the National Grid tests and the
26# latter for the UTM tests.
27eval { require Geography::NationalGrid; };
28if ( $@ ) {
29    plan skip_all => "Geography::NationalGrid not installed";
30}
31
32eval { require Geo::Coordinates::UTM; };
33if ( $@ ) {
34    plan skip_all => "Geo::Coordinates::UTM not installed";
35}
36
37plan tests => 12;
38
39# Clear out the database from any previous runs.
40unlink "t/node.db";
41unlink <t/indexes/*>;
42
43Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
44my $config = OpenGuides::Test->make_basic_config;
45$config->use_plucene( 1 );
46
47# British National Grid guides should have os_x/os_y/os_dist search fields.
48my $guide = OpenGuides->new( config => $config );
49
50OpenGuides::Test->write_data(
51                              guide => $guide,
52                              node  => "Banana Leaf",
53                              os_x  => 532125,
54                              os_y  => 165504,
55                            );
56
57# Display the node, check that the distance search form defaults to OS co-ords
58# (stops places being "found" 70m away from themselves due to rounding).
59my $output = $guide->display_node(
60                                   id => "Banana Leaf",
61                                   return_output => 1,
62                                 );
63
64# Strip Content-Type header to stop Test::HTML::Content getting confused.
65$output =~ s/^Content-Type.*[\r\n]+//m;
66
67Test::HTML::Content::tag_ok( $output, "select", { name => "os_dist" },
68                             "distance select defaults to os_dist with BNG" );
69# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check)
70like( $output, qr|select\sname="os_dist".*metres.*kilometres.*/select|is,
71      "...and to offering distances in metres/kilometres" );
72Test::HTML::Content::tag_ok( $output, "input",
73                             { name => "os_x", value => "532125" },
74                             "...includes input 'os_x' with correct value");
75Test::HTML::Content::tag_ok( $output, "input",
76                             { name => "os_y", value => "165504" },
77                             "...includes input 'os_y' with correct value");
78
79
80# Irish National Grid guides should have osie_x/osie_y/osie_dist.
81$config->geo_handler( 2 );
82$guide = OpenGuides->new( config => $config );
83
84OpenGuides::Test->write_data(
85                              guide  => $guide,
86                              node   => "I Made This Place Up",
87                              osie_x => 100000,
88                              osie_y => 200000,
89                            );
90
91# Display node, check distance search form.
92$output = $guide->display_node(
93                                id => "I Made This Place Up",
94                                return_output => 1,
95                              );
96
97$output =~ s/^Content-Type.*[\r\n]+//m;
98
99Test::HTML::Content::tag_ok( $output, "select", { name => "osie_dist" },
100                             "distance select defaults to osie_dist with ING");
101like( $output, qr|select\sname="osie_dist".*metres.*kilometres.*/select|is,
102      "...and to offering distances in metres/kilometres" );
103Test::HTML::Content::tag_ok( $output, "input",
104                             { name => "osie_x", value => "100000" },
105                             "...includes input 'osie_x' with correct value");
106Test::HTML::Content::tag_ok( $output, "input",
107                             { name => "osie_y", value => "200000" },
108                             "...includes input 'osie_y' with correct value");
109
110
111# UTM guides should have latitude/longitude/latlong_dist.
112$config->geo_handler( 3 );
113$config->ellipsoid( "Airy" );
114$guide = OpenGuides->new( config => $config );
115
116OpenGuides::Test->write_data(
117                              guide     => $guide,
118                              node      => "London Aquarium",
119                              latitude  => 51.502,
120                              longitude => -0.118,
121                            );
122
123# Display node, check distance search form.
124# UTM guides currently use latitude/longitude for searching.
125$output = $guide->display_node(
126                                id => "London Aquarium",
127                                return_output => 1,
128                              );
129$output =~ s/^Content-Type.*[\r\n]+//m;
130
131Test::HTML::Content::tag_ok( $output, "select", { name => "latlong_dist" },
132                             "dist select defaults to latlong_dist with UTM" );
133like( $output, qr|select\sname="latlong_dist".*metres.*kilometres.*/select|is,
134      "...and to offering distances in metres/kilometres" );
135Test::HTML::Content::tag_ok( $output, "input",
136                             { name => "latitude", value => "51.502" },
137                             "...includes input 'latitude' with correct value");
138Test::HTML::Content::tag_ok( $output, "input",
139                             { name => "longitude", value => "-0.118" },
140                             "...includes input 'longitude' with correct value");
Note: See TracBrowser for help on using the repository browser.