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