root/tags/rel0_59/t/70_admin_home.t

Revision 959, 2.3 kB (checked in by kake, 22 months ago)

Fix up test 70 so it doesn't occasionally fail when writing of test data spans the 1-second boundary.

Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    my ($error) = $@ =~ /^(.*?)\n/;
10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
11}
12
13plan tests => 12;
14
15Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
16my $config = OpenGuides::Test->make_basic_config;
17$config->script_name( "wiki.cgi" );
18$config->script_url( "http://example.com/" );
19my $guide = OpenGuides->new( config => $config );
20isa_ok( $guide, "OpenGuides" );
21my $wiki = $guide->wiki;
22isa_ok( $wiki, "Wiki::Toolkit" );
23
24# Clear out the database from any previous runs.
25foreach 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";
41my %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
48my %ttvars = eval {
49       $guide->display_admin_interface( return_tt_vars=> 1 );
50};
51is( $@, "", "->display_admin_interface doesn't die" );
52
53is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" );
54is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" );
55is( scalar @{$ttvars{'categories'}}, 0, "Right number of categories" );
56
57my @node_names = map { $_->{name}; } @{$ttvars{nodes}};
58is_deeply( [ sort @node_names ], [ "Test Page", "Test Page 2" ],
59           "Right nodes" );
60is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" );
61
62# Test the normal, HTML version
63my $output = eval {
64    $guide->display_admin_interface( return_output=>1 );
65};
66is( $@, "", "->display_admin_interface doesn't die" );
67
68like( $output, qr|Site Administration|, "Right page" );
69like( $output, qr|Test Page|, "Has nodes" );
70like( $output, qr|Bar|, "Has locales" );
Note: See TracBrowser for help on using the browser.