source: trunk/t/25_write_geo_data.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: 8.1 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides;
5use OpenGuides::Test;
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 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 the former for the National Grid tests and the
22# latter for the UTM tests.
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 => 53;
34
35# Clear out the database from any previous runs.
36unlink "t/node.db";
37unlink <t/indexes/*>;
38
39Wiki::Toolkit::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,
51               }
52);
53
54# First check that British National Grid will accept both OS X/Y and lat/long,
55# and will store both however the data was given to it.
56my $guide = OpenGuides->new( config => $config );
57is( $guide->locator->x_field, "os_x", "correct x field" );
58is( $guide->locator->y_field, "os_y", "correct y field" );
59
60OpenGuides::Test->write_data(
61                              guide      => $guide,
62                              node       => "Crabtree Tavern",
63                              os_x       => 523465,
64                              os_y       => 177490,
65                              categories => "Pubs",
66                            );
67my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" );
68is( $data{metadata}{os_x}[0], 523465,      "os_x stored correctly" );
69is( $data{metadata}{os_y}[0], 177490,      "os_y stored correctly" );
70ok( defined $data{metadata}{latitude}[0],  "latitude stored" );
71ok( defined $data{metadata}{longitude}[0], "longitude stored" );
72
73OpenGuides::Test->write_data(
74                              guide      => $guide,
75                              node       => "El Sombrero",
76                              latitude   => 51.368,
77                              longitude  => -0.097,
78                              categories => "Restaurants",
79                            );
80%data = $guide->wiki->retrieve_node( "El Sombrero" );
81ok( defined $data{metadata}{os_x}[0],      "os_x stored" );
82like( $data{metadata}{os_x}[0], qr/^\d+$/,  "...as integer" );
83ok( defined $data{metadata}{os_y}[0],      "os_y stored" );
84like( $data{metadata}{os_y}[0], qr/^\d+$/,  "...as integer" );
85is( $data{metadata}{latitude}[0], 51.368,  "latitude stored correctly" );
86is( $data{metadata}{longitude}[0], -0.097, "longitude stored correctly" );
87
88eval {
89    local $SIG{__WARN__} = sub { die $_[0]; };
90    OpenGuides::Test->write_data(
91                                  guide      => $guide,
92                                  node       => "Locationless Page 1",
93                                );
94};
95is( $@, "",
96    "commit doesn't warn when using BNG and node has no location data" );
97%data = $guide->wiki->retrieve_node( "Locationless Page 1" );
98ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
99ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
100ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
101ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
102ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
103ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
104
105# Now check Irish National Grid.
106$config->geo_handler( 2 );
107$guide = OpenGuides->new( config => $config );
108is( $guide->locator->x_field, "osie_x", "correct x field" );
109is( $guide->locator->y_field, "osie_y", "correct y field" );
110
111OpenGuides::Test->write_data(
112                              guide      => $guide,
113                              node       => "I Made This Place Up",
114                              osie_x     => 100000,
115                              osie_y     => 200000,
116                            );
117%data = $guide->wiki->retrieve_node( "I Made This Place Up" );
118is( $data{metadata}{osie_x}[0], 100000,    "osie_x stored correctly" );
119is( $data{metadata}{osie_y}[0], 200000,    "osie_y stored correctly" );
120ok( defined $data{metadata}{latitude}[0],  "latitude stored" );
121ok( defined $data{metadata}{longitude}[0], "longitude stored" );
122
123OpenGuides::Test->write_data(
124                              guide      => $guide,
125                              node       => "Brambles Coffee Shop",
126                              latitude   => 54.6434,
127                              longitude  => -5.6731,
128                             );
129%data = $guide->wiki->retrieve_node( "Brambles Coffee Shop" );
130ok( defined $data{metadata}{osie_x}[0],     "osie_x stored" );
131like( $data{metadata}{osie_x}[0], qr/^\d+$/,  "...as integer" );
132ok( defined $data{metadata}{osie_y}[0],     "osie_y stored" );
133like( $data{metadata}{osie_y}[0], qr/^\d+$/,  "...as integer" );
134is( $data{metadata}{latitude}[0], 54.6434,  "latitude stored correctly" );
135is( $data{metadata}{longitude}[0], -5.6731, "longitude stored correctly" );
136
137eval {
138    local $SIG{__WARN__} = sub { die $_[0]; };
139    OpenGuides::Test->write_data(
140                                  guide      => $guide,
141                                  node       => "Locationless Page 2",
142                                );
143};
144is( $@, "",
145    "commit doesn't warn when using ING and node has no location data" );
146%data = $guide->wiki->retrieve_node( "Locationless Page 2" );
147ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
148ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
149ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
150ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
151ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
152ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
153
154# Finally check UTM.
155$config->geo_handler( 3 );
156$config->ellipsoid( "Airy" );
157$guide = OpenGuides->new( config => $config );
158is( $guide->locator->x_field, "easting", "correct x field" );
159is( $guide->locator->y_field, "northing", "correct y field" );
160
161OpenGuides::Test->write_data(
162                              guide      => $guide,
163                              node       => "London Aquarium",
164                              latitude   => 51.502,
165                              longitude  => -0.118,
166                            );
167%data = $guide->wiki->retrieve_node( "London Aquarium" );
168ok( defined $data{metadata}{easting}[0],       "easting stored" );
169like( $data{metadata}{easting}[0], qr/^\d+$/,  "...as integer" );
170ok( defined $data{metadata}{northing}[0],      "northing stored" );
171like( $data{metadata}{northing}[0], qr/^\d+$/, "...as integer" );
172is( $data{metadata}{latitude}[0], 51.502,      "latitude stored correctly" );
173is( $data{metadata}{longitude}[0], -0.118,     "longitude stored correctly" );
174
175eval {
176    local $SIG{__WARN__} = sub { die $_[0]; };
177    OpenGuides::Test->write_data(
178                                  guide      => $guide,
179                                  node       => "Locationless Page 3",
180                                );
181};
182is( $@, "",
183    "commit doesn't warn when using UTM and node has no location data" );
184%data = $guide->wiki->retrieve_node( "Locationless Page 3" );
185ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
186ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
187ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
188ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
189ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
190ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
Note: See TracBrowser for help on using the repository browser.