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

(-)a/Koha/Plugins/Method.pm (-24 lines)
Lines 17-26 package Koha::Plugins::Method; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
21
use Koha::Cache::Memory::Lite;
22
use Koha::Plugins;
23
24
use base qw(Koha::Object);
20
use base qw(Koha::Object);
25
21
26
=head1 NAME
22
=head1 NAME
Lines 31-56 Koha::Plugin::Method - Koha Plugin Method Object class Link Here
31
27
32
=head2 Class Methods
28
=head2 Class Methods
33
29
34
=head3 delete
35
36
    Delete method record.
37
    But also delete associated plugin_data records.
38
    Clear cache key.
39
40
=cut
41
42
sub delete {
43
    my ($self) = @_;
44
45
    # Remove corresponding records from plugin_data. Clear cache.
46
    my $cond = { plugin_class => $self->plugin_class };
47
    Koha::Database->new->schema->resultset('PluginData')->search($cond)->delete;
48
    Koha::Cache::Memory::Lite->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY );
49
50
    # Now do the actual delete
51
    return $self->SUPER::delete;
52
}
53
54
=head3 type
30
=head3 type
55
31
56
=cut
32
=cut
(-)a/t/db_dependent/Koha/Plugins/BackgroundJob.t (-1 / +1 lines)
Lines 84-89 subtest 'background_tasks() hooks tests' => sub { Link Here
84
84
85
    is_deeply( $tasks, $bj->core_types_to_classes, 'Only core mapping returned when plugins disabled' );
85
    is_deeply( $tasks, $bj->core_types_to_classes, 'Only core mapping returned when plugins disabled' );
86
86
87
    $schema->storage->txn_rollback;
88
    Koha::Plugins->RemovePlugins;
87
    Koha::Plugins->RemovePlugins;
88
    $schema->storage->txn_rollback;
89
};
89
};
(-)a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t (-1 / +1 lines)
Lines 99-104 subtest 'patron_barcode_transform() and item_barcode_transform() hook tests' => Link Here
99
        qr/Plugin error \(Test Plugin\): Exception 'Koha::Exception' thrown 'item_barcode_transform called with parameter: THISISATEST'/,
99
        qr/Plugin error \(Test Plugin\): Exception 'Koha::Exception' thrown 'item_barcode_transform called with parameter: THISISATEST'/,
100
        'Koha::Item->store calls the item_barcode_transform hook';
100
        'Koha::Item->store calls the item_barcode_transform hook';
101
101
102
    $schema->storage->txn_rollback;
103
    Koha::Plugins->RemovePlugins;
102
    Koha::Plugins->RemovePlugins;
103
    $schema->storage->txn_rollback;
104
};
104
};
(-)a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t (-1 / +1 lines)
Lines 83-88 subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { Link Here
83
            qr/after_biblio_action called with action: delete, id: $biblio_id/,
83
            qr/after_biblio_action called with action: delete, id: $biblio_id/,
84
            'DelBiblio calls the hook with action=delete biblio_id passed';
84
            'DelBiblio calls the hook with action=delete biblio_id passed';
85
85
86
    $schema->storage->txn_rollback;
87
    Koha::Plugins->RemovePlugins;
86
    Koha::Plugins->RemovePlugins;
87
    $schema->storage->txn_rollback;
88
};
88
};
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (-1 / +1 lines)
Lines 120-125 subtest 'after_circ_action() hook tests' => sub { Link Here
120
          'AddReturn calls the after_circ_action hook';
120
          'AddReturn calls the after_circ_action hook';
121
    };
121
    };
122
122
123
    $schema->storage->txn_rollback;
124
    Koha::Plugins->RemovePlugins;
123
    Koha::Plugins->RemovePlugins;
124
    $schema->storage->txn_rollback;
125
};
125
};
(-)a/t/db_dependent/Koha/Plugins/Method.t (-73 lines)
Lines 1-73 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2023 Rijksmuseum, Koha development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Test::MockModule;
22
use Test::More tests => 1;
23
24
use t::lib::TestBuilder;
25
26
use Koha::Database;
27
use Koha::Cache::Memory::Lite;
28
use Koha::Plugins;
29
use Koha::Plugins::Methods;
30
31
my $builder = t::lib::TestBuilder->new;
32
my $schema  = Koha::Database->new->schema;
33
34
$schema->storage->txn_begin;
35
36
# We need to mock can_load from Module::Load::Conditional in Koha/Plugins
37
my $mock = Test::MockModule->new('Koha::Plugins')->mock( can_load => 1 );
38
39
subtest 'delete' => sub {
40
    plan tests => 7;
41
42
    my $count_m = Koha::Plugins::Methods->count;
43
    my $count_d = $schema->resultset('PluginData')->count;
44
    Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY );
45
    my @enabled_plugins = Koha::Plugins->get_enabled_plugins;
46
47
    # Mock creation of new plugin
48
    my $method = $builder->build_object( { class => 'Koha::Plugins::Methods' } );
49
    my $values = { plugin_class => $method->plugin_class, plugin_key => '__ENABLED__', plugin_value => 1 };
50
    my $data   = $builder->build( { source => 'PluginData', value => $values } );
51
52
    # Note: no_auto => 1 in next call prevent loading of a not-existing module
53
    my $plugin_mock = Test::MockModule->new( $method->plugin_class, no_auto => 1 )
54
        ->mock( new => bless( { mocked => 1 }, $method->plugin_class ) );
55
56
    # Check for new method and if get_enabled_plugins sees it too
57
    is( Koha::Plugins::Methods->count,           $count_m + 1, 'Expect a new method' );
58
    is( $schema->resultset('PluginData')->count, $count_d + 1, 'Expect entry in plugin_data' );
59
    Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY );
60
    is( scalar Koha::Plugins->get_enabled_plugins, 1 + @enabled_plugins, 'Recheck get_enabled_plugins' );
61
62
    # Delete the method from plugin_methods, check table and cache
63
    Koha::Plugins::Methods->search( { plugin_class => $method->plugin_class } )->delete;
64
    is(
65
        Koha::Cache::Memory::Lite->get_instance->get_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ),
66
        undef, 'Cache has been cleared by delete method'
67
    );
68
    is( Koha::Plugins::Methods->count,             $count_m,                'Original number of methods' );
69
    is( $schema->resultset('PluginData')->count,   $count_d,                'Original count in plugin_data' );
70
    is( scalar Koha::Plugins->get_enabled_plugins, scalar @enabled_plugins, 'Original number of enabled plugins' );
71
};
72
73
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Plugins/Patron.t (-3 / +1 lines)
Lines 87-94 subtest 'check_password hook tests' => sub { Link Here
87
    ok( $patron->set_password({ password => '4321' }), 'Patron password updated with good string' );
87
    ok( $patron->set_password({ password => '4321' }), 'Patron password updated with good string' );
88
    ok( $patron->set_password({ password => 'explosion', skip_validation => 1}), 'Patron password updated via skip validation');
88
    ok( $patron->set_password({ password => 'explosion', skip_validation => 1}), 'Patron password updated via skip validation');
89
89
90
    $schema->storage->txn_rollback;
91
    Koha::Plugins->RemovePlugins;
90
    Koha::Plugins->RemovePlugins;
91
    $schema->storage->txn_rollback;
92
};
92
};
93
94
1;
(-)a/t/db_dependent/Koha/Plugins/authority_hooks.t (-2 / +1 lines)
Lines 65-70 subtest 'after_authority_action hook' => sub { Link Here
65
            qr/after_authority_action called with action: delete, id: $id/,
65
            qr/after_authority_action called with action: delete, id: $id/,
66
            'DelAuthority calls the hook with action=delete, id passed';
66
            'DelAuthority calls the hook with action=delete, id passed';
67
67
68
    $schema->storage->txn_rollback;
69
    Koha::Plugins->RemovePlugins;
68
    Koha::Plugins->RemovePlugins;
69
    $schema->storage->txn_rollback;
70
};
70
};
71
- 

Return to bug 35536