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