source: trunk/t/70_admin_home.t @ 878

Last change on this file since 878 was 823, checked in by nick, 15 years ago

Add tests for admin home page

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