| 1 | use strict; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Test; |
|---|
| 4 | use Test::More; |
|---|
| 5 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 10 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | plan tests => 15; |
|---|
| 14 | |
|---|
| 15 | my ( $config, $guide, $wiki ); |
|---|
| 16 | |
|---|
| 17 | # Clear out the database from any previous runs. |
|---|
| 18 | unlink "t/node.db"; |
|---|
| 19 | unlink <t/indexes/*>; |
|---|
| 20 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 21 | |
|---|
| 22 | # Write some data to show up in recent changes. |
|---|
| 23 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 24 | $guide = OpenGuides->new( config => $config ); |
|---|
| 25 | OpenGuides::Test->write_data( |
|---|
| 26 | guide => $guide, |
|---|
| 27 | node => "Red Lion", |
|---|
| 28 | content => "A pub.", |
|---|
| 29 | username => "Kake", |
|---|
| 30 | comment => "I edited it.", |
|---|
| 31 | ); |
|---|
| 32 | |
|---|
| 33 | # First test that recent changes show up on the front page by default. |
|---|
| 34 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 35 | $guide = OpenGuides->new( config => $config ); |
|---|
| 36 | |
|---|
| 37 | my $output = $guide->display_node( |
|---|
| 38 | id => $config->home_name, |
|---|
| 39 | return_output => 1, |
|---|
| 40 | ); |
|---|
| 41 | like( $output, qr/Red Lion/, |
|---|
| 42 | "recent changes show up on home page by default" ); |
|---|
| 43 | like( $output, qr/I edited it\./, "...including comments" ); |
|---|
| 44 | like( $output, qr/Kake/, "...and usernames" ); |
|---|
| 45 | like( $output, qr/Edit this page/, "...edit this page link is there too" ); |
|---|
| 46 | |
|---|
| 47 | # And that they show up when we explicitly ask for them. |
|---|
| 48 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 49 | $config->recent_changes_on_home_page( 1 ); |
|---|
| 50 | $guide = OpenGuides->new( config => $config ); |
|---|
| 51 | |
|---|
| 52 | $output = $guide->display_node( |
|---|
| 53 | id => $config->home_name, |
|---|
| 54 | return_output => 1, |
|---|
| 55 | ); |
|---|
| 56 | like( $output, qr/Red Lion/, |
|---|
| 57 | "recent changes show up on home page when we ask for them" ); |
|---|
| 58 | like( $output, qr/I edited it\./, "...including comments" ); |
|---|
| 59 | like( $output, qr/Kake/, "...and usernames" ); |
|---|
| 60 | like( $output, qr/Edit this page/, "...edit this page link is there too" ); |
|---|
| 61 | |
|---|
| 62 | OpenGuides::Test->write_data( |
|---|
| 63 | guide => $guide, |
|---|
| 64 | node => "Red Lion", |
|---|
| 65 | content => "A nice pub.", |
|---|
| 66 | username => "Earle", |
|---|
| 67 | comment => "I also edited it. For fun, here are two links: [[A Page]], and the same link [[A Page|again]].", |
|---|
| 68 | ); |
|---|
| 69 | |
|---|
| 70 | # Reload page. |
|---|
| 71 | $output = $guide->display_node( |
|---|
| 72 | id => $config->home_name, |
|---|
| 73 | return_output => 1, |
|---|
| 74 | ); |
|---|
| 75 | |
|---|
| 76 | like( $output, qr{<a href="\?A Page">A Page</a>}, "...simple wiki links appear in Recent Changes" ); |
|---|
| 77 | like( $output, qr{<a href="\?A Page">again</a>}, "...titled wiki links appear in Recent Changes" ); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | # And that they don't show up if we don't want them. Turn off the navbar |
|---|
| 81 | # too, since we want to make sure the edit page link shows up regardless (it |
|---|
| 82 | # normally appears in the recent changes box). |
|---|
| 83 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 84 | $config->recent_changes_on_home_page( 0 ); |
|---|
| 85 | $config->navbar_on_home_page( 0 ); |
|---|
| 86 | $guide = OpenGuides->new( config => $config ); |
|---|
| 87 | |
|---|
| 88 | $output = $guide->display_node( |
|---|
| 89 | id => $config->home_name, |
|---|
| 90 | return_output => 1, |
|---|
| 91 | ); |
|---|
| 92 | unlike( $output, qr/Red Lion/, |
|---|
| 93 | "recent changes don't show up on home page if we turn them off" ); |
|---|
| 94 | unlike( $output, qr/I edited it\./, "...comments not shown either" ); |
|---|
| 95 | unlike( $output, qr/Kake/, "...nor usernames" ); |
|---|
| 96 | unlike( $output, qr/Ten most.*recent changes/, "...heading not shown either" ); |
|---|
| 97 | like( $output, qr/Edit this page/, "...edit this page link is there though" ); |
|---|