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

Last change on this file since 878 was 785, checked in by Dominic Hargreaves, 16 years ago

Use Wiki::Toolkit. Note that CGI::Wiki::Plugin::Diff hasn't been converted yet,
so tests will be broken for now.

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