| 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 | plan tests => 9; |
|---|
| 14 | |
|---|
| 15 | my ( $config, $guide, $wiki, $cookie, $output ); |
|---|
| 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 | # Make a guide. |
|---|
| 23 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 24 | $guide = OpenGuides->new( config => $config ); |
|---|
| 25 | |
|---|
| 26 | # Write a node. |
|---|
| 27 | OpenGuides::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 | ); |
|---|
| 37 | unlike( $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 | ); |
|---|
| 44 | unlike( $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 | ); |
|---|
| 51 | unlike( $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 | ); |
|---|
| 58 | like( $output, qr/ga.js/, "does show up if key is provided" ); |
|---|
| 59 | like( $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 ); |
|---|
| 65 | unlike( $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 ); |
|---|
| 69 | unlike( $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 ); |
|---|
| 73 | like( $output, qr/ga.js/, "does show up if key is provided" ); |
|---|
| 74 | like( $output, qr/ThisIsNotAKey/, "...correct key" ); |
|---|