Ticket #192: openguides-fix-gmaps-pref.patch

File openguides-fix-gmaps-pref.patch, 7.5 kB (added by ilmari, 19 months ago)

Fix for the ticket

  • templates/preferences.tt

    ==== Patch <openguides-fix-gmaps-pref> level 1
    Source: 46bc3436-8211-0410-8564-d96f7a728040:/local/openguides/hackfestsummer2007:22761
    Target: a7917b76-13f7-0310-8727-ec6248764fd6:/trunk:1045
            (https://urchin.earth.li/svn/openguides)
    Log:
     r22760@vesla:  ilmari | 2007-06-09 19:08:52 +0100
     Local branch for the hackfest
     r22761@vesla:  ilmari | 2007-06-09 19:15:22 +0100
     Only display the google maps preference if node maps are enabled (fixes #192)
    
    === templates/preferences.tt
    ==================================================================
     
    6666      <label for="track_recent_changes_views">Track my visits to Recent Changes and offer me a link for &#8220;changes since I last viewed Recent Changes&#8221;.</label> 
    6767    </p> 
    6868 
    69     [% IF gmaps_api_key %] 
     69    [% IF gmaps_api_key AND config.show_gmap_in_node_display %] 
    7070      <p> 
    7171        [% IF display_google_maps %] 
    7272          <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" checked="1" /> 
     
    152152    [% UNLESS track_recent_changes_views %] not [% END %] 
    153153  be tracked.</p> 
    154154 
    155   [% IF gmaps_api_key %] 
     155  [% IF gmaps_api_key AND config.show_gmap_in_node_display %] 
    156156    <p>Google Maps will 
    157157      [% UNLESS display_google_maps %] not [% END %] 
    158158    be displayed.</p> 
  • t/59_preferences.t

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

    === lib/OpenGuides/Template.pm
    ==================================================================
     
    5656Returns everything you need to send to STDOUT, including the 
    5757Content-Type: header. Croaks unless C<template> is supplied. 
    5858 
    59 The variables supplied in C<vars> are passed through to the template 
    60 specified.  Additional Template Toolkit variables are automatically 
    61 set and passed through as well, as described below.  B<Note:> 
    62 variables set in C<vars> will over-ride any variables of the same name 
    63 in the config object or the user cookies. 
     59The config object and variables supplied in C<vars> are passed through 
     60to the template specified.  Additional Template Toolkit variables are 
     61automatically set and passed through as well, as described below. 
     62B<Note:> variables set in C<vars> will over-ride any variables of the 
     63same name in the config object or the user cookies. 
    6464 
    6565=over 
    6666