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

(-)a/t/db_dependent/Koha/Plugins/KitchenSink.t (-1 / +83 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
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
17
use Modern::Perl;
18
use Archive::Extract;
19
use File::Temp qw/tempdir/;
20
use FindBin    qw($Bin);
21
use Test::MockModule;
22
use Test::More tests => 1;
23
use Test::Warn;
24
25
use t::lib::Mocks;
26
27
use C4::Context;
28
use Koha::Database;
29
use Koha::Plugins;
30
use Koha::Plugins::Datas;
31
use Koha::Plugins::Handler;
32
use Koha::Plugins::Methods;
33
34
my $schema = Koha::Database->new->schema;
35
36
subtest 'Fun with KitchenSink, Handler->delete' => sub {
37
    plan tests => 7;
38
39
    create_mytable();    # IMPORTANT: before transaction start (prevent implicit commit)
40
    $schema->storage->txn_begin;
41
    t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
42
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
43
44
    my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink';
45
    my $pm_path     = 'Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm';
46
    Koha::Plugins->RemovePlugins( { plugin_class => $module_name, destructive => 1 } );    # just to be safe
47
    Koha::Plugins->new->InstallPlugins;                                                    # install without KitchenSink
48
    my ( $count_d, $count_m ) = ( Koha::Plugins::Datas->count, Koha::Plugins::Methods->count );
49
50
    # Install KitchenSink, mock install and uninstall
51
    my $plugins_dir = tempdir( CLEANUP => 1 );
52
    t::lib::Mocks::mock_config( 'pluginsdir', $plugins_dir );
53
    push @INC, $plugins_dir;
54
    my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' );
55
    $ae->extract( to => $plugins_dir ) or warn "ERROR: " . $ae->error;
56
    my $mock = Test::MockModule->new($module_name)->mock( install => 1 )->mock( uninstall => 1 );
57
    warning_is { Koha::Plugins->new->InstallPlugins; } undef, 'No warnings from InstallPlugins';
58
    ok( Koha::Plugins::Datas->count > $count_d,   'More records in plugin_data' );
59
    ok( Koha::Plugins::Methods->count > $count_m, 'More records in plugin_methods' );
60
    ok( -f "$plugins_dir/$pm_path",               "KitchenSink module found" );
61
62
    # Delete via Handler->delete, uninstall has been mocked to prevent implicit commit (DROP TABLE)
63
    Koha::Plugins::Handler->delete( { class => $module_name } );
64
65
    # Final checks
66
    ok( !-f "$plugins_dir/$pm_path", "Module file no longer found" );
67
    is( Koha::Plugins::Datas->count,   $count_d, 'Original count in plugin_data' );
68
    is( Koha::Plugins::Methods->count, $count_m, 'Original count in plugin_methods' );
69
70
    $schema->storage->txn_rollback;
71
    drop_mytable();    # Created before txn, remove after rollback
72
};
73
74
sub create_mytable {
75
76
    # This create mimics what KitchenSink would do.
77
    # The columns are not relevant here.
78
    C4::Context->dbh->do("CREATE TABLE IF NOT EXISTS mytable ( test int )");
79
}
80
81
sub drop_mytable {
82
    C4::Context->dbh->do("DROP TABLE mytable");
83
}

Return to bug 35548