source: trunk/t/74_ping_plugin.t @ 1273

Last change on this file since 1273 was 1273, checked in by Dominic Hargreaves, 12 years ago

test cleanups for refreshing the test db (thanks bob) (fixes #271)

File size: 3.1 KB
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 => 11;
14
15eval { require Wiki::Toolkit::Plugin::Ping; };
16my $have_ping = $@ ? 0 : 1;
17
18    OpenGuides::Test::refresh_db();
19
20my $config = OpenGuides::Config->new(
21    vars => {
22                dbtype             => "sqlite",
23                dbname             => "t/node.db",
24                indexing_directory => "t/indexes",
25                script_url         => "http://wiki.example.com/",
26                script_name        => "mywiki.cgi",
27                site_name          => "Wiki::Toolkit Test Site",
28                default_city       => "London",
29                default_country    => "United Kingdom",
30                ping_services      => ""
31            }
32);
33my $guide = OpenGuides->new( config => $config );
34
35ok( $guide, "Created a guide with blank ping_services" );
36
37# Check for the plugin
38my @plugins = @{ $guide->wiki->{_registered_plugins} };
39is( scalar @plugins, 2, "...and it has two plugins" );
40
41
42# Now with the plugin
43$config = OpenGuides::Config->new(
44    vars => {
45                dbtype             => "sqlite",
46                dbname             => "t/node.db",
47                indexing_directory => "t/indexes",
48                script_url         => "http://wiki.example.com/",
49                script_name        => "mywiki.cgi",
50                site_name          => "Wiki::Toolkit Test Site",
51                default_city       => "London",
52                default_country    => "United Kingdom",
53                ping_services      => "pingerati,geourl,FOOOO"
54            }
55);
56
57SKIP: {
58    skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful "
59         . "failure", 2
60        if $have_ping;
61    eval {
62        # Suppress warnings; we expect them.
63        local $SIG{__WARN__} = sub { };
64        $guide = OpenGuides->new( config => $config );
65    };
66    ok( !$@, "Guide creation doesn't die if we ask for ping_services but "
67        . "don't have Wiki::Toolkit::Plugin::Ping" );
68    eval {
69        local $SIG{__WARN__} = sub { die $_[0]; };
70        $guide = OpenGuides->new( config => $config );
71    };
72    ok( $@, "...but it does warn" );
73}
74
75SKIP: {
76    skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works",
77         7
78        unless $have_ping;
79
80    $guide = OpenGuides->new( config => $config );
81    ok($guide, "Made the guide OK");
82
83    @plugins = @{ $guide->wiki->{_registered_plugins} };
84    is( scalar @plugins, 3, "Has plugin now" );
85    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" );
86    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" );
87
88    # Check it has the right services registered
89    my %services = $plugins[2]->services;
90    my @snames = sort keys %services;
91    is( scalar @snames, 2, "Has 2 services as expected" );
92    is( $snames[0], "geourl", "Right service" );
93    is( $snames[1], "pingerati", "Right service" );
94}
Note: See TracBrowser for help on using the repository browser.