source: trunk/t/51_display_node.t @ 1064

Last change on this file since 1064 was 1064, checked in by kake, 14 years ago

Add intercept_redirect parameter to Openguides->display_node - used with the return_output parameter for testing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides;
5use Test::More;
6
7eval { require DBD::SQLite; };
8my $have_sqlite = $@ ? 0 : 1;
9
10if ( $@ ) {
11    my ($error) = $@ =~ /^(.*?)\n/;
12    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
13}
14
15plan tests => 9;
16
17Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
18my $config = OpenGuides::Config->new(
19       vars => {
20                 dbtype             => "sqlite",
21                 dbname             => "t/node.db",
22                 indexing_directory => "t/indexes",
23                 script_name        => "wiki.cgi",
24                 script_url         => "http://example.com/",
25                 site_name          => "Test Site",
26                 template_path      => "./templates",
27                 home_name          => "Home",
28               }
29);
30eval { require Wiki::Toolkit::Search::Plucene; };
31if ( $@ ) { $config->use_plucene ( 0 ) };
32
33my $guide = OpenGuides->new( config => $config );
34isa_ok( $guide, "OpenGuides" );
35my $wiki = $guide->wiki;
36isa_ok( $wiki, "Wiki::Toolkit" );
37$wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } );
38my $output = eval {
39    $guide->display_node( id => "Test Page", return_output => 1 );
40};
41is( $@, "", "->display_node doesn't die" );
42
43like( $output, qr{\<a.*?\Qhref="alternate.cgi?id=Test_Page;action=edit"\E>Edit\s+this\s+page</a>}, "...and edit link is redirected to source URL" );
44$config->home_name( "My Home Page" );
45$output = $guide->display_node( return_output => 1 );
46like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" );
47like( $output, qr{\Q<a href="wiki.cgi?action=edit;id=My_Home_Page"\E>Edit\s+this\s+page</a>}, "...and home page has an edit link" );
48my %tt_vars = $guide->display_node( return_tt_vars => 1 );
49ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" );
50
51$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef );
52
53$output = $guide->display_node( id => 'Redirect Test',
54                                return_output => 1,
55                                intercept_redirect => 1 );
56
57like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test}ms,
58      '#REDIRECT redirects correctly' );
59
60$output = $guide->display_node( id => 'Redirect Test', return_output => 1, redirect => 0 );
61
62unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
Note: See TracBrowser for help on using the repository browser.