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

Last change on this file since 562 was 562, checked in by kake, 17 years ago

Pull out common testing code into OpenGuides::Test

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