| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 10 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | plan tests => 11; |
|---|
| 14 | |
|---|
| 15 | eval { require Wiki::Toolkit::Plugin::Ping; }; |
|---|
| 16 | my $have_ping = $@ ? 0 : 1; |
|---|
| 17 | |
|---|
| 18 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 19 | my $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 | ); |
|---|
| 32 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 33 | |
|---|
| 34 | ok( $guide, "Created a guide with blank ping_services" ); |
|---|
| 35 | |
|---|
| 36 | # Check for the plugin |
|---|
| 37 | my @plugins = @{ $guide->wiki->{_registered_plugins} }; |
|---|
| 38 | is( 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 | |
|---|
| 56 | SKIP: { |
|---|
| 57 | skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful " |
|---|
| 58 | . "failure", 2 |
|---|
| 59 | if $have_ping; |
|---|
| 60 | eval { |
|---|
| 61 | # Suppress warnings; we expect them. |
|---|
| 62 | local $SIG{__WARN__} = sub { }; |
|---|
| 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 | } |
|---|
| 73 | |
|---|
| 74 | SKIP: { |
|---|
| 75 | skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works", |
|---|
| 76 | 7 |
|---|
| 77 | unless $have_ping; |
|---|
| 78 | |
|---|
| 79 | $guide = OpenGuides->new( config => $config ); |
|---|
| 80 | ok($guide, "Made the guide OK"); |
|---|
| 81 | |
|---|
| 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 | } |
|---|