| 1 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Test; |
|---|
| 4 | use Test::More; |
|---|
| 5 | |
|---|
| 6 | eval { require DBD::SQLite; }; |
|---|
| 7 | |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 10 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | eval { require DBD::SQLite; }; |
|---|
| 14 | if ( $@ ) { |
|---|
| 15 | plan skip_all => "DBD::SQLite not installed - no database to test with"; |
|---|
| 16 | exit 0; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | eval { require Test::HTML::Content; }; |
|---|
| 20 | if ( $@ ) { |
|---|
| 21 | plan skip_all => "Test::HTML::Content not installed"; |
|---|
| 22 | exit 0; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | plan tests => 2; |
|---|
| 26 | |
|---|
| 27 | Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/prefs.db" } ); |
|---|
| 28 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/prefs.db" } ); |
|---|
| 29 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 30 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 31 | my $wiki = $guide->wiki; |
|---|
| 32 | |
|---|
| 33 | $config->gmaps_api_key( "This is not a real API key." ); |
|---|
| 34 | $config->show_gmap_in_node_display( 1 ); |
|---|
| 35 | |
|---|
| 36 | my $cookie = OpenGuides::CGI->make_prefs_cookie( |
|---|
| 37 | config => $config, |
|---|
| 38 | display_google_maps => 1, |
|---|
| 39 | ); |
|---|
| 40 | $ENV{HTTP_COOKIE} = $cookie; |
|---|
| 41 | |
|---|
| 42 | # If the google API is present and node maps are enabled, we should have the pref |
|---|
| 43 | Test::HTML::Content::tag_ok( get_output($wiki, $config), 'input', |
|---|
| 44 | { type => 'checkbox', name => 'display_google_maps' }, |
|---|
| 45 | 'Google maps pref shown' |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | # But not if the node map is globally disabled |
|---|
| 49 | $config->show_gmap_in_node_display( 0 ); |
|---|
| 50 | Test::HTML::Content::no_tag( get_output($wiki, $config), 'input', |
|---|
| 51 | { type => 'checkbox', name => 'display_google_maps' }, |
|---|
| 52 | 'No google maps prefs if node maps disabled' |
|---|
| 53 | ); |
|---|
| 54 | |
|---|
| 55 | sub get_output { |
|---|
| 56 | my ($wiki, $config) = @_; |
|---|
| 57 | |
|---|
| 58 | return OpenGuides::Template->output( |
|---|
| 59 | wiki => $wiki, |
|---|
| 60 | config => $config, |
|---|
| 61 | template => "preferences.tt", |
|---|
| 62 | noheaders => 1, |
|---|
| 63 | vars => { |
|---|
| 64 | not_editable => 1, |
|---|
| 65 | show_form => 1 |
|---|
| 66 | }, |
|---|
| 67 | ); |
|---|
| 68 | } |
|---|