Author: kake Date: 2007-06-11 03:23:11 +0100 (Mon, 11 Jun 2007) New Revision: 1064
Modified: trunk/lib/OpenGuides.pm trunk/t/51_display_node.t trunk/t/54_redirect.t Log: Add intercept_redirect parameter to Openguides->display_node - used with the return_output parameter for testing.
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2007-06-10 17:31:17 UTC (rev 1063) +++ trunk/lib/OpenGuides.pm 2007-06-11 02:23:11 UTC (rev 1064) @@ -163,13 +163,25 @@ return_tt_vars => 1, );
-If C<version> is omitted then the latest version will be displayed. +If C<version> is omitted then it will assume you want the latest version.
+Note that if you pass the C<return_output> parameter, and your node is a +redirecting node, this method will fake the redirect and return the output +that will actually end up in the user's browser. If instead you want to see +the HTTP headers that will be printed in order to perform the redirect, pass +the C<intercept_redirect> parameter as well. The C<intercept_redirect> +parameter has no effect if the node isn't a redirect, or if the +C<return_output> parameter is omitted. + +(At the moment, C<return_tt_vars> acts as if the C<intercept_redirect> +parameter was passed.) + =cut
sub display_node { my ($self, %args) = @_; my $return_output = $args{return_output} || 0; + my $intercept_redirect = $args{intercept_redirect}; my $version = $args{version}; my $id = $args{id} || $self->config->home_name; my $wiki = $self->wiki; @@ -276,9 +288,17 @@ print $output; } elsif ( $wiki->node_exists($redirect) && $redirect ne $id && $redirect ne $oldid ) { # Avoid loops by not generating redirects to the same node or the previous node. - my $output = $self->redirect_to_node($redirect, $id); - return $output if $return_output; - print $output; + if ( $return_output ) { + if ( $intercept_redirect ) { + return $self->redirect_to_node( $redirect, $id ); + } else { + return $self->display_node( id => $redirect, + oldid => $id, + return_output => 1, + ); + } + } + print $self->redirect_to_node( $redirect, $id ); return 0; } }
Modified: trunk/t/51_display_node.t =================================================================== --- trunk/t/51_display_node.t 2007-06-10 17:31:17 UTC (rev 1063) +++ trunk/t/51_display_node.t 2007-06-11 02:23:11 UTC (rev 1064) @@ -50,7 +50,9 @@
$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef );
-$output = $guide->display_node( id => 'Redirect Test', return_output => 1 ); +$output = $guide->display_node( id => 'Redirect Test', + return_output => 1, + intercept_redirect => 1 );
like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test%7Dms, '#REDIRECT redirects correctly' );
Modified: trunk/t/54_redirect.t =================================================================== --- trunk/t/54_redirect.t 2007-06-10 17:31:17 UTC (rev 1063) +++ trunk/t/54_redirect.t 2007-06-11 02:23:11 UTC (rev 1064) @@ -41,7 +41,9 @@ $wiki->write_node( "Test Page 2", "foo" ) or die "Can't write node"; my $output = eval { - $guide->display_node( id => "Test Page", return_output => 1 ); + $guide->display_node( id => "Test Page", + return_output => 1, + intercept_redirect => 1 ); }; is( $@, "", "->display_node doesn't die when page is a redirect" );
openguides-commits@lists.openguides.org