source: trunk/t/25_write_geo_data.t @ 785

Last change on this file since 785 was 785, checked in by Dominic Hargreaves, 15 years ago

Use Wiki::Toolkit. Note that CGI::Wiki::Plugin::Diff hasn't been converted yet,
so tests will be broken for now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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    plan skip_all => "DBD::SQLite not installed";
11}
12
13eval { require Plucene; };
14if ( $@ ) {
15    plan skip_all => "Plucene not installed";
16}
17
18# Strictly speaking we don't need to skip _all_ tests if we don't have
19# the modules below.  Revisit this when not in a hurry.
20# We only actually need the former for the National Grid tests and the
21# latter for the UTM tests.
22eval { require Geography::NationalGrid; };
23if ( $@ ) {
24    plan skip_all => "Geography::NationalGrid not installed";
25}
26
27eval { require Geo::Coordinates::UTM; };
28if ( $@ ) {
29    plan skip_all => "Geo::Coordinates::UTM not installed";
30}
31
32plan tests => 53;
33
34# Clear out the database from any previous runs.
35unlink "t/node.db";
36unlink <t/indexes/*>;
37
38Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
39my $config = OpenGuides::Config->new(
40       vars => {
41                 dbtype             => "sqlite",
42                 dbname             => "t/node.db",
43                 indexing_directory => "t/indexes",
44                 script_name        => "wiki.cgi",
45                 script_url         => "http://example.com/",
46                 site_name          => "Test Site",
47                 template_path      => "./templates",
48                 use_plucene        => 1,
49                 geo_handler        => 1,
50               }
51);
52
53# First check that British National Grid will accept both OS X/Y and lat/long,
54# and will store both however the data was given to it.
55my $guide = OpenGuides->new( config => $config );
56is( $guide->locator->x_field, "os_x", "correct x field" );
57is( $guide->locator->y_field, "os_y", "correct y field" );
58
59OpenGuides::Test->write_data(
60                              guide      => $guide,
61                              node       => "Crabtree Tavern",
62                              os_x       => 523465,
63                              os_y       => 177490,
64                              categories => "Pubs",
65                            );
66my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" );
67is( $data{metadata}{os_x}[0], 523465,      "os_x stored correctly" );
68is( $data{metadata}{os_y}[0], 177490,      "os_y stored correctly" );
69ok( defined $data{metadata}{latitude}[0],  "latitude stored" );
70ok( defined $data{metadata}{longitude}[0], "longitude stored" );
71
72OpenGuides::Test->write_data(
73                              guide      => $guide,
74                              node       => "El Sombrero",
75                              latitude   => 51.368,
76                              longitude  => -0.097,
77                              categories => "Restaurants",
78                            );
79%data = $guide->wiki->retrieve_node( "El Sombrero" );
80ok( defined $data{metadata}{os_x}[0],      "os_x stored" );
81like( $data{metadata}{os_x}[0], qr/^\d+$/,  "...as integer" );
82ok( defined $data{metadata}{os_y}[0],      "os_y stored" );
83like( $data{metadata}{os_y}[0], qr/^\d+$/,  "...as integer" );
84is( $data{metadata}{latitude}[0], 51.368,  "latitude stored correctly" );
85is( $data{metadata}{longitude}[0], -0.097, "longitude stored correctly" );
86
87eval {
88    local $SIG{__WARN__} = sub { die $_[0]; };
89    OpenGuides::Test->write_data(
90                                  guide      => $guide,
91                                  node       => "Locationless Page 1",
92                                );
93};
94is( $@, "",
95    "commit doesn't warn when using BNG and node has no location data" );
96%data = $guide->wiki->retrieve_node( "Locationless Page 1" );
97ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
98ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
99ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
100ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
101ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
102ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
103
104# Now check Irish National Grid.
105$config->geo_handler( 2 );
106$guide = OpenGuides->new( config => $config );
107is( $guide->locator->x_field, "osie_x", "correct x field" );
108is( $guide->locator->y_field, "osie_y", "correct y field" );
109
110OpenGuides::Test->write_data(
111                              guide      => $guide,
112                              node       => "I Made This Place Up",
113                              osie_x     => 100000,
114                              osie_y     => 200000,
115                            );
116%data = $guide->wiki->retrieve_node( "I Made This Place Up" );
117is( $data{metadata}{osie_x}[0], 100000,    "osie_x stored correctly" );
118is( $data{metadata}{osie_y}[0], 200000,    "osie_y stored correctly" );
119ok( defined $data{metadata}{latitude}[0],  "latitude stored" );
120ok( defined $data{metadata}{longitude}[0], "longitude stored" );
121
122OpenGuides::Test->write_data(
123                              guide      => $guide,
124                              node       => "Brambles Coffee Shop",
125                              latitude   => 54.6434,
126                              longitude  => -5.6731,
127                             );
128%data = $guide->wiki->retrieve_node( "Brambles Coffee Shop" );
129ok( defined $data{metadata}{osie_x}[0],     "osie_x stored" );
130like( $data{metadata}{osie_x}[0], qr/^\d+$/,  "...as integer" );
131ok( defined $data{metadata}{osie_y}[0],     "osie_y stored" );
132like( $data{metadata}{osie_y}[0], qr/^\d+$/,  "...as integer" );
133is( $data{metadata}{latitude}[0], 54.6434,  "latitude stored correctly" );
134is( $data{metadata}{longitude}[0], -5.6731, "longitude stored correctly" );
135
136eval {
137    local $SIG{__WARN__} = sub { die $_[0]; };
138    OpenGuides::Test->write_data(
139                                  guide      => $guide,
140                                  node       => "Locationless Page 2",
141                                );
142};
143is( $@, "",
144    "commit doesn't warn when using ING and node has no location data" );
145%data = $guide->wiki->retrieve_node( "Locationless Page 2" );
146ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
147ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
148ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
149ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
150ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
151ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
152
153# Finally check UTM.
154$config->geo_handler( 3 );
155$config->ellipsoid( "Airy" );
156$guide = OpenGuides->new( config => $config );
157is( $guide->locator->x_field, "easting", "correct x field" );
158is( $guide->locator->y_field, "northing", "correct y field" );
159
160OpenGuides::Test->write_data(
161                              guide      => $guide,
162                              node       => "London Aquarium",
163                              latitude   => 51.502,
164                              longitude  => -0.118,
165                            );
166%data = $guide->wiki->retrieve_node( "London Aquarium" );
167ok( defined $data{metadata}{easting}[0],       "easting stored" );
168like( $data{metadata}{easting}[0], qr/^\d+$/,  "...as integer" );
169ok( defined $data{metadata}{northing}[0],      "northing stored" );
170like( $data{metadata}{northing}[0], qr/^\d+$/, "...as integer" );
171is( $data{metadata}{latitude}[0], 51.502,      "latitude stored correctly" );
172is( $data{metadata}{longitude}[0], -0.118,     "longitude stored correctly" );
173
174eval {
175    local $SIG{__WARN__} = sub { die $_[0]; };
176    OpenGuides::Test->write_data(
177                                  guide      => $guide,
178                                  node       => "Locationless Page 3",
179                                );
180};
181is( $@, "",
182    "commit doesn't warn when using UTM and node has no location data" );
183%data = $guide->wiki->retrieve_node( "Locationless Page 3" );
184ok( !defined $data{metadata}{latitude}[0],  "...and latitude not stored" );
185ok( !defined $data{metadata}{longitude}[0], "...nor longitude" );
186ok( !defined $data{metadata}{os_x}[0],      "...nor os_x" );
187ok( !defined $data{metadata}{os_y}[0],      "...nor os_y" );
188ok( !defined $data{metadata}{osie_x}[0],    "...nor osie_x" );
189ok( !defined $data{metadata}{osie_y}[0],    "...nor osie_y" );
Note: See TracBrowser for help on using the repository browser.