| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 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 => 12; |
|---|
| 14 | |
|---|
| 15 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 16 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 17 | $config->script_name( "wiki.cgi" ); |
|---|
| 18 | $config->script_url( "http://example.com/" ); |
|---|
| 19 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 20 | isa_ok( $guide, "OpenGuides" ); |
|---|
| 21 | my $wiki = $guide->wiki; |
|---|
| 22 | isa_ok( $wiki, "Wiki::Toolkit" ); |
|---|
| 23 | |
|---|
| 24 | # Clear out the database from any previous runs. |
|---|
| 25 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 26 | print "# Deleting node $del_node\n"; |
|---|
| 27 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | # Add 3 different pages, one of which with two versions |
|---|
| 32 | $wiki->write_node( "Test Page", "foo", undef, |
|---|
| 33 | { category => "Alpha" } ) |
|---|
| 34 | or die "Couldn't write node"; |
|---|
| 35 | $wiki->write_node( "Test Page 2", "foo", undef, |
|---|
| 36 | { category => "Alpha" } ) |
|---|
| 37 | or die "Couldn't write node"; |
|---|
| 38 | $wiki->write_node( "Locale Bar", "foo", undef, |
|---|
| 39 | { category => "Locales" } ) |
|---|
| 40 | or die "Couldn't write locale"; |
|---|
| 41 | my %data = $wiki->retrieve_node( "Locale Bar" ); |
|---|
| 42 | $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, |
|---|
| 43 | { category => "Locales" } ) |
|---|
| 44 | or die "Couldn't write locale for the 2nd time"; |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | # Test the tt vars |
|---|
| 48 | my %ttvars = eval { |
|---|
| 49 | $guide->display_admin_interface( return_tt_vars=> 1 ); |
|---|
| 50 | }; |
|---|
| 51 | is( $@, "", "->display_admin_interface doesn't die" ); |
|---|
| 52 | |
|---|
| 53 | is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" ); |
|---|
| 54 | is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" ); |
|---|
| 55 | is( scalar @{$ttvars{'categories'}}, 0, "Right number of categories" ); |
|---|
| 56 | |
|---|
| 57 | my @node_names = map { $_->{name}; } @{$ttvars{nodes}}; |
|---|
| 58 | is_deeply( [ sort @node_names ], [ "Test Page", "Test Page 2" ], |
|---|
| 59 | "Right nodes" ); |
|---|
| 60 | is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" ); |
|---|
| 61 | |
|---|
| 62 | # Test the normal, HTML version |
|---|
| 63 | my $output = eval { |
|---|
| 64 | $guide->display_admin_interface( return_output=>1 ); |
|---|
| 65 | }; |
|---|
| 66 | is( $@, "", "->display_admin_interface doesn't die" ); |
|---|
| 67 | |
|---|
| 68 | like( $output, qr|Site Administration|, "Right page" ); |
|---|
| 69 | like( $output, qr|Test Page|, "Has nodes" ); |
|---|
| 70 | like( $output, qr|Bar|, "Has locales" ); |
|---|