root/trunk/t/48_google_analytics.t

Revision 1204, 2.6 kB (checked in by dom, 5 months ago)

Fix Google Analytics by not trying to escape the key

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
13plan tests => 9;
14
15my ( $config, $guide, $wiki, $cookie, $output );
16
17# Clear out the database from any previous runs.
18unlink "t/node.db";
19unlink <t/indexes/*>;
20Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
21
22# Make a guide.
23$config = OpenGuides::Test->make_basic_config;
24$guide = OpenGuides->new( config => $config );
25
26# Write a node.
27OpenGuides::Test->write_data(
28                              guide => $guide,
29                              node  => "Red Lion",
30                            );
31
32# Make sure analytics stuff only shows up if we want it to.
33$output = $guide->display_node(
34                                id => "Red Lion",
35                                return_output => 1,
36                              );
37unlike( $output, qr/ga.js/, "Google analytics omitted by default" );
38
39$config->google_analytics_key( "" );
40$output = $guide->display_node(
41                                id => "Red Lion",
42                                return_output => 1,
43                              );
44unlike( $output, qr/ga.js/, "...also if analytics key is blank" );
45
46$config->google_analytics_key( 0 );
47$output = $guide->display_node(
48                                id => "Red Lion",
49                                return_output => 1,
50                              );
51unlike( $output, qr/ga.js/, "...also if analytics key is zero" );
52
53$config->google_analytics_key( "ThisIsNotAKey" );
54$output = $guide->display_node(
55                                id => "Red Lion",
56                                return_output => 1,
57                              );
58like( $output, qr/ga.js/, "does show up if key is provided" );
59like( $output, qr/ThisIsNotAKey/, "...correct key" );
60# Make sure analytics stuff only shows up if we want it to on recent changes
61# recent changes doesnt use CGI. which we dont need anymore but we should test in case we change our mind again.
62
63$config->google_analytics_key( "" );
64$output = $guide->display_recent_changes( return_output => 1 );
65unlike( $output, qr/ga.js/, "...also if analytics key is blank" );
66
67$config->google_analytics_key( 0 );
68$output = $guide->display_recent_changes( return_output => 1 );
69unlike( $output, qr/ga.js/, "...also if analytics key is zero" );
70
71$config->google_analytics_key( "ThisIsNotAKey" );
72$output = $guide->display_recent_changes( return_output => 1 );
73like( $output, qr/ga.js/, "does show up if key is provided" );
74like( $output, qr/ThisIsNotAKey/, "...correct key" );
Note: See TracBrowser for help on using the browser.