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

Last change on this file since 1033 was 1033, checked in by kake, 14 years ago

Suppress expected warnings in ping test.

File size: 3.1 KB
RevLine 
[874]1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
[924]8if ( $@ ) {
[956]9    my ($error) = $@ =~ /^(.*?)\n/;
10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
[924]11}
[874]12
[956]13plan tests => 11;
14
[925]15eval { require Wiki::Toolkit::Plugin::Ping; };
16my $have_ping = $@ ? 0 : 1;
17
[924]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 );
[874]33
[925]34ok( $guide, "Created a guide with blank ping_services" );
[874]35
[924]36# Check for the plugin
37my @plugins = @{ $guide->wiki->{_registered_plugins} };
[925]38is( scalar @plugins, 2, "...and it has two plugins" );
[874]39
40
[924]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);
[874]55
[925]56SKIP: {
57    skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful "
58         . "failure", 2
59        if $have_ping;
60    eval {
[1033]61        # Suppress warnings; we expect them.
62        local $SIG{__WARN__} = sub { };
[925]63        $guide = OpenGuides->new( config => $config );
64    };
65    ok( !$@, "Guide creation doesn't die if we ask for ping_services but "
66        . "don't have Wiki::Toolkit::Plugin::Ping" );
67    eval {
68        local $SIG{__WARN__} = sub { die $_[0]; };
69        $guide = OpenGuides->new( config => $config );
70    };
71    ok( $@, "...but it does warn" );
72}
[874]73
[925]74SKIP: {
75    skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works",
76         7
77        unless $have_ping;
[874]78
[925]79    $guide = OpenGuides->new( config => $config );
80    ok($guide, "Made the guide OK");
[874]81
[925]82    @plugins = @{ $guide->wiki->{_registered_plugins} };
83    is( scalar @plugins, 3, "Has plugin now" );
84    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" );
85    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" );
86
87    # Check it has the right services registered
88    my %services = $plugins[2]->services;
89    my @snames = sort keys %services;
90    is( scalar @snames, 2, "Has 2 services as expected" );
91    is( $snames[0], "geourl", "Right service" );
92    is( $snames[1], "pingerati", "Right service" );
93}
Note: See TracBrowser for help on using the repository browser.