Changeset 925


Ignore:
Timestamp:
Mar 10, 2007, 3:25:25 PM (14 years ago)
Author:
kake
Message:

Make sure we warn instead of dying if a guide asks for ping services but we haven't got Wiki::Toolkit::Plugin::Ping installed; also add tests for this; also skip testing the plugin's functionality if we haven't got it. closes #167

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r919 r925  
    6969
    7070    if($self->config->ping_services) {
    71         require Wiki::Toolkit::Plugin::Ping;
    72 
    73         my @ws = split(/\s*,\s*/, $self->config->ping_services);
    74         my %well_known = Wiki::Toolkit::Plugin::Ping->well_known;
    75         my %services;
    76         foreach my $s (@ws) {
    77             if($well_known{$s}) {
    78                 $services{$s} = $well_known{$s};
    79             } else {
    80                 warn("Ignoring unknown ping service '$s'");
     71        eval {
     72            require Wiki::Toolkit::Plugin::Ping;
     73        };
     74
     75        if ( $@ ) {
     76            warn "You asked for some ping services, but can't find "
     77                 . "Wiki::Toolkit::Plugin::Ping";
     78        } else {
     79            my @ws = split(/\s*,\s*/, $self->config->ping_services);
     80            my %well_known = Wiki::Toolkit::Plugin::Ping->well_known;
     81            my %services;
     82            foreach my $s (@ws) {
     83                if($well_known{$s}) {
     84                    $services{$s} = $well_known{$s};
     85                } else {
     86                    warn("Ignoring unknown ping service '$s'");
     87                }
    8188            }
    82         }
    83         my $ping = Wiki::Toolkit::Plugin::Ping->new(
    84             node_to_url => $self->{config}->{script_url} . $self->{config}->{script_name} . '?$node',
    85             services => \%services
    86         );
    87         $wiki->register_plugin( plugin => $ping );
     89            my $ping = Wiki::Toolkit::Plugin::Ping->new(
     90                node_to_url => $self->{config}->{script_url}
     91                               . $self->{config}->{script_name} . '?$node',
     92                services => \%services
     93            );
     94            $wiki->register_plugin( plugin => $ping );
     95        }
    8896    }
    8997
  • trunk/t/74_ping_plugin.t

    r924 r925  
    99  plan skip_all => "DBD::SQLite not installed - no database to test with";
    1010} else {
    11   plan tests => 9;
     11  plan tests => 11;
    1212}
     13
     14eval { require Wiki::Toolkit::Plugin::Ping; };
     15my $have_ping = $@ ? 0 : 1;
    1316
    1417Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     
    2831my $guide = OpenGuides->new( config => $config );
    2932
    30 ok($guide, "Made the guide OK");
     33ok( $guide, "Created a guide with blank ping_services" );
    3134
    3235# Check for the plugin
    3336my @plugins = @{ $guide->wiki->{_registered_plugins} };
    34 is( scalar @plugins, 2, "Two plugins to start" );
     37is( scalar @plugins, 2, "...and it has two plugins" );
    3538
    3639
     
    4952            }
    5053);
    51 $guide = OpenGuides->new( config => $config );
    5254
    53 ok($guide, "Made the guide OK");
     55SKIP: {
     56    skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful "
     57         . "failure", 2
     58        if $have_ping;
     59    eval {
     60        $guide = OpenGuides->new( config => $config );
     61    };
     62    ok( !$@, "Guide creation doesn't die if we ask for ping_services but "
     63        . "don't have Wiki::Toolkit::Plugin::Ping" );
     64    eval {
     65        local $SIG{__WARN__} = sub { die $_[0]; };
     66        $guide = OpenGuides->new( config => $config );
     67    };
     68    ok( $@, "...but it does warn" );
     69}
    5470
    55 @plugins = @{ $guide->wiki->{_registered_plugins} };
    56 is( scalar @plugins, 3, "Has plugin now" );
    57 ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" );
    58 ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" );
     71SKIP: {
     72    skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works",
     73         7
     74        unless $have_ping;
    5975
    60 # Check it has the right services registered
    61 my %services = $plugins[2]->services;
    62 my @snames = sort keys %services;
    63 is( scalar @snames, 2, "Has 2 services as expected" );
    64 is( $snames[0], "geourl", "Right service" );
    65 is( $snames[1], "pingerati", "Right service" );
     76    $guide = OpenGuides->new( config => $config );
     77    ok($guide, "Made the guide OK");
    6678
     79    @plugins = @{ $guide->wiki->{_registered_plugins} };
     80    is( scalar @plugins, 3, "Has plugin now" );
     81    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" );
     82    ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" );
     83
     84    # Check it has the right services registered
     85    my %services = $plugins[2]->services;
     86    my @snames = sort keys %services;
     87    is( scalar @snames, 2, "Has 2 services as expected" );
     88    is( $snames[0], "geourl", "Right service" );
     89    is( $snames[1], "pingerati", "Right service" );
     90}
Note: See TracChangeset for help on using the changeset viewer.