| 1 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 2 | use OpenGuides::Config; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Template; |
|---|
| 5 | use OpenGuides::Test; |
|---|
| 6 | use Test::More; |
|---|
| 7 | |
|---|
| 8 | eval { require DBD::SQLite; }; |
|---|
| 9 | |
|---|
| 10 | if ( $@ ) { |
|---|
| 11 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 12 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | plan tests => 8; |
|---|
| 16 | |
|---|
| 17 | # Clear out the database from any previous runs. |
|---|
| 18 | unlink "t/node.db"; |
|---|
| 19 | unlink <t/indexes/*>; |
|---|
| 20 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 21 | |
|---|
| 22 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 23 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 24 | |
|---|
| 25 | SKIP: { |
|---|
| 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 | |
|---|
| 46 | SKIP: { |
|---|
| 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 | |
|---|
| 68 | SKIP: { |
|---|
| 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 | |
|---|
| 90 | OpenGuides::Test->write_data( |
|---|
| 91 | guide => $guide, |
|---|
| 92 | node => "A Node", |
|---|
| 93 | categories => " Food \r\n Live Music ", |
|---|
| 94 | locales => " Hammersmith \r\n Fulham ", |
|---|
| 95 | ); |
|---|
| 96 | my %node = $guide->wiki->retrieve_node( "A Node" ); |
|---|
| 97 | my %data = %{ $node{metadata} }; |
|---|
| 98 | my @cats = sort @{ $data{category} || [] }; |
|---|
| 99 | is_deeply( \@cats, [ "Food", "Live Music" ], |
|---|
| 100 | "leading and trailing spaces stripped from all categories when stored" ); |
|---|
| 101 | my @locs = sort @{ $data{locale} || [] }; |
|---|
| 102 | is_deeply( \@locs, [ "Fulham", "Hammersmith" ], "...and all locales" ); |
|---|