| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | |
|---|
| 9 | if ( $@ ) { |
|---|
| 10 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 11 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | plan tests => 2; |
|---|
| 15 | |
|---|
| 16 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 17 | my $config = OpenGuides::Config->new( |
|---|
| 18 | vars => { |
|---|
| 19 | dbtype => "sqlite", |
|---|
| 20 | dbname => "t/node.db", |
|---|
| 21 | indexing_directory => "t/indexes", |
|---|
| 22 | script_name => "wiki.cgi", |
|---|
| 23 | script_url => "http://example.com/", |
|---|
| 24 | site_name => "Test Site", |
|---|
| 25 | template_path => "./templates", |
|---|
| 26 | } |
|---|
| 27 | ); |
|---|
| 28 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 29 | if ( $@ ) { $config->use_plucene ( 0 ) }; |
|---|
| 30 | |
|---|
| 31 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 32 | my $wiki = $guide->wiki; |
|---|
| 33 | |
|---|
| 34 | # Clear out the database from any previous runs. |
|---|
| 35 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 36 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | $wiki->write_node( "Test Page", "#REDIRECT [[Test Page 2]]" ) |
|---|
| 40 | or die "Can't write node"; |
|---|
| 41 | $wiki->write_node( "Test Page 2", "foo" ) |
|---|
| 42 | or die "Can't write node"; |
|---|
| 43 | my $output = eval { |
|---|
| 44 | $guide->display_node( id => "Test Page", return_output => 1 ); |
|---|
| 45 | }; |
|---|
| 46 | is( $@, "", "->display_node doesn't die when page is a redirect" ); |
|---|
| 47 | |
|---|
| 48 | # Old versions of CGI.pm mistakenly print location: instead of Location: |
|---|
| 49 | like( $output, |
|---|
| 50 | qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?id=Test_Page_2\;oldid=Test_Page/, |
|---|
| 51 | "...and redirects to the right place" ); |
|---|