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; |