Author: kake Date: 2007-06-24 03:10:37 +0100 (Sun, 24 Jun 2007) New Revision: 1098
Modified: trunk/lib/OpenGuides/Template.pm trunk/t/51_display_node.t Log: Fix changeset [1095] - categories and locales weren't getting linkified even if they _did_ exist.
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2007-06-21 11:25:06 UTC (rev 1097) +++ trunk/lib/OpenGuides/Template.pm 2007-06-24 02:10:37 UTC (rev 1098) @@ -290,7 +290,8 @@ my ($class, %args) = @_; my %metadata = %{$args{metadata} || {} }; my $q = $args{cgi_obj}; - my $formatter = $args{wiki}->formatter; + my $wiki = $args{wiki}; + my $formatter = $wiki->formatter; my $config = $args{config}; my $script_name = $config->script_name;
@@ -318,13 +319,33 @@ split("\r\n", $locales_text); }
- my @categories = map { { name => $_, - url => $args{wiki}->node_exists( "Category_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Category_" - . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @catlist; + # Some stuff here is copied from OpenGuides->_autoCreateCategoryLocale + # - we should rationalise this. + my @categories = map { + my $param = $formatter->node_name_to_node_param( $_ ); + my $name = $_; + $name =~ s/(.*)/\u$1/; + $name = $wiki->formatter->_do_freeupper( "Category $name" ); + { + name => $_, + url => $wiki->node_exists( $name ) + ? "$script_name?Category_" . uri_escape( $param ) + : "", + }; + } @catlist;
- my @locales = map { { name => $_, - url => $args{wiki}->node_exists( "Locale_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Locale_" - . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @loclist; + my @locales = map { + my $param = $formatter->node_name_to_node_param( $_ ); + my $name = $_; + $name =~ s/(.*)/\u$1/; + $name = $wiki->formatter->_do_freeupper( "Locale $name" ); + { + name => $_, + url => $wiki->node_exists( $name ) + ? "$script_name?Locale_" . uri_escape( $param ) + : "", + }; + } @loclist;
# The 'website' attribute might contain a URL so we wiki-format it here # rather than just CGI::escapeHTMLing it all in the template.
Modified: trunk/t/51_display_node.t =================================================================== --- trunk/t/51_display_node.t 2007-06-21 11:25:06 UTC (rev 1097) +++ trunk/t/51_display_node.t 2007-06-24 02:10:37 UTC (rev 1098) @@ -2,6 +2,7 @@ use Wiki::Toolkit::Setup::SQLite; use OpenGuides::Config; use OpenGuides; +use OpenGuides::Test; use Test::More;
eval { require DBD::SQLite; }; @@ -12,7 +13,7 @@ plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; }
-plan tests => 13; +plan tests => 15;
Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); @@ -26,6 +27,7 @@ site_name => "Test Site", template_path => "./templates", home_name => "Home", + admin_pass => "password", } ); eval { require Wiki::Toolkit::Search::Plucene; }; @@ -62,36 +64,49 @@
unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
-$wiki->write_node( "Non-existent categories and locales", "foo", undef, - { category => [ "Does not exist" ], - locale => [ "Does not exist" ] } ); +# Write a node, then delete one each of its categories and locales. +OpenGuides::Test->write_data( + guide => $guide, + node => "Non-existent categories and locales", + categories => "Does Not Exist\r\nDoes Exist", + locales => "Does Not Exist\r\nDoes Exist", + return_output => 1, + ); +foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) { + $guide->delete_node( + id => $id, + password => "password", + return_output => 1, + ); +}
+# Check the display comes up right for the existent and nonexistent. $output = $guide->display_node( id => 'Non-existent categories and locales', return_output => 1 );
unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"}, - 'Category name not linked if category does not exist' ); - -$wiki->write_node( "Category_Does_Not_Exist", "bar", undef, undef ); - -$output = $guide->display_node( id => 'Non-existent categories and locales', - return_output => 1 - ); - -like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"}, - 'but does when it does exist' ); - + "category name not linked if category does not exist" ); +like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, + "...but does when it does exist" ); unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"}, - 'Locale name not linked if category does not exist' ); + "locale name not linked if category does not exist" ); +like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, + "...but does when it does exist" );
-$wiki->write_node( "Locale_Does_Not_Exist", "wibble", undef, undef ); +# Check it works when the case is different too. +OpenGuides::Test->write_data( + guide => $guide, + node => "Existent categories and locales", + categories => "does exist", + locales => "does exist", + return_output => 1, + );
-$output = $guide->display_node( id => 'Non-existent categories and locales', +$output = $guide->display_node( id => "Existent categories and locales", return_output => 1 ); - -like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"}, - 'but does when it does exist' ); - - +like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, + "wrongly-cased categories are linked as they should be" ); +like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, + "wrongly-cased locales are linked as they should be" );
openguides-commits@lists.openguides.org