| 1 | use strict; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Test; |
|---|
| 4 | use Test::More; |
|---|
| 5 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | plan skip_all => "DBD::SQLite not installed - no database to test with"; |
|---|
| 10 | exit 0; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | eval { require Test::HTML::Content; }; |
|---|
| 14 | if ( $@ ) { |
|---|
| 15 | plan skip_all => "Test::HTML::Content not installed"; |
|---|
| 16 | exit 0; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | plan tests => 4; |
|---|
| 20 | |
|---|
| 21 | my ( $config, $guide, $wiki, $cookie, $output ); |
|---|
| 22 | |
|---|
| 23 | # Clear out the database from any previous runs. |
|---|
| 24 | unlink "t/node.db"; |
|---|
| 25 | unlink <t/indexes/*>; |
|---|
| 26 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 27 | |
|---|
| 28 | # Make a guide. |
|---|
| 29 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 30 | $guide = OpenGuides->new( config => $config ); |
|---|
| 31 | $wiki = $guide->wiki; |
|---|
| 32 | |
|---|
| 33 | # Write a node with location data. |
|---|
| 34 | OpenGuides::Test->write_data( |
|---|
| 35 | guide => $guide, |
|---|
| 36 | node => "Red Lion", |
|---|
| 37 | os_x => 530000, |
|---|
| 38 | os_y => 180000, |
|---|
| 39 | ); |
|---|
| 40 | |
|---|
| 41 | # Maps shouldn't show up if there's no API key. |
|---|
| 42 | $config->show_gmap_in_node_display( 1 ); |
|---|
| 43 | $cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 44 | config => $config, |
|---|
| 45 | display_google_maps => 1, |
|---|
| 46 | ); |
|---|
| 47 | $ENV{HTTP_COOKIE} = $cookie; |
|---|
| 48 | |
|---|
| 49 | $output = $guide->display_node( |
|---|
| 50 | id => "Red Lion", |
|---|
| 51 | return_output => 1, |
|---|
| 52 | ); |
|---|
| 53 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 54 | Test::HTML::Content::no_tag( $output, "div", { id => "map" }, |
|---|
| 55 | "Google map omitted from node if no API key" ); |
|---|
| 56 | |
|---|
| 57 | # And they should if there is. |
|---|
| 58 | $config->gmaps_api_key( "This is not a real API key." ); |
|---|
| 59 | $output = $guide->display_node( |
|---|
| 60 | id => "Red Lion", |
|---|
| 61 | return_output => 1, |
|---|
| 62 | ); |
|---|
| 63 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 64 | Test::HTML::Content::tag_ok( $output, "div", { id => "map" }, |
|---|
| 65 | "Google map shown on node if we have an API key"); |
|---|
| 66 | |
|---|
| 67 | # But not if the user doesn't want them. |
|---|
| 68 | $cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 69 | config => $config, |
|---|
| 70 | display_google_maps => 0, |
|---|
| 71 | ); |
|---|
| 72 | $ENV{HTTP_COOKIE} = $cookie; |
|---|
| 73 | $output = $guide->display_node( |
|---|
| 74 | id => "Red Lion", |
|---|
| 75 | return_output => 1, |
|---|
| 76 | ); |
|---|
| 77 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 78 | Test::HTML::Content::no_tag( $output, "div", { id => "map" }, |
|---|
| 79 | "...but not if the user turned it off" ); |
|---|
| 80 | |
|---|
| 81 | # And not if the admin doesn't want them. |
|---|
| 82 | $config->show_gmap_in_node_display( 0 ); |
|---|
| 83 | $cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 84 | config => $config, |
|---|
| 85 | display_google_maps => 1, |
|---|
| 86 | ); |
|---|
| 87 | $ENV{HTTP_COOKIE} = $cookie; |
|---|
| 88 | $output = $guide->display_node( |
|---|
| 89 | id => "Red Lion", |
|---|
| 90 | return_output => 1, |
|---|
| 91 | ); |
|---|
| 92 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 93 | Test::HTML::Content::no_tag( $output, "div", { id => "map" }, |
|---|
| 94 | "...and not if the admin turned it off" ); |
|---|