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

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

Pull out common testing code into OpenGuides::Test

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