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

Last change on this file since 594 was 594, checked in by Dominic Hargreaves, 17 years ago

Update tests so they pass without Plucene installed again (was affected by
config rejig).

  • 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; };
44if ( $@ ) { $config->use_plucene( 0 ) };
45
46my $guide = OpenGuides->new( config => $config );
47
48# Set preferences to have lat/long displayed in deg/min/sec.
49my $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
63OpenGuides::Test->write_data(
64                              guide      => $guide,
65                              node       => "Test Page",
66                              latitude   => 51.368,
67                              longitude  => -0.0973,
68                            );
69
70my %data = $guide->wiki->retrieve_node( "Test Page" );
71my $lat = $data{metadata}{latitude}[0];
72unlike( $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.
76my $output = $guide->display_node(
77                                   return_output => 1,
78                                   id => "Test Page",
79                                 );
80unlike( $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.
85eval {
86    local $SIG{__WARN__} = sub { die $_[0]; };
87    OpenGuides::Test->write_data(
88                                  guide      => $guide,
89                                  node       => "Locationless Page",
90                                );
91};
92is( $@, "",
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                              );
99unlike( $output, qr/latitude:/i,
100        "node with no location data doesn't display a latitude" );
Note: See TracBrowser for help on using the repository browser.