File: 406_map_in_node_display.t

package info (click to toggle)
openguides 0.84-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,628 kB
  • sloc: perl: 4,812; sh: 56; javascript: 56; makefile: 19
file content (150 lines) | stat: -rw-r--r-- 5,977 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use strict;
use OpenGuides;
use OpenGuides::Test;
use Test::More;
use Wiki::Toolkit::Setup::SQLite;

eval { require DBD::SQLite; };
if ( $@ ) {
    plan skip_all => "DBD::SQLite not installed - no database to test with";
    exit 0;
}

eval { require Test::HTML::Content; };
if ( $@ ) {
    plan skip_all => "Test::HTML::Content not installed";
    exit 0;
}

plan tests => 10;

my ( $config, $guide, $wiki, $cookie, $output );

# Clear out the database from any previous runs.
    OpenGuides::Test::refresh_db();

# Make a guide.
$config = OpenGuides::Test->make_basic_config;
$guide = OpenGuides->new( config => $config );
$wiki = $guide->wiki;

# Write a node with location data.
OpenGuides::Test->write_data(
                              guide => $guide,
                              node  => "Red Lion",
                              os_x  => 530000,
                              os_y  => 180000,
                            );

# Maps shouldn't show up if there's no API key and we're not using Leaflet.
$config->show_gmap_in_node_display( 1 );
$config->use_leaflet( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
                                              config => $config,
                                              display_google_maps => 1,
                                            );
$ENV{HTTP_COOKIE} = $cookie;

$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
               "Map omitted from node if no API key and not using Leaflet" );

# And they should if there is a Google API key.
$config->gmaps_api_key( "This is not a real API key." );
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::tag_ok( $output, "div", { id => "map" },
                             "Map shown on node if we have a Google API key");

# But not if the user doesn't want them.
$cookie = OpenGuides::CGI->make_prefs_cookie(
                                              config => $config,
                                              display_google_maps => 0,
                                            );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
                             "...but not if the user turned it off" );

# And not if the admin doesn't want them.
$config->show_gmap_in_node_display( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
                                              config => $config,
                                              display_google_maps => 1,
                                            );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
                             "...and not if the admin turned it off" );

# Now test with Leaflet.
$cookie = OpenGuides::CGI->make_prefs_cookie(
                               config => $config, display_google_maps => 1 );
$ENV{HTTP_COOKIE} = $cookie;
$config->gmaps_api_key( "I still have a key but don't expect to use it" );
$config->show_gmap_in_node_display( 1 );
$config->use_leaflet( 1 );

# Shouldn't get any of the GMap stuff.
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
unlike( $output, qr|new GMap|,
        "No invocation of GMap constructor when using Leaflet" );
unlike ( $output, qr|new GPoint|, "...nor GPoint" );
unlike ( $output, qr|new GIcon|, "...nor GIcon" );

# Map should show in node if we're using Leaflet and have no GMap API key.
$config->gmaps_api_key( "" );
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::tag_ok( $output, "div", { id => "node_map_canvas" },
                             "Map shown on node if using Leaflet");

# But not if the user doesn't want them.
$cookie = OpenGuides::CGI->make_prefs_cookie(
                                              config => $config,
                                              display_google_maps => 0,
                                            );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
                             "...but not if the user turned it off" );

# And not if the admin doesn't want them.
$config->show_gmap_in_node_display( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
                                              config => $config,
                                              display_google_maps => 1,
                                            );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
                                id => "Red Lion",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
                             "...and not if the admin turned it off" );