| 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 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | eval { require Plucene; }; |
|---|
| 13 | if ( $@ ) { |
|---|
| 14 | plan skip_all => "Plucene not installed"; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | eval { require Test::HTML::Content; }; |
|---|
| 18 | if ( $@ ) { |
|---|
| 19 | plan skip_all => "Test::HTML::Content not installed"; |
|---|
| 20 | exit 0; |
|---|
| 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 => 12; |
|---|
| 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/os_dist search fields. |
|---|
| 48 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 49 | |
|---|
| 50 | OpenGuides::Test->write_data( |
|---|
| 51 | guide => $guide, |
|---|
| 52 | node => "Banana Leaf", |
|---|
| 53 | os_x => 532125, |
|---|
| 54 | os_y => 165504, |
|---|
| 55 | ); |
|---|
| 56 | |
|---|
| 57 | # Display the node, check that the distance search form defaults to OS co-ords |
|---|
| 58 | # (stops places being "found" 70m away from themselves due to rounding). |
|---|
| 59 | my $output = $guide->display_node( |
|---|
| 60 | id => "Banana Leaf", |
|---|
| 61 | return_output => 1, |
|---|
| 62 | ); |
|---|
| 63 | |
|---|
| 64 | # Strip Content-Type header to stop Test::HTML::Content getting confused. |
|---|
| 65 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 66 | |
|---|
| 67 | Test::HTML::Content::tag_ok( $output, "select", { name => "os_dist" }, |
|---|
| 68 | "distance select defaults to os_dist with BNG" ); |
|---|
| 69 | # Use a regex; Test::HTML::Content can't do this yet I think (read docs, check) |
|---|
| 70 | like( $output, qr|select\sname="os_dist".*metres.*kilometres.*/select|is, |
|---|
| 71 | "...and to offering distances in metres/kilometres" ); |
|---|
| 72 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 73 | { name => "os_x", value => "532125" }, |
|---|
| 74 | "...includes input 'os_x' with correct value"); |
|---|
| 75 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 76 | { name => "os_y", value => "165504" }, |
|---|
| 77 | "...includes input 'os_y' with correct value"); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | # Irish National Grid guides should have osie_x/osie_y/osie_dist. |
|---|
| 81 | $config->geo_handler( 2 ); |
|---|
| 82 | $guide = OpenGuides->new( config => $config ); |
|---|
| 83 | |
|---|
| 84 | OpenGuides::Test->write_data( |
|---|
| 85 | guide => $guide, |
|---|
| 86 | node => "I Made This Place Up", |
|---|
| 87 | osie_x => 100000, |
|---|
| 88 | osie_y => 200000, |
|---|
| 89 | ); |
|---|
| 90 | |
|---|
| 91 | # Display node, check distance search form. |
|---|
| 92 | $output = $guide->display_node( |
|---|
| 93 | id => "I Made This Place Up", |
|---|
| 94 | return_output => 1, |
|---|
| 95 | ); |
|---|
| 96 | |
|---|
| 97 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 98 | |
|---|
| 99 | Test::HTML::Content::tag_ok( $output, "select", { name => "osie_dist" }, |
|---|
| 100 | "distance select defaults to osie_dist with ING"); |
|---|
| 101 | like( $output, qr|select\sname="osie_dist".*metres.*kilometres.*/select|is, |
|---|
| 102 | "...and to offering distances in metres/kilometres" ); |
|---|
| 103 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 104 | { name => "osie_x", value => "100000" }, |
|---|
| 105 | "...includes input 'osie_x' with correct value"); |
|---|
| 106 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 107 | { name => "osie_y", value => "200000" }, |
|---|
| 108 | "...includes input 'osie_y' with correct value"); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | # UTM guides should have latitude/longitude/latlong_dist. |
|---|
| 112 | $config->geo_handler( 3 ); |
|---|
| 113 | $config->ellipsoid( "Airy" ); |
|---|
| 114 | $guide = OpenGuides->new( config => $config ); |
|---|
| 115 | |
|---|
| 116 | OpenGuides::Test->write_data( |
|---|
| 117 | guide => $guide, |
|---|
| 118 | node => "London Aquarium", |
|---|
| 119 | latitude => 51.502, |
|---|
| 120 | longitude => -0.118, |
|---|
| 121 | ); |
|---|
| 122 | |
|---|
| 123 | # Display node, check distance search form. |
|---|
| 124 | # UTM guides currently use latitude/longitude for searching. |
|---|
| 125 | $output = $guide->display_node( |
|---|
| 126 | id => "London Aquarium", |
|---|
| 127 | return_output => 1, |
|---|
| 128 | ); |
|---|
| 129 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 130 | |
|---|
| 131 | Test::HTML::Content::tag_ok( $output, "select", { name => "latlong_dist" }, |
|---|
| 132 | "dist select defaults to latlong_dist with UTM" ); |
|---|
| 133 | like( $output, qr|select\sname="latlong_dist".*metres.*kilometres.*/select|is, |
|---|
| 134 | "...and to offering distances in metres/kilometres" ); |
|---|
| 135 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 136 | { name => "latitude", value => "51.502" }, |
|---|
| 137 | "...includes input 'latitude' with correct value"); |
|---|
| 138 | Test::HTML::Content::tag_ok( $output, "input", |
|---|
| 139 | { name => "longitude", value => "-0.118" }, |
|---|
| 140 | "...includes input 'longitude' with correct value"); |
|---|