| 1 | use strict; |
|---|
| 2 | use CGI::Wiki::Setup::SQLite; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | eval { require Plucene; }; |
|---|
| 13 | if ( $@ ) { |
|---|
| 14 | plan skip_all => "Plucene not installed"; |
|---|
| 15 | exit 0; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | eval { require Test::HTML::Content; }; |
|---|
| 19 | if ( $@ ) { |
|---|
| 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. |
|---|
| 28 | eval { require Geography::NationalGrid; }; |
|---|
| 29 | if ( $@ ) { |
|---|
| 30 | plan skip_all => "Geography::NationalGrid not installed"; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | eval { require Geo::Coordinates::UTM; }; |
|---|
| 34 | if ( $@ ) { |
|---|
| 35 | plan skip_all => "Geo::Coordinates::UTM not installed"; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | plan tests => 18; |
|---|
| 39 | |
|---|
| 40 | # Clear out the database from any previous runs. |
|---|
| 41 | unlink "t/node.db"; |
|---|
| 42 | unlink <t/indexes/*>; |
|---|
| 43 | |
|---|
| 44 | CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 45 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 46 | $config->use_plucene( 1 ); |
|---|
| 47 | |
|---|
| 48 | # British National Grid guides should have os_x/os_y fields. |
|---|
| 49 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 50 | my $wiki = $guide->wiki; |
|---|
| 51 | # Write some data. |
|---|
| 52 | OpenGuides::Test->write_data( |
|---|
| 53 | guide => $guide, |
|---|
| 54 | node => "Crabtree Tavern", |
|---|
| 55 | os_x => 523465, |
|---|
| 56 | os_y => 177490, |
|---|
| 57 | categories => "Pubs", |
|---|
| 58 | ); |
|---|
| 59 | my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" ); |
|---|
| 60 | # Set up the coord_field vars. |
|---|
| 61 | my %metadata_vars = OpenGuides::Template->extract_metadata_vars( |
|---|
| 62 | wiki => $wiki, |
|---|
| 63 | config => $config, |
|---|
| 64 | metadata => $data{metadata}, |
|---|
| 65 | ); |
|---|
| 66 | my $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; |
|---|
| 74 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, |
|---|
| 75 | "BNG defaults to 'os_x' input box..." ); |
|---|
| 76 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_x", |
|---|
| 77 | value => 523465 }, |
|---|
| 78 | "...with correct value..." ); |
|---|
| 79 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, |
|---|
| 80 | "...and 'os_y' input box" ); |
|---|
| 81 | Test::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) |
|---|
| 85 | like( $output, qr|OS\sX\scoordinate:|s, |
|---|
| 86 | "...'OS X coordinate:' label included" ); |
|---|
| 87 | like( $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. |
|---|
| 95 | OpenGuides::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; |
|---|
| 115 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, |
|---|
| 116 | "ING defaults to 'osie_x' input box..." ); |
|---|
| 117 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x", |
|---|
| 118 | value => 100000 }, |
|---|
| 119 | "...with correct value..." ); |
|---|
| 120 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, |
|---|
| 121 | "...and 'osie_y' input box" ); |
|---|
| 122 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y", |
|---|
| 123 | value => 200000 }, |
|---|
| 124 | "...with correct value..." ); |
|---|
| 125 | like( $output, qr|Irish\sNational\sGrid\sX\scoordinate:|s, |
|---|
| 126 | "...'Irish National Grid X coordinate:' label included" ); |
|---|
| 127 | like( $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. |
|---|
| 136 | OpenGuides::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; |
|---|
| 156 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, |
|---|
| 157 | "UTM defaults to 'latitude' input box..." ); |
|---|
| 158 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", |
|---|
| 159 | value => 51.502 }, |
|---|
| 160 | "...with correct value..." ); |
|---|
| 161 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, |
|---|
| 162 | "...and 'longitude' input box" ); |
|---|
| 163 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", |
|---|
| 164 | value => -0.118 }, |
|---|
| 165 | "...with correct value..." ); |
|---|
| 166 | like( $output, qr|Latitude \(decimal\):|s, |
|---|
| 167 | "...'Latitude (decimal):' label included" ); |
|---|
| 168 | like( $output, qr|Longitude \(decimal\):|s, |
|---|
| 169 | "...'Longitude (decimal):' label included" ); |
|---|