source: trunk/t/27_geo_data_edit_form.t @ 579

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

Update UTM edit form label tests in line with code changes.

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