source: trunk/t/62_bug_trailing_whitespace.t @ 956

Last change on this file since 956 was 956, checked in by Earle Martin, 15 years 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
File size: 3.5 KB
Line 
1use Wiki::Toolkit::Setup::SQLite;
2use OpenGuides::Config;
3use OpenGuides;
4use OpenGuides::Template;
5use OpenGuides::Test;
6use Test::More;
7
8eval { require DBD::SQLite; };
9
10if ( $@ ) {
11    my ($error) = $@ =~ /^(.*?)\n/;
12    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
13}
14
15plan tests => 8;
16
17# Clear out the database from any previous runs.
18unlink "t/node.db";
19unlink <t/indexes/*>;
20Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
21
22my $config = OpenGuides::Test->make_basic_config;
23my $guide = OpenGuides->new( config => $config );
24
25SKIP: {
26    eval { require Geography::NationalGrid::GB; };
27    skip "Geography::NationalGrid::GB not installed", 2 if $@;
28
29    my $q = CGI->new( "" );
30    $q->param( -name => "os_x", -value => " 123456 " );
31    $q->param( -name => "os_y", -value => " 654321 " );
32    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
33    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
34
35    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
36        wiki    => $guide->wiki,
37        config  => $config,
38        cgi_obj => $q,
39    );
40
41    is( $metadata_vars{os_x}, "123456",
42        "leading and trailing spaces stripped from os_x when processed" );
43    is( $metadata_vars{os_y}, "654321", "...and os_y" );
44}
45
46SKIP: {
47    eval { require Geography::NationalGrid::IE; };
48    skip "Geography::NationalGrid::IE not installed", 2 if $@;
49
50    $config->geo_handler( 2 );
51    my $q = CGI->new( "" );
52    $q->param( -name => "osie_x", -value => " 100000 " );
53    $q->param( -name => "osie_y", -value => " 200000 " );
54    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
55    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
56
57    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
58        wiki    => $guide->wiki,
59        config  => $config,
60        cgi_obj => $q,
61    );
62
63    is( $metadata_vars{osie_x}, "100000",
64        "leading and trailing spaces stripped from osie_x when processed" );
65    is( $metadata_vars{osie_y}, "200000", "...and osie_y" );
66}
67
68SKIP: {
69    eval { require Geo::Coordinates::UTM; };
70    skip "Geo::Coordinates::UTM not installed", 2 if $@;
71
72    $config->geo_handler( 3 );
73    my $q = CGI->new( "" );
74    $q->param( -name => "latitude", -value => " 1.463113 " );
75    $q->param( -name => "longitude", -value => " -0.215293 " );
76    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
77    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
78
79    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
80        wiki    => $guide->wiki,
81        config  => $config,
82        cgi_obj => $q,
83    );
84
85    is( $metadata_vars{latitude}, "1.463113",
86        "leading and trailing spaces stripped from latitude when processed" );
87    is( $metadata_vars{longitude}, "-0.215293", "...and longitude" );
88}
89
90OpenGuides::Test->write_data(
91                              guide => $guide,
92                              node  => "A Node",
93                              categories => " Food \r\n Live Music ",
94                              locales    => " Hammersmith \r\n Fulham ",
95);
96my %node = $guide->wiki->retrieve_node( "A Node" );
97my %data = %{ $node{metadata} };
98my @cats = sort @{ $data{category} || [] };
99is_deeply( \@cats, [ "Food", "Live Music" ],
100    "leading and trailing spaces stripped from all categories when stored" );
101my @locs = sort @{ $data{locale} || [] };
102is_deeply( \@locs, [ "Fulham", "Hammersmith" ], "...and all locales" );
Note: See TracBrowser for help on using the repository browser.