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

(-)a/t/db_dependent/Koha/Plugins/Loader.t (-5 / +35 lines)
Lines 17-23 Link Here
17
use Modern::Perl;
17
use Modern::Perl;
18
use File::Basename;
18
use File::Basename;
19
use Test::MockModule;
19
use Test::MockModule;
20
use Test::More tests => 6;
20
use Test::More tests => 9;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 35-46 BEGIN { Link Here
35
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
35
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
36
36
37
    use_ok('Koha::Plugins::Loader');
37
    use_ok('Koha::Plugins::Loader');
38
    use_ok('Koha::Plugins');
39
    use_ok('Koha::Plugins::Handler');
40
    use_ok('Koha::Plugin::Test');
38
}
41
}
39
42
40
my $schema = Koha::Database->new->schema;
43
my $schema = Koha::Database->new->schema;
41
44
42
subtest 'get_enabled_plugins - basic functionality' => sub {
45
subtest 'get_enabled_plugins - basic functionality' => sub {
43
    plan tests => 4;
46
    plan tests => 8;
44
47
45
    $schema->storage->txn_begin;
48
    $schema->storage->txn_begin;
46
49
Lines 50-62 subtest 'get_enabled_plugins - basic functionality' => sub { Link Here
50
    # Remove any existing plugins
53
    # Remove any existing plugins
51
    Koha::Plugins::Datas->delete;
54
    Koha::Plugins::Datas->delete;
52
55
56
    my $cache_key = 'enabled_plugins';
57
53
    # Test with no enabled plugins
58
    # Test with no enabled plugins
54
    my @plugins = Koha::Plugins::Loader->get_enabled_plugins();
59
    my @plugins = Koha::Plugins::Loader->get_enabled_plugins();
55
    is( scalar @plugins, 0, 'Returns empty list when no plugins are enabled' );
60
    is( scalar @plugins, 0, 'Returns empty list when no plugins are enabled' );
56
61
57
    # Test caching behavior
62
    # Test caching behavior
58
    my @plugins_cached = Koha::Plugins::Loader->get_enabled_plugins();
63
    my $cached = Koha::Cache::Memory::Lite->get_from_cache($cache_key);
59
    is( scalar @plugins_cached, 0, 'Cached empty result works correctly' );
64
    is( $cached, undef, "Nothing cached when no plugins" );
65
66
    my $mock_plugins = Test::MockModule->new("Koha::Plugins");
67
    $mock_plugins->mock( 'can_load', sub { return 0; } );
68
69
    # Test with invalid plugin class that can't be loaded by adding directly to DB
70
    Koha::Plugins::Data->new(
71
        {
72
            plugin_class => 'Koha::Plugin::Test',
73
            plugin_key   => '__ENABLED__',
74
            plugin_value => 1,
75
        }
76
    )->store;
77
    my $mock_test_plugin = Test::MockModule->new("Koha::Plugin::Test");
78
    $mock_test_plugin->mock( 'new', sub { return "Test"; } );
79
80
    @plugins = Koha::Plugins::Loader->get_enabled_plugins();
81
    is( scalar @plugins, 0, 'Returns empty list when no plugins are loaded' );
82
    $cached = Koha::Cache::Memory::Lite->get_from_cache($cache_key);
83
    is( $cached, undef, "Nothing cached when no plugins can be loaded" );
84
85
    $mock_plugins->mock( "can_load", sub { return 1; } );
86
87
    @plugins = Koha::Plugins::Loader->get_enabled_plugins();
88
    is( scalar @plugins, 1, 'Returns the plugin when loaded' );
89
    $cached = Koha::Cache::Memory::Lite->get_from_cache($cache_key);
90
    is( @{$cached}[0], $plugins[0], "Plugin successfully loaded and cached" );
60
91
61
    # The core functionality of loading plugins is tested indirectly through
92
    # The core functionality of loading plugins is tested indirectly through
62
    # the Koha::Plugins tests which use the Loader
93
    # the Koha::Plugins tests which use the Loader
63
- 

Return to bug 38384