Changeset 1098


Ignore:
Timestamp:
Jun 24, 2007, 3:10:37 AM (14 years ago)
Author:
kake
Message:

Fix changeset [1095] - categories and locales weren't getting linkified even if they _did_ exist.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Template.pm

    r1095 r1098  
    291291    my %metadata = %{$args{metadata} || {} };
    292292    my $q = $args{cgi_obj};
    293     my $formatter = $args{wiki}->formatter;
     293    my $wiki = $args{wiki};
     294    my $formatter = $wiki->formatter;
    294295    my $config = $args{config};
    295296    my $script_name = $config->script_name;
     
    319320    }
    320321
    321     my @categories = map { { name => $_,
    322                              url  => $args{wiki}->node_exists( "Category_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Category_"
    323             . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @catlist;
    324 
    325     my @locales    = map { { name => $_,
    326                              url  => $args{wiki}->node_exists( "Locale_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Locale_"
    327             . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @loclist;
     322    # Some stuff here is copied from OpenGuides->_autoCreateCategoryLocale
     323    # - we should rationalise this.
     324    my @categories = map {
     325        my $param = $formatter->node_name_to_node_param( $_ );
     326        my $name = $_;
     327        $name =~ s/(.*)/\u$1/;
     328        $name = $wiki->formatter->_do_freeupper( "Category $name" );
     329        {
     330          name => $_,
     331          url  => $wiki->node_exists( $name )
     332                      ? "$script_name?Category_" . uri_escape( $param )
     333                      : "",
     334        };
     335    } @catlist;
     336
     337    my @locales = map {
     338        my $param = $formatter->node_name_to_node_param( $_ );
     339        my $name = $_;
     340        $name =~ s/(.*)/\u$1/;
     341        $name = $wiki->formatter->_do_freeupper( "Locale $name" );
     342        {
     343          name => $_,
     344          url  => $wiki->node_exists( $name )
     345                      ? "$script_name?Locale_" . uri_escape( $param )
     346                      : "",
     347        };
     348    } @loclist;
    328349
    329350    # The 'website' attribute might contain a URL so we wiki-format it here
  • trunk/t/51_display_node.t

    r1095 r1098  
    33use OpenGuides::Config;
    44use OpenGuides;
     5use OpenGuides::Test;
    56use Test::More;
    67
     
    1314}
    1415
    15 plan tests => 13;
     16plan tests => 15;
    1617
    1718Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     
    2728                 template_path      => "./templates",
    2829                 home_name          => "Home",
     30                 admin_pass         => "password",
    2931               }
    3032);
     
    6365unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
    6466
    65 $wiki->write_node( "Non-existent categories and locales", "foo", undef,
    66                                 { category => [ "Does not exist" ],
    67                                   locale   => [ "Does not exist" ] } );
     67# Write a node, then delete one each of its categories and locales.
     68OpenGuides::Test->write_data(
     69                              guide => $guide,
     70                              node => "Non-existent categories and locales",
     71                              categories => "Does Not Exist\r\nDoes Exist",
     72                              locales => "Does Not Exist\r\nDoes Exist",
     73                              return_output => 1,
     74                            );
     75foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) {
     76    $guide->delete_node(
     77                         id => $id,
     78                         password => "password",
     79                         return_output => 1,
     80                       );
     81}
    6882
     83# Check the display comes up right for the existent and nonexistent.
    6984$output = $guide->display_node( id => 'Non-existent categories and locales',
    7085                                return_output => 1
     
    7287
    7388unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
    74     'Category name not linked if category does not exist' );
     89    "category name not linked if category does not exist" );
     90like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"},
     91    "...but does when it does exist" );
     92unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
     93    "locale name not linked if category does not exist" );
     94like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"},
     95    "...but does when it does exist" );
    7596
    76 $wiki->write_node( "Category_Does_Not_Exist", "bar", undef, undef );
     97# Check it works when the case is different too.
     98OpenGuides::Test->write_data(
     99                              guide => $guide,
     100                              node => "Existent categories and locales",
     101                              categories => "does exist",
     102                              locales => "does exist",
     103                              return_output => 1,
     104                            );
    77105
    78 $output = $guide->display_node( id => 'Non-existent categories and locales',
     106$output = $guide->display_node( id => "Existent categories and locales",
    79107                                return_output => 1
    80108                              );
    81 
    82 like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
    83     'but does when it does exist' );
    84 
    85 unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
    86     'Locale name not linked if category does not exist' );
    87 
    88 $wiki->write_node( "Locale_Does_Not_Exist", "wibble", undef, undef );
    89 
    90 $output = $guide->display_node( id => 'Non-existent categories and locales',
    91                                 return_output => 1
    92                               );
    93 
    94 like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
    95     'but does when it does exist' );
    96 
    97 
     109like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"},
     110    "wrongly-cased categories are linked as they should be" );
     111like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"},
     112    "wrongly-cased locales are linked as they should be" );
Note: See TracChangeset for help on using the changeset viewer.