root/tags/rel0_59/t/46_map_in_node_display.t

Revision 953, 3.4 kB (checked in by kake, 22 months ago)

Add config option to suppress inline maps on geotagged nodes (#188). Fix preferences to take notice of users turning off inline Google maps (#189).

Line 
1use strict;
2use OpenGuides;
3use OpenGuides::Test;
4use Test::More;
5use Wiki::Toolkit::Setup::SQLite;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    plan skip_all => "DBD::SQLite not installed - no database to test with";
10    exit 0;
11}
12
13eval { require Test::HTML::Content; };
14if ( $@ ) {
15    plan skip_all => "Test::HTML::Content not installed";
16    exit 0;
17}
18
19plan tests => 4;
20
21my ( $config, $guide, $wiki, $cookie, $output );
22
23# Clear out the database from any previous runs.
24unlink "t/node.db";
25unlink <t/indexes/*>;
26Wiki::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.
34OpenGuides::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;
54Test::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;
64Test::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;
78Test::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;
93Test::HTML::Content::no_tag( $output, "div", { id => "map" },
94                             "...and not if the admin turned it off" );
Note: See TracBrowser for help on using the browser.