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

(-)a/t/db_dependent/Plugins.t (-37 / +65 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 9-15 use File::Temp qw( tempdir tempfile ); Link Here
9
use FindBin qw($Bin);
23
use FindBin qw($Bin);
10
use Module::Load::Conditional qw(can_load);
24
use Module::Load::Conditional qw(can_load);
11
use Test::MockModule;
25
use Test::MockModule;
12
use Test::More tests => 42;
26
use Test::More tests => 41;
13
27
14
use C4::Context;
28
use C4::Context;
15
use Koha::Database;
29
use Koha::Database;
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' );
Lines 82-99 close $fh; Link Here
82
my $classname = ref($plugin);
145
my $classname = ref($plugin);
83
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
146
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
84
147
85
# testing GetPlugins
86
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
87
    method => 'report'
88
});
89
my @names = map { $_->get_metadata()->{'name'} } @plugins;
90
is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
91
@plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
92
    metadata => { my_example_tag  => 'find_me' },
93
});
94
@names = map { $_->get_metadata()->{'name'} } @plugins;
95
is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" );
96
97
for my $pass ( 1 .. 2 ) {
148
for my $pass ( 1 .. 2 ) {
98
    my $plugins_dir;
149
    my $plugins_dir;
99
    my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink';
150
    my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink';
Lines 160-187 subtest 'output and output_html tests' => sub { Link Here
160
    like($stdout, qr{¡Hola output_html!}, 'Correct data');
211
    like($stdout, qr{¡Hola output_html!}, 'Correct data');
161
};
212
};
162
213
163
subtest 'Version upgrade tests' => sub {
164
165
    plan tests => 1;
166
167
    $schema->storage->txn_begin;
168
169
    my $plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
170
171
    # make sure there's no version on the DB
172
    $schema->resultset('PluginData')
173
        ->search( { plugin_class => $plugin->{class}, plugin_key => '__INSTALLED_VERSION__' } )
174
        ->delete;
175
176
    $plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
177
    my $version = $plugin->retrieve_data('__INSTALLED_VERSION__');
178
179
    is( $version, $plugin->get_metadata->{version}, 'Version has been populated correctly' );
180
181
    $schema->storage->txn_rollback;
182
};
183
184
185
subtest 'Test _version_compare' => sub {
214
subtest 'Test _version_compare' => sub {
186
215
187
    plan tests => 6;
216
    plan tests => 6;
188
- 

Return to bug 21073