| 1 | use strict; |
|---|
| 2 | use CGI; |
|---|
| 3 | use CGI::Wiki::Setup::SQLite; |
|---|
| 4 | use OpenGuides::Config; |
|---|
| 5 | use OpenGuides::CGI; |
|---|
| 6 | use OpenGuides; |
|---|
| 7 | use OpenGuides::Test; |
|---|
| 8 | use Test::More; |
|---|
| 9 | |
|---|
| 10 | eval { require DBD::SQLite; }; |
|---|
| 11 | if ( $@ ) { |
|---|
| 12 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | eval { require Geo::Coordinates::UTM; }; |
|---|
| 16 | if ( $@ ) { |
|---|
| 17 | plan skip_all => "Geo::Coordinates::UTM not installed"; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | plan tests => 4; |
|---|
| 21 | |
|---|
| 22 | # Clear out the database from any previous runs. |
|---|
| 23 | unlink "t/node.db"; |
|---|
| 24 | unlink <t/indexes/*>; |
|---|
| 25 | |
|---|
| 26 | CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 27 | my $config = OpenGuides::Config->new( |
|---|
| 28 | vars => { |
|---|
| 29 | dbtype => "sqlite", |
|---|
| 30 | dbname => "t/node.db", |
|---|
| 31 | indexing_directory => "t/indexes", |
|---|
| 32 | script_name => "wiki.cgi", |
|---|
| 33 | script_url => "http://example.com/", |
|---|
| 34 | site_name => "Test Site", |
|---|
| 35 | template_path => "./templates", |
|---|
| 36 | home_name => "Home", |
|---|
| 37 | geo_handler => 3, # Test w/ UTM - nat grids use X/Y |
|---|
| 38 | ellipsoid => "Airy", |
|---|
| 39 | } |
|---|
| 40 | ); |
|---|
| 41 | |
|---|
| 42 | # Plucene is the recommended searcher now. |
|---|
| 43 | eval { require CGI::Wiki::Search::Plucene; }; |
|---|
| 44 | if ( $@ ) { $config->use_plucene( 0 ) }; |
|---|
| 45 | |
|---|
| 46 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 47 | |
|---|
| 48 | # Set preferences to have lat/long displayed in deg/min/sec. |
|---|
| 49 | my $cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 50 | config => $config, |
|---|
| 51 | username => "Kake", |
|---|
| 52 | include_geocache_link => 1, |
|---|
| 53 | preview_above_edit_box => 1, |
|---|
| 54 | latlong_traditional => 1, # this is the important bit |
|---|
| 55 | omit_help_links => 1, |
|---|
| 56 | show_minor_edits_in_rc => 1, |
|---|
| 57 | default_edit_type => "tidying", |
|---|
| 58 | cookie_expires => "never", |
|---|
| 59 | track_recent_changes_views => 1, |
|---|
| 60 | ); |
|---|
| 61 | $ENV{HTTP_COOKIE} = $cookie; |
|---|
| 62 | |
|---|
| 63 | OpenGuides::Test->write_data( |
|---|
| 64 | guide => $guide, |
|---|
| 65 | node => "Test Page", |
|---|
| 66 | latitude => 51.368, |
|---|
| 67 | longitude => -0.0973, |
|---|
| 68 | ); |
|---|
| 69 | |
|---|
| 70 | my %data = $guide->wiki->retrieve_node( "Test Page" ); |
|---|
| 71 | my $lat = $data{metadata}{latitude}[0]; |
|---|
| 72 | unlike( $lat, qr/d/, |
|---|
| 73 | "lat not stored in dms format even if prefs set to display that way" ); |
|---|
| 74 | |
|---|
| 75 | # Check the distance search form has unmunged lat/long. |
|---|
| 76 | my $output = $guide->display_node( |
|---|
| 77 | return_output => 1, |
|---|
| 78 | id => "Test Page", |
|---|
| 79 | ); |
|---|
| 80 | unlike( $output, qr/name="latitude"\svalue="[-0-9]*d/, |
|---|
| 81 | "latitude in non-dms format in distance search form" ); |
|---|
| 82 | |
|---|
| 83 | # Now write a node with no location data, and check that it doesn't |
|---|
| 84 | # claim to have any when we display it. |
|---|
| 85 | eval { |
|---|
| 86 | local $SIG{__WARN__} = sub { die $_[0]; }; |
|---|
| 87 | OpenGuides::Test->write_data( |
|---|
| 88 | guide => $guide, |
|---|
| 89 | node => "Locationless Page", |
|---|
| 90 | ); |
|---|
| 91 | }; |
|---|
| 92 | is( $@, "", |
|---|
| 93 | "commit doesn't warn when prefs say dms format and node has no loc data" ); |
|---|
| 94 | |
|---|
| 95 | $output = $guide->display_node( |
|---|
| 96 | return_output => 1, |
|---|
| 97 | id => "Locationless Page", |
|---|
| 98 | ); |
|---|
| 99 | unlike( $output, qr/latitude:/i, |
|---|
| 100 | "node with no location data doesn't display a latitude" ); |
|---|