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::Cache::Memory::Lite; |
31 |
use Koha::Database; |
32 |
use Koha::Database; |
|
|
33 |
use Koha::Plugins::Datas; |
32 |
use Koha::Plugins::Methods; |
34 |
use Koha::Plugins::Methods; |
33 |
|
35 |
|
34 |
use t::lib::Mocks; |
36 |
use t::lib::Mocks; |
Lines 323-329
subtest 'Koha::Plugin::Test' => sub {
Link Here
|
323 |
$schema->storage->txn_rollback; |
325 |
$schema->storage->txn_rollback; |
324 |
}; |
326 |
}; |
325 |
|
327 |
|
326 |
$schema->storage->txn_begin; # matching rollback at the very end |
328 |
subtest 'RemovePlugins' => sub { |
|
|
329 |
plan tests => 3; |
330 |
|
331 |
$schema->storage->txn_begin; |
332 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
333 |
|
334 |
our $class_basename = 'Koha::Plugin::TestMR::' . time; |
335 |
|
336 |
sub reload_plugin { |
337 |
my ( $i, $mocks ) = @_; |
338 |
Koha::Plugins::Data->new( |
339 |
{ plugin_class => "$class_basename$i", plugin_key => '__ENABLED__', plugin_value => 1 } )->store; |
340 |
Koha::Plugins::Method->new( { plugin_class => "$class_basename$i", plugin_method => "testmr$i" } )->store; |
341 |
|
342 |
# no_auto => 1 here prevents loading of a not-existing module |
343 |
$mocks->[$i] = Test::MockModule->new( "$class_basename$i", no_auto => 1 )->mock( new => 1 ) |
344 |
unless $mocks->[$i]; |
345 |
} |
346 |
|
347 |
# We will (re)create new plugins (without modules) |
348 |
# This requires mocking can_load from Module::Load::Conditional |
349 |
my $mlc_mock = Test::MockModule->new('Koha::Plugins')->mock( can_load => 1 ); |
350 |
my $plugin_mocks = []; |
351 |
my @enabled_plugins; |
352 |
|
353 |
subtest 'Destructive flag' => sub { |
354 |
reload_plugin( $_, $plugin_mocks ) for 1 .. 3; |
355 |
Koha::Plugins->RemovePlugins( { destructive => 1 } ); |
356 |
is( Koha::Plugins::Datas->count, 0, 'No data in plugin_data' ); |
357 |
is( Koha::Plugins::Methods->count, 0, 'No data in plugin_methods' ); |
358 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; # testing if cache cleared |
359 |
is( scalar @enabled_plugins, 0, 'No enabled plugins' ); |
360 |
|
361 |
reload_plugin( $_, $plugin_mocks ) for 1 .. 3; |
362 |
Koha::Plugins->RemovePlugins( { plugin_class => "${class_basename}2", destructive => 1 } ); |
363 |
is( Koha::Plugins::Datas->count, 2, '2 in plugin_data' ); |
364 |
is( Koha::Plugins::Methods->count, 2, '2 in plugin_methods' ); |
365 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
366 |
is( scalar @enabled_plugins, 2, '2 enabled plugins' ); |
367 |
Koha::Plugins->RemovePlugins( { destructive => 1 } ); |
368 |
}; |
369 |
|
370 |
subtest 'Disable flag' => sub { |
371 |
reload_plugin( $_, $plugin_mocks ) for 1 .. 4; |
372 |
Koha::Plugins->RemovePlugins( { disable => 1 } ); |
373 |
is( Koha::Plugins::Datas->count, 4, '4 in plugin_data' ); |
374 |
is( Koha::Plugins::Methods->count, 0, 'No data in plugin_methods' ); |
375 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
376 |
is( scalar @enabled_plugins, 0, '0 enabled plugins' ); |
377 |
|
378 |
reload_plugin( $_, $plugin_mocks ) for 5 .. 6; |
379 |
Koha::Plugins->RemovePlugins( { plugin_class => "${class_basename}5", disable => 1 } ); |
380 |
is( Koha::Plugins::Datas->count, 6, '6 in plugin_data' ); |
381 |
is( Koha::Plugins::Methods->count, 1, '1 in plugin_methods' ); |
382 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
383 |
is( scalar @enabled_plugins, 1, '1 enabled plugins' ); |
384 |
Koha::Plugins->RemovePlugins( { destructive => 1 } ); |
385 |
}; |
386 |
|
387 |
subtest 'No flags' => sub { |
388 |
reload_plugin( $_, $plugin_mocks ) for 1 .. 2; |
389 |
Koha::Plugins->RemovePlugins; |
390 |
is( Koha::Plugins::Datas->count, 2, '2 in plugin_data' ); |
391 |
is( Koha::Plugins::Methods->count, 0, 'No data in plugin_methods' ); |
392 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
393 |
is( scalar @enabled_plugins, 2, '2 enabled plugins' ); |
394 |
|
395 |
reload_plugin( $_, $plugin_mocks ) for 3 .. 4; |
396 |
Koha::Plugins->RemovePlugins( { plugin_class => "${class_basename}4" } ); |
397 |
is( Koha::Plugins::Datas->count, 4, '4 in plugin_data' ); |
398 |
is( Koha::Plugins::Methods->count, 1, '1 in plugin_methods' ); |
399 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
400 |
is( scalar @enabled_plugins, 2, '2 enabled plugins (from cache)' ); |
401 |
|
402 |
# clear cache and try again, expect 4 since RemovePlugins did not touch plugin_data here |
403 |
Koha::Cache::Memory::Lite->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); |
404 |
@enabled_plugins = Koha::Plugins->get_enabled_plugins; |
405 |
is( scalar @enabled_plugins, 4, '4 enabled plugins' ); |
406 |
Koha::Plugins->RemovePlugins( { destructive => 1 } ); |
407 |
}; |
408 |
|
409 |
$schema->storage->txn_rollback; |
410 |
}; |
411 |
|
412 |
|
413 |
$schema->storage->txn_begin; # Matching rollback at very end |
327 |
|
414 |
|
328 |
subtest 'output and output_html tests' => sub { |
415 |
subtest 'output and output_html tests' => sub { |
329 |
|
416 |
|
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' ); |
499 |
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' ); |
413 |
}; |
500 |
}; |
414 |
|
501 |
|
415 |
Koha::Plugins::Methods->delete; |
|
|
416 |
$schema->storage->txn_rollback; |
502 |
$schema->storage->txn_rollback; |
417 |
- |
503 |
#!/usr/bin/perl |