source: trunk/t/27_geo_data_edit_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: 7.1 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 => 18;
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 fields.
48my $guide = OpenGuides->new( config => $config );
49my $wiki = $guide->wiki;
50# Write some data.
51OpenGuides::Test->write_data(
52                              guide      => $guide,
53                              node       => "Crabtree Tavern",
54                              os_x       => 523465,
55                              os_y       => 177490,
56                              categories => "Pubs",
57                            );
58my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" );
59# Set up the coord_field vars.
60my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
61    wiki     => $wiki,
62    config   => $config,
63    metadata => $data{metadata},
64);
65my $output = OpenGuides::Template->output(
66                                           wiki     => $wiki,
67                                           config   => $config,
68                                           template => "edit_form.tt",
69                                           vars     => \%metadata_vars,
70                                         );
71# Strip Content-Type header to stop Test::HTML::Content getting confused.
72$output =~ s/^Content-Type.*[\r\n]+//m;
73Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" },
74                             "BNG defaults to 'os_x' input box..." );
75Test::HTML::Content::tag_ok( $output, "input", { name  => "os_x",
76                                                 value => 523465 },
77                             "...with correct value..." );
78Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" },
79                             "...and 'os_y' input box" );
80Test::HTML::Content::tag_ok( $output, "input", { name  => "os_y",
81                                                 value => 177490 },
82                             "...with correct value..." );
83# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check)
84like( $output, qr|OS\sX\scoordinate:|s,
85      "...'OS X coordinate:' label included" );
86like( $output, qr|OS\sY\scoordinate:|s,
87      "...'OS Y coordinate:' label included" );
88
89# Irish National Grid guides should have osie_x/osie_y fields.
90$config->geo_handler( 2 );
91$guide = OpenGuides->new( config => $config );
92$wiki = $guide->wiki;
93# Write some data.
94OpenGuides::Test->write_data(
95                              guide      => $guide,
96                              node       => "I Made This Place Up",
97                              osie_x     => 100000,
98                              osie_y     => 200000,
99                            );
100%data = $guide->wiki->retrieve_node( "I Made This Place Up" );
101# Set up the coord_field vars.
102%metadata_vars = OpenGuides::Template->extract_metadata_vars(
103    wiki     => $wiki,
104    config   => $config,
105    metadata => $data{metadata},
106);
107$output = OpenGuides::Template->output(
108                                        wiki     => $wiki,
109                                        config   => $config,
110                                        template => "edit_form.tt",
111                                        vars     => \%metadata_vars,
112                                      );
113$output =~ s/^Content-Type.*[\r\n]+//m;
114Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" },
115                             "ING defaults to 'osie_x' input box..." );
116Test::HTML::Content::tag_ok( $output, "input", { name  => "osie_x",
117                                                 value => 100000 },
118                             "...with correct value..." );
119Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" },
120                             "...and 'osie_y' input box" );
121Test::HTML::Content::tag_ok( $output, "input", { name  => "osie_y",
122                                                 value => 200000 },
123                             "...with correct value..." );
124like( $output, qr|Irish\sNational\sGrid\sX\scoordinate:|s,
125      "...'Irish National Grid X coordinate:' label included" );
126like( $output, qr|Irish\sNational\sGrid\sY\scoordinate:|s,
127      "...'Irish National Grid Y coordinate:' label included" );
128
129# UTM guides should have lat/long fields.
130$config->geo_handler( 3 );
131$config->ellipsoid( "Airy" );
132$guide = OpenGuides->new( config => $config );
133$wiki = $guide->wiki;
134# Write some data.
135OpenGuides::Test->write_data(
136                              guide     => $guide,
137                              node      => "London Aquarium",
138                              latitude  => 51.502,
139                              longitude => -0.118,
140                            );
141%data = $guide->wiki->retrieve_node( "London Aquarium" );
142# Set up the coord_field vars.
143%metadata_vars = OpenGuides::Template->extract_metadata_vars(
144    wiki     => $wiki,
145    config   => $config,
146    metadata => $data{metadata},
147);
148$output = OpenGuides::Template->output(
149                                        wiki     => $wiki,
150                                        config   => $config,
151                                        template => "edit_form.tt",
152                                        vars     => \%metadata_vars,
153                                      );
154$output =~ s/^Content-Type.*[\r\n]+//m;
155Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" },
156                             "UTM defaults to 'latitude' input box..." );
157Test::HTML::Content::tag_ok( $output, "input", { name  => "latitude",
158                                                 value => 51.502 },
159                             "...with correct value..." );
160Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" },
161                             "...and 'longitude' input box" );
162Test::HTML::Content::tag_ok( $output, "input", { name  => "longitude",
163                                                 value => -0.118 },
164                             "...with correct value..." );
165like( $output, qr|Latitude \(decimal\):|s,
166      "...'Latitude (decimal):' label included" );
167like( $output, qr|Longitude \(decimal\):|s,
168      "...'Longitude (decimal):' label included" );
Note: See TracBrowser for help on using the repository browser.