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

(-)a/Koha/Plugins/Method.pm (-1 / +19 lines)
Lines 17-24 package Koha::Plugins::Method; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
21
use Koha::Database;
20
use Koha::Database;
21
use Koha::Plugins::Base qw();
22
22
23
use base qw(Koha::Object);
23
use base qw(Koha::Object);
24
24
Lines 30-37 Koha::Plugin::Method - Koha Plugin Method Object class Link Here
30
30
31
=head2 Class Methods
31
=head2 Class Methods
32
32
33
=head3 delete
34
35
    Delete method record but disable plugin too and clear enabled plugins cache key.
36
33
=cut
37
=cut
34
38
39
sub delete {
40
    my ($self) = @_;
41
42
    # Next call makes sure that plugin is disabled, and ENABLED_PLUGINS_CACHE_KEY is cleared
43
    # The self parameter only needs the class name
44
    Koha::Plugins::Base::store_data(
45
        { class       => $self->plugin_class },
46
        { __ENABLED__ => 0 }
47
    );
48
49
    # Now do the actual delete
50
    return $self->SUPER::delete;
51
}
52
35
=head3 type
53
=head3 type
36
54
37
=cut
55
=cut
(-)a/t/db_dependent/Koha/Plugins/Method.t (-1 / +70 lines)
Line 0 Link Here
0
- 
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 => 5;
41
42
    my $count = Koha::Plugins::Methods->count;
43
    Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY );
44
    my @enabled_plugins = Koha::Plugins->get_enabled_plugins;
45
46
    # Mock creation of new plugin
47
    my $method = $builder->build_object( { class => 'Koha::Plugins::Methods' } );
48
    my $values = { plugin_class => $method->plugin_class, plugin_key => '__ENABLED__', plugin_value => 1 };
49
    my $data   = $builder->build( { source => 'PluginData', value => $values } );
50
51
    # Note: no_auto => 1 in next call prevent loading of a not-existing module
52
    my $plugin_mock = Test::MockModule->new( $method->plugin_class, no_auto => 1 )
53
        ->mock( new => bless( { mocked => 1 }, $method->plugin_class ) );
54
55
    # Check for new method and if get_enabled_plugins sees it too
56
    is( Koha::Plugins::Methods->count, $count + 1, 'Expect a new method' );
57
    Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY );
58
    is( scalar Koha::Plugins->get_enabled_plugins, 1 + @enabled_plugins, 'Recheck get_enabled_plugins' );
59
60
    # Delete the method from plugin_methods, check table and cache
61
    Koha::Plugins::Methods->search( { plugin_class => $method->plugin_class } )->delete;
62
    is(
63
        Koha::Cache::Memory::Lite->get_instance->get_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ),
64
        undef, 'Cache has been cleared by delete method'
65
    );
66
    is( Koha::Plugins::Methods->count,             $count,                  'Original number of methods' );
67
    is( scalar Koha::Plugins->get_enabled_plugins, scalar @enabled_plugins, 'Original number of enabled plugins' );
68
};
69
70
$schema->storage->txn_rollback;

Return to bug 35507