File: 704_ping_plugin.t

package info (click to toggle)
openguides 0.84-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,628 kB
  • sloc: perl: 4,812; sh: 56; javascript: 56; makefile: 19
file content (94 lines) | stat: -rw-r--r-- 3,130 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use strict;
use Wiki::Toolkit::Setup::SQLite;
use OpenGuides;
use OpenGuides::Test;
use Test::More;

eval { require DBD::SQLite; };
if ( $@ ) {
    my ($error) = $@ =~ /^(.*?)\n/;
    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
}

plan tests => 11;

eval { require Wiki::Toolkit::Plugin::Ping; };
my $have_ping = $@ ? 0 : 1;

    OpenGuides::Test::refresh_db();

my $config = OpenGuides::Config->new(
    vars => {
                dbtype             => "sqlite",
                dbname             => "t/node.db",
                indexing_directory => "t/indexes",
                script_url         => "http://wiki.example.com/",
                script_name        => "mywiki.cgi",
                site_name          => "Wiki::Toolkit Test Site",
                default_city       => "London",
                default_country    => "United Kingdom",
                ping_services      => ""
            }
);
my $guide = OpenGuides->new( config => $config );

ok( $guide, "Created a guide with blank ping_services" );

# Check for the plugin
my @plugins = @{ $guide->wiki->{_registered_plugins} };
is( scalar @plugins, 2, "...and it has two plugins" );


# Now with the plugin
$config = OpenGuides::Config->new(
    vars => {
                dbtype             => "sqlite",
                dbname             => "t/node.db",
                indexing_directory => "t/indexes",
                script_url         => "http://wiki.example.com/",
                script_name        => "mywiki.cgi",
                site_name          => "Wiki::Toolkit Test Site",
                default_city       => "London",
                default_country    => "United Kingdom",
                ping_services      => "pingerati,geourl,FOOOO"
            }
);

SKIP: {
    skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful "
         . "failure", 2
        if $have_ping;
    eval {
        # Suppress warnings; we expect them.
        local $SIG{__WARN__} = sub { };
        $guide = OpenGuides->new( config => $config );
    };
    ok( !$@, "Guide creation doesn't die if we ask for ping_services but "
        . "don't have Wiki::Toolkit::Plugin::Ping" );
    eval {
        local $SIG{__WARN__} = sub { die $_[0]; };
        $guide = OpenGuides->new( config => $config );
    };
    ok( $@, "...but it does warn" );
}

SKIP: {
    skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works",
         7
        unless $have_ping;

    $guide = OpenGuides->new( config => $config );
    ok($guide, "Made the guide OK");

    @plugins = @{ $guide->wiki->{_registered_plugins} };
    is( scalar @plugins, 3, "Has plugin now" );
    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" );
    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" );

    # Check it has the right services registered
    my %services = $plugins[2]->services;
    my @snames = sort keys %services;
    is( scalar @snames, 2, "Has 2 services as expected" );
    is( $snames[0], "geourl", "Right service" );
    is( $snames[1], "pingerati", "Right service" );
}