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

Last change on this file since 956 was 956, checked in by Earle Martin, 15 years ago

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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