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