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

(-)a/t/db_dependent/Plugins.t (-2 / +64 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
3
use Modern::Perl;
17
use Modern::Perl;
4
18
5
use Archive::Extract;
19
use Archive::Extract;
Lines 18-24 use Koha::Plugins::Methods; Link Here
18
use t::lib::Mocks;
32
use t::lib::Mocks;
19
33
20
BEGIN {
34
BEGIN {
21
    push( @INC, dirname(__FILE__) . '/../lib' );
35
    # Mock pluginsdir before loading Plugins module
36
    my $path = dirname(__FILE__) . '/../lib';
37
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
22
38
23
    use_ok('Koha::Plugins');
39
    use_ok('Koha::Plugins');
24
    use_ok('Koha::Plugins::Handler');
40
    use_ok('Koha::Plugins::Handler');
Lines 28-33 BEGIN { Link Here
28
44
29
my $schema = Koha::Database->new->schema;
45
my $schema = Koha::Database->new->schema;
30
46
47
subtest 'GetPlugins() tests' => sub {
48
49
    plan tests => 2;
50
51
    $schema->storage->txn_begin;
52
    # Temporarily remove any installed plugins data
53
    Koha::Plugins::Methods->delete;
54
55
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
56
    $plugins->InstallPlugins;
57
58
    my @plugins = $plugins->GetPlugins({ method => 'report' });
59
60
    my @names = map { $_->get_metadata()->{'name'} } @plugins;
61
    is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
62
63
    @plugins = $plugins->GetPlugins({ metadata => { my_example_tag  => 'find_me' } });
64
    @names = map { $_->get_metadata()->{'name'} } @plugins;
65
    is( scalar @names, 2, "Only two plugins found via a metadata tag" );
66
67
    $schema->storage->txn_rollback;
68
};
69
70
subtest 'Version upgrade tests' => sub {
71
72
    plan tests => 1;
73
74
    $schema->storage->txn_begin;
75
76
    my $plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
77
78
    # make sure there's no version on the DB
79
    $schema->resultset('PluginData')
80
        ->search( { plugin_class => $plugin->{class}, plugin_key => '__INSTALLED_VERSION__' } )
81
        ->delete;
82
83
    $plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
84
    my $version = $plugin->retrieve_data('__INSTALLED_VERSION__');
85
86
    is( $version, $plugin->get_metadata->{version}, 'Version has been populated correctly' );
87
88
    $schema->storage->txn_rollback;
89
};
90
91
$schema->storage->txn_begin;
92
Koha::Plugins::Methods->delete;
93
31
Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins();
94
Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins();
32
95
33
ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
96
ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
34
- 

Return to bug 21073