View | Details | Raw Unified | Return to bug 29121
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-7 / +20 lines)
Lines 25-31 use File::Temp qw( tempdir tempfile ); Link Here
25
use FindBin qw($Bin);
25
use FindBin qw($Bin);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Load::Conditional qw(can_load);
27
use Test::MockModule;
27
use Test::MockModule;
28
use Test::More tests => 55;
28
use Test::More tests => 58;
29
use Test::Warn;
29
30
30
use C4::Context;
31
use C4::Context;
31
use Koha::Database;
32
use Koha::Database;
Lines 47-53 BEGIN { Link Here
47
my $schema = Koha::Database->new->schema;
48
my $schema = Koha::Database->new->schema;
48
49
49
subtest 'call() tests' => sub {
50
subtest 'call() tests' => sub {
50
    plan tests => 3;
51
52
    plan tests => 4;
51
53
52
    $schema->storage->txn_begin;
54
    $schema->storage->txn_begin;
53
    # Temporarily remove any installed plugins data
55
    # Temporarily remove any installed plugins data
Lines 55-61 subtest 'call() tests' => sub { Link Here
55
57
56
    t::lib::Mocks::mock_config('enable_plugins', 1);
58
    t::lib::Mocks::mock_config('enable_plugins', 1);
57
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
59
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
58
    my @plugins = $plugins->InstallPlugins;
60
61
    my @plugins;
62
63
    warnings_are
64
     { @plugins = $plugins->InstallPlugins; }
65
     [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
66
59
    foreach my $plugin (@plugins) {
67
    foreach my $plugin (@plugins) {
60
        $plugin->enable();
68
        $plugin->enable();
61
    }
69
    }
Lines 80-93 subtest 'call() tests' => sub { Link Here
80
88
81
subtest 'GetPlugins() tests' => sub {
89
subtest 'GetPlugins() tests' => sub {
82
90
83
    plan tests => 2;
91
    plan tests => 3;
84
92
85
    $schema->storage->txn_begin;
93
    $schema->storage->txn_begin;
86
    # Temporarily remove any installed plugins data
94
    # Temporarily remove any installed plugins data
87
    Koha::Plugins::Methods->delete;
95
    Koha::Plugins::Methods->delete;
88
96
89
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
97
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
90
    $plugins->InstallPlugins;
98
99
    warnings_are { $plugins->InstallPlugins; }
100
    [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
91
101
92
    my @plugins = $plugins->GetPlugins({ method => 'report', all => 1 });
102
    my @plugins = $plugins->GetPlugins({ method => 'report', all => 1 });
93
103
Lines 148-154 subtest 'is_enabled() tests' => sub { Link Here
148
$schema->storage->txn_begin;
158
$schema->storage->txn_begin;
149
Koha::Plugins::Methods->delete;
159
Koha::Plugins::Methods->delete;
150
160
151
Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins();
161
warnings_are { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); }
162
[ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
152
163
153
ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
164
ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
154
is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' );
165
is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' );
Lines 262-268 for my $pass ( 1 .. 2 ) { Link Here
262
273
263
    ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
274
    ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
264
    $INC{$pm_path} = $full_pm_path; # FIXME I do not really know why, but if this is moved before the $plugin constructor, it will fail with Can't locate object method "new" via package "Koha::Plugin::Com::ByWaterSolutions::KitchenSink"
275
    $INC{$pm_path} = $full_pm_path; # FIXME I do not really know why, but if this is moved before the $plugin constructor, it will fail with Can't locate object method "new" via package "Koha::Plugin::Com::ByWaterSolutions::KitchenSink"
265
    Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins();
276
    warnings_are
277
        { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); }
278
        [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
266
    ok( -f $full_pm_path, "Koha::Plugins::Handler::delete works correctly (pass $pass)" );
279
    ok( -f $full_pm_path, "Koha::Plugins::Handler::delete works correctly (pass $pass)" );
267
    Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins => 1 });
280
    Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins => 1 });
268
    my $sth = C4::Context->dbh->table_info( undef, undef, $table, 'TABLE' );
281
    my $sth = C4::Context->dbh->table_info( undef, undef, $table, 'TABLE' );
(-)a/t/lib/Koha/Plugin/BrokenInstall.pm (+30 lines)
Line 0 Link Here
1
package Koha::Plugin::BrokenInstall;
2
3
use Modern::Perl;
4
5
use base qw(Koha::Plugins::Base);
6
7
our $VERSION = 1.01;
8
our $metadata = {
9
    name            => 'Broken install plugin',
10
    author          => 'Kyle M Hall',
11
    description     => 'Broken install plugin',
12
    date_authored   => '2013-01-14',
13
    date_updated    => '2013-01-14',
14
    minimum_version => '3.11',
15
    maximum_version => undef,
16
    version         => $VERSION,
17
};
18
19
sub new {
20
    my ( $class, $args ) = @_;
21
    $args->{'metadata'} = $metadata;
22
    my $self = $class->SUPER::new($args);
23
    return $self;
24
}
25
26
sub install {
27
    die "Why Liz? WHY?";
28
}
29
30
1;
(-)a/t/lib/Koha/Plugin/BrokenUpgrade.pm (-1 / +30 lines)
Line 0 Link Here
0
- 
1
package Koha::Plugin::BrokenUpgrade;
2
3
use Modern::Perl;
4
5
use base qw(Koha::Plugins::Base);
6
7
our $VERSION = 1.01;
8
our $metadata = {
9
    name            => 'Broken upgrade plugin',
10
    author          => 'Kyle M Hall',
11
    description     => 'Broken upgrade plugin',
12
    date_authored   => '2013-01-14',
13
    date_updated    => '2013-01-14',
14
    minimum_version => '3.11',
15
    maximum_version => undef,
16
    version         => $VERSION,
17
};
18
19
sub new {
20
    my ( $class, $args ) = @_;
21
    $args->{'metadata'} = $metadata;
22
    my $self = $class->SUPER::new($args);
23
    return $self;
24
}
25
26
sub upgrade {
27
    die "Why Liz? WHY?";
28
}
29
30
1;

Return to bug 29121