source: trunk/t/66_bug_latlong_representation.t @ 587

Last change on this file since 587 was 587, checked in by kake, 17 years ago

Encapsulate config data in OpenGuides::Config.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1use strict;
2use CGI;
3use CGI::Wiki::Setup::SQLite;
4use OpenGuides::Config;
5use OpenGuides::CGI;
6use OpenGuides;
7use OpenGuides::Test;
8use Test::More;
9
10eval { require DBD::SQLite; };
11if ( $@ ) {
12    plan skip_all => "DBD::SQLite not installed";
13}
14
15eval { require Geo::Coordinates::UTM; };
16if ( $@ ) {
17    plan skip_all => "Geo::Coordinates::UTM not installed";
18}
19
20plan tests => 4;
21
22# Clear out the database from any previous runs.
23unlink "t/node.db";
24unlink <t/indexes/*>;
25
26CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
27my $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.
43eval { require CGI::Wiki::Search::Plucene; };
44unless ( $@ ) {
45    $config->use_plucene( 1 );
46}
47
48my $guide = OpenGuides->new( config => $config );
49
50# Set preferences to have lat/long displayed in deg/min/sec.
51my $cookie = OpenGuides::CGI->make_prefs_cookie(
52    config                     => $config,
53    username                   => "Kake",
54    include_geocache_link      => 1,
55    preview_above_edit_box     => 1,
56    latlong_traditional        => 1,  # this is the important bit
57    omit_help_links            => 1,
58    show_minor_edits_in_rc     => 1,
59    default_edit_type          => "tidying",
60    cookie_expires             => "never",
61    track_recent_changes_views => 1,
62);
63$ENV{HTTP_COOKIE} = $cookie;
64
65OpenGuides::Test->write_data(
66                              guide      => $guide,
67                              node       => "Test Page",
68                              latitude   => 51.368,
69                              longitude  => -0.0973,
70                            );
71
72my %data = $guide->wiki->retrieve_node( "Test Page" );
73my $lat = $data{metadata}{latitude}[0];
74unlike( $lat, qr/d/,
75    "lat not stored in dms format even if prefs set to display that way" );
76
77# Check the distance search form has unmunged lat/long.
78my $output = $guide->display_node(
79                                   return_output => 1,
80                                   id => "Test Page",
81                                 );
82unlike( $output, qr/name="latitude"\svalue="[-0-9]*d/,
83        "latitude in non-dms format in distance search form" );
84
85# Now write a node with no location data, and check that it doesn't
86# claim to have any when we display it.
87eval {
88    local $SIG{__WARN__} = sub { die $_[0]; };
89    OpenGuides::Test->write_data(
90                                  guide      => $guide,
91                                  node       => "Locationless Page",
92                                );
93};
94is( $@, "",
95    "commit doesn't warn when prefs say dms format and node has no loc data" );
96
97$output = $guide->display_node(
98                                return_output => 1,
99                                id => "Locationless Page",
100                              );
101unlike( $output, qr/latitude:/i,
102        "node with no location data doesn't display a latitude" );
Note: See TracBrowser for help on using the repository browser.