| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides; |
|---|
| 5 | use Test::More tests => 7; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | my $have_sqlite = $@ ? 0 : 1; |
|---|
| 9 | |
|---|
| 10 | SKIP: { |
|---|
| 11 | skip "DBD::SQLite not installed - no database to test with", 5 |
|---|
| 12 | unless $have_sqlite; |
|---|
| 13 | |
|---|
| 14 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 15 | my $config = OpenGuides::Config->new( |
|---|
| 16 | vars => { |
|---|
| 17 | dbtype => "sqlite", |
|---|
| 18 | dbname => "t/node.db", |
|---|
| 19 | indexing_directory => "t/indexes", |
|---|
| 20 | script_name => "wiki.cgi", |
|---|
| 21 | script_url => "http://example.com/", |
|---|
| 22 | site_name => "Test Site", |
|---|
| 23 | template_path => "./templates", |
|---|
| 24 | home_name => "Home", |
|---|
| 25 | } |
|---|
| 26 | ); |
|---|
| 27 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 28 | if ( $@ ) { $config->use_plucene ( 0 ) }; |
|---|
| 29 | |
|---|
| 30 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 31 | isa_ok( $guide, "OpenGuides" ); |
|---|
| 32 | my $wiki = $guide->wiki; |
|---|
| 33 | isa_ok( $wiki, "Wiki::Toolkit" ); |
|---|
| 34 | $wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } ); |
|---|
| 35 | my $output = eval { |
|---|
| 36 | $guide->display_node( id => "Test Page", return_output => 1 ); |
|---|
| 37 | }; |
|---|
| 38 | is( $@, "", "->display_node doesn't die" ); |
|---|
| 39 | |
|---|
| 40 | like( $output, qr{\<a.*?\Qhref="alternate.cgi?id=Test_Page;action=edit">Edit this page</a>\E}, "...and edit link is redirected to source URL" ); |
|---|
| 41 | $config->home_name( "My Home Page" ); |
|---|
| 42 | $output = $guide->display_node( return_output => 1 ); |
|---|
| 43 | like( $output, qr/My Home Page/, "...and defaults to the home node, and takes notice of what we want to call it" ); |
|---|
| 44 | like( $output, qr{\Q<a href="wiki.cgi?action=edit;id=My_Home_Page">Edit this page</a>\E}, "...and home page has an edit link" ); |
|---|
| 45 | my %tt_vars = $guide->display_node( return_tt_vars => 1 ); |
|---|
| 46 | ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" ); |
|---|
| 47 | } |
|---|