| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides; |
|---|
| 5 | use OpenGuides::Test; |
|---|
| 6 | use Test::More; |
|---|
| 7 | |
|---|
| 8 | eval { require DBD::SQLite; }; |
|---|
| 9 | my $have_sqlite = $@ ? 0 : 1; |
|---|
| 10 | |
|---|
| 11 | if ( $@ ) { |
|---|
| 12 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 13 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | plan tests => 15; |
|---|
| 17 | |
|---|
| 18 | Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); |
|---|
| 19 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 20 | my $config = OpenGuides::Config->new( |
|---|
| 21 | vars => { |
|---|
| 22 | dbtype => "sqlite", |
|---|
| 23 | dbname => "t/node.db", |
|---|
| 24 | indexing_directory => "t/indexes", |
|---|
| 25 | script_name => "wiki.cgi", |
|---|
| 26 | script_url => "http://example.com/", |
|---|
| 27 | site_name => "Test Site", |
|---|
| 28 | template_path => "./templates", |
|---|
| 29 | home_name => "Home", |
|---|
| 30 | admin_pass => "password", |
|---|
| 31 | } |
|---|
| 32 | ); |
|---|
| 33 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 34 | if ( $@ ) { $config->use_plucene ( 0 ) }; |
|---|
| 35 | |
|---|
| 36 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 37 | isa_ok( $guide, "OpenGuides" ); |
|---|
| 38 | my $wiki = $guide->wiki; |
|---|
| 39 | isa_ok( $wiki, "Wiki::Toolkit" ); |
|---|
| 40 | $wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } ); |
|---|
| 41 | my $output = eval { |
|---|
| 42 | $guide->display_node( id => "Test Page", return_output => 1 ); |
|---|
| 43 | }; |
|---|
| 44 | is( $@, "", "->display_node doesn't die" ); |
|---|
| 45 | |
|---|
| 46 | like( $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" ); |
|---|
| 47 | $config->home_name( "My Home Page" ); |
|---|
| 48 | $output = $guide->display_node( return_output => 1 ); |
|---|
| 49 | like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" ); |
|---|
| 50 | like( $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" ); |
|---|
| 51 | my %tt_vars = $guide->display_node( return_tt_vars => 1 ); |
|---|
| 52 | ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" ); |
|---|
| 53 | |
|---|
| 54 | $wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef ); |
|---|
| 55 | |
|---|
| 56 | $output = $guide->display_node( id => 'Redirect Test', |
|---|
| 57 | return_output => 1, |
|---|
| 58 | intercept_redirect => 1 ); |
|---|
| 59 | |
|---|
| 60 | like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test}ms, |
|---|
| 61 | '#REDIRECT redirects correctly' ); |
|---|
| 62 | |
|---|
| 63 | $output = $guide->display_node( id => 'Redirect Test', return_output => 1, redirect => 0 ); |
|---|
| 64 | |
|---|
| 65 | unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' ); |
|---|
| 66 | |
|---|
| 67 | # Write a node, then delete one each of its categories and locales. |
|---|
| 68 | OpenGuides::Test->write_data( |
|---|
| 69 | guide => $guide, |
|---|
| 70 | node => "Non-existent categories and locales", |
|---|
| 71 | categories => "Does Not Exist\r\nDoes Exist", |
|---|
| 72 | locales => "Does Not Exist\r\nDoes Exist", |
|---|
| 73 | return_output => 1, |
|---|
| 74 | ); |
|---|
| 75 | foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) { |
|---|
| 76 | $guide->delete_node( |
|---|
| 77 | id => $id, |
|---|
| 78 | password => "password", |
|---|
| 79 | return_output => 1, |
|---|
| 80 | ); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | # Check the display comes up right for the existent and nonexistent. |
|---|
| 84 | $output = $guide->display_node( id => 'Non-existent categories and locales', |
|---|
| 85 | return_output => 1 |
|---|
| 86 | ); |
|---|
| 87 | |
|---|
| 88 | unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"}, |
|---|
| 89 | "category name not linked if category does not exist" ); |
|---|
| 90 | like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, |
|---|
| 91 | "...but does when it does exist" ); |
|---|
| 92 | unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"}, |
|---|
| 93 | "locale name not linked if category does not exist" ); |
|---|
| 94 | like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, |
|---|
| 95 | "...but does when it does exist" ); |
|---|
| 96 | |
|---|
| 97 | # Check it works when the case is different too. |
|---|
| 98 | OpenGuides::Test->write_data( |
|---|
| 99 | guide => $guide, |
|---|
| 100 | node => "Existent categories and locales", |
|---|
| 101 | categories => "does exist", |
|---|
| 102 | locales => "does exist", |
|---|
| 103 | return_output => 1, |
|---|
| 104 | ); |
|---|
| 105 | |
|---|
| 106 | $output = $guide->display_node( id => "Existent categories and locales", |
|---|
| 107 | return_output => 1 |
|---|
| 108 | ); |
|---|
| 109 | like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, |
|---|
| 110 | "wrongly-cased categories are linked as they should be" ); |
|---|
| 111 | like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, |
|---|
| 112 | "wrongly-cased locales are linked as they should be" ); |
|---|