| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More tests => 6; |
|---|
| 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", 6 |
|---|
| 12 | unless $have_sqlite; |
|---|
| 13 | |
|---|
| 14 | # Clear out the database from any previous runs. |
|---|
| 15 | unlink "t/node.db"; |
|---|
| 16 | unlink <t/indexes/*>; |
|---|
| 17 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 18 | |
|---|
| 19 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 20 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 21 | my $wiki = $guide->wiki; |
|---|
| 22 | |
|---|
| 23 | # Test @INDEX_LINK |
|---|
| 24 | $wiki->write_node( "Test 1", "\@INDEX_LINK [[Category Foo]]" ) |
|---|
| 25 | or die "Can't write node"; |
|---|
| 26 | $wiki->write_node( "Test 2", "\@INDEX_LINK [[Category Bar|Bars]]" ) |
|---|
| 27 | or die "Can't write node"; |
|---|
| 28 | |
|---|
| 29 | my $output; |
|---|
| 30 | $output = $guide->display_node( |
|---|
| 31 | return_output => 1, |
|---|
| 32 | id => "Test 1", |
|---|
| 33 | ); |
|---|
| 34 | like( $output, qr/View all pages in Category Foo/, |
|---|
| 35 | "\@INDEX_LINK has right default link text" ); |
|---|
| 36 | $output = $guide->display_node( |
|---|
| 37 | return_output => 1, |
|---|
| 38 | id => "Test 2", |
|---|
| 39 | ); |
|---|
| 40 | like( $output, qr/>Bars<\/a>/, "...and can be overridden" ); |
|---|
| 41 | |
|---|
| 42 | # Test @INDEX_LIST |
|---|
| 43 | $wiki->write_node( "Test 3", "\@INDEX_LIST [[Category Foo]]" ) |
|---|
| 44 | or die "Can't write node"; |
|---|
| 45 | $wiki->write_node( "Test 4", "\@INDEX_LIST [[Locale Bar]]" ) |
|---|
| 46 | or die "Can't write node"; |
|---|
| 47 | $wiki->write_node( "Test 5", "\@INDEX_LIST [[Category Nonexistent]]" ) |
|---|
| 48 | or die "Can't write node"; |
|---|
| 49 | $wiki->write_node( "Test 6", "\@INDEX_LIST [[Locale Nonexistent]]" ) |
|---|
| 50 | or die "Can't write node"; |
|---|
| 51 | $wiki->write_node( "Wibble", "wibble", undef, |
|---|
| 52 | { |
|---|
| 53 | category => "foo", |
|---|
| 54 | locale => "bar", |
|---|
| 55 | } |
|---|
| 56 | ) |
|---|
| 57 | or die "Can't write node"; |
|---|
| 58 | $output = $guide->display_node( |
|---|
| 59 | return_output => 1, |
|---|
| 60 | id => "Test 3", |
|---|
| 61 | ); |
|---|
| 62 | like ( $output, qr|<a href=".*">Wibble</a>|, |
|---|
| 63 | '@INDEX_LIST works for categories' ); |
|---|
| 64 | $output = $guide->display_node( |
|---|
| 65 | return_output => 1, |
|---|
| 66 | id => "Test 5", |
|---|
| 67 | ); |
|---|
| 68 | like ( $output, qr|No pages currently in category|, |
|---|
| 69 | "...and fails nicely if no pages in category" ); |
|---|
| 70 | $output = $guide->display_node( |
|---|
| 71 | return_output => 1, |
|---|
| 72 | id => "Test 4", |
|---|
| 73 | ); |
|---|
| 74 | like ( $output, qr|<a href=".*">Wibble</a>|, |
|---|
| 75 | '@INDEX_LIST works for locales' ); |
|---|
| 76 | $output = $guide->display_node( |
|---|
| 77 | return_output => 1, |
|---|
| 78 | id => "Test 6", |
|---|
| 79 | ); |
|---|
| 80 | like ( $output, qr|No pages currently in locale|, |
|---|
| 81 | "...and fails nicely if no pages in locale" ); |
|---|
| 82 | } |
|---|