Lines 24-34
use File::Temp qw( tempdir tempfile );
Link Here
|
24 |
use FindBin qw($Bin); |
24 |
use FindBin qw($Bin); |
25 |
use Module::Load::Conditional qw(can_load); |
25 |
use Module::Load::Conditional qw(can_load); |
26 |
use Test::MockModule; |
26 |
use Test::MockModule; |
27 |
use Test::More tests => 16; |
27 |
use Test::More tests => 17; |
28 |
use Test::Warn; |
28 |
use Test::Warn; |
29 |
|
29 |
|
30 |
use C4::Context; |
30 |
use C4::Context; |
31 |
use Koha::Database; |
31 |
use Koha::Database; |
|
|
32 |
use Koha::Plugins::Datas; |
32 |
use Koha::Plugins::Methods; |
33 |
use Koha::Plugins::Methods; |
33 |
|
34 |
|
34 |
use t::lib::Mocks; |
35 |
use t::lib::Mocks; |
Lines 130-137
subtest 'more call() tests' => sub {
Link Here
|
130 |
$schema->storage->txn_rollback; |
131 |
$schema->storage->txn_rollback; |
131 |
}; |
132 |
}; |
132 |
|
133 |
|
133 |
$schema->storage->txn_begin; # matching rollback at the very end |
|
|
134 |
|
135 |
subtest 'feature_enabled tests' => sub { |
134 |
subtest 'feature_enabled tests' => sub { |
136 |
plan tests => 4; |
135 |
plan tests => 4; |
137 |
|
136 |
|
Lines 325-330
subtest 'Koha::Plugin::Test' => sub {
Link Here
|
325 |
$schema->storage->txn_rollback; |
324 |
$schema->storage->txn_rollback; |
326 |
}; |
325 |
}; |
327 |
|
326 |
|
|
|
327 |
$schema->storage->txn_begin; # Matching rollback at very end |
328 |
|
328 |
subtest 'output and output_html tests' => sub { |
329 |
subtest 'output and output_html tests' => sub { |
329 |
|
330 |
|
330 |
plan tests => 6; |
331 |
plan tests => 6; |
Lines 412-416
subtest 'new() tests' => sub {
Link Here
|
412 |
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' ); |
413 |
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' ); |
413 |
}; |
414 |
}; |
414 |
|
415 |
|
415 |
Koha::Plugins::Methods->delete; |
416 |
subtest 'RemovePlugins' => sub { |
|
|
417 |
plan tests => 9; |
418 |
|
419 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
420 |
|
421 |
# We need to mock can_load from Module::Load::Conditional in Koha/Plugins |
422 |
my $mock = Test::MockModule->new('Koha::Plugins')->mock( can_load => 1 ); |
423 |
|
424 |
# First call without argument |
425 |
Koha::Plugins->RemovePlugins; |
426 |
is( Koha::Plugins::Datas->count, 0, 'No data in plugin_data' ); |
427 |
is( Koha::Plugins::Methods->count, 0, 'No data in plugin_methods' ); |
428 |
my @enabled_plugins = Koha::Plugins->get_enabled_plugins; |
429 |
|
430 |
# Mock creation of three new plugins |
431 |
my ( @data, @methods, @mocks ); |
432 |
my $class_basename = 'Koha::Plugin::TestMR::' . time; |
433 |
foreach my $i ( 1 .. 3 ) { |
434 |
push @data, |
435 |
Koha::Plugins::Data->new( |
436 |
{ plugin_class => "$class_basename$i", plugin_key => '__ENABLED__', plugin_value => 1 } )->store; |
437 |
push @methods, |
438 |
Koha::Plugins::Method->new( { plugin_class => "$class_basename$i", plugin_method => "testmr$i" } )->store; |
439 |
|
440 |
# no_auto => 1 here prevents loading of a not-existing module |
441 |
push @mocks, |
442 |
Test::MockModule->new( "$class_basename$i", no_auto => 1 ) |
443 |
->mock( new => bless( { mocked => 1 }, "$class_basename$i" ) ); |
444 |
} |
445 |
|
446 |
# Check for new method and if get_enabled_plugins sees it too |
447 |
is( Koha::Plugins::Datas->count, 3, 'Records in plugin_data' ); |
448 |
is( Koha::Plugins::Methods->count, 3, 'Records in plugin_methods' ); |
449 |
Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); |
450 |
is( scalar Koha::Plugins->get_enabled_plugins, 3, 'Check get_enabled_plugins again' ); |
451 |
|
452 |
# Call with argument: delete specific method, check tables and cache again |
453 |
Koha::Plugins->RemovePlugins( { plugin_class => $class_basename . "2" } ); |
454 |
is( |
455 |
Koha::Cache::Memory::Lite->get_instance->get_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ), |
456 |
undef, 'Cache has been cleared by delete method' |
457 |
); |
458 |
is( Koha::Plugins::Datas->count, 2, 'One record less in plugin_data' ); |
459 |
is( Koha::Plugins::Methods->count, 2, 'One record less in plugin_methods' ); |
460 |
is( scalar Koha::Plugins->get_enabled_plugins, 2, 'Check get_enabled_plugins' ); |
461 |
}; |
462 |
|
416 |
$schema->storage->txn_rollback; |
463 |
$schema->storage->txn_rollback; |
417 |
- |
|
|