root/branches/new-install-process/t/66_bug_latlong_representation.t

Revision 956, 3.5 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1use strict;
2use CGI;
3use Wiki::Toolkit::Setup::SQLite;
4use OpenGuides::Config;
5use OpenGuides::CGI;
6use OpenGuides;
7use OpenGuides::Test;
8use Test::More;
9
10eval { require DBD::SQLite; };
11if ( $@ ) {
12    my ($error) = $@ =~ /^(.*?)\n/;
13    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
14}
15
16eval { require Geo::Coordinates::UTM; };
17if ( $@ ) {
18    plan skip_all => "Geo::Coordinates::UTM not installed";
19}
20
21plan tests => 4;
22
23# Clear out the database from any previous runs.
24unlink "t/node.db";
25unlink <t/indexes/*>;
26
27Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
28my $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.
44eval { require Wiki::Toolkit::Search::Plucene; };
45if ( $@ ) { $config->use_plucene( 0 ) };
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 browser.