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

(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-42 / +4 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Archive::Extract;
20
use CGI;
19
use CGI;
21
use Cwd qw(abs_path);
20
use Cwd qw(abs_path);
22
use File::Basename;
21
use File::Basename;
Lines 25-31 use File::Temp qw( tempdir tempfile ); Link Here
25
use FindBin qw($Bin);
24
use FindBin qw($Bin);
26
use Module::Load::Conditional qw(can_load);
25
use Module::Load::Conditional qw(can_load);
27
use Test::MockModule;
26
use Test::MockModule;
28
use Test::More tests => 62;
27
use Test::More tests => 50;
29
use Test::Warn;
28
use Test::Warn;
30
29
31
use C4::Context;
30
use C4::Context;
Lines 48-53 BEGIN { Link Here
48
47
49
my $schema = Koha::Database->new->schema;
48
my $schema = Koha::Database->new->schema;
50
49
50
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
51
51
subtest 'call() tests' => sub {
52
subtest 'call() tests' => sub {
52
53
53
    plan tests => 4;
54
    plan tests => 4;
Lines 318-362 is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disable Link Here
318
@names = map { $_->get_metadata()->{'name'} } @plugins;
319
@names = map { $_->get_metadata()->{'name'} } @plugins;
319
is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" );
320
is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" );
320
321
321
for my $pass ( 1 .. 2 ) {
322
    my $plugins_dir;
323
    my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink';
324
    my $pm_path = 'Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm';
325
    if ( $pass == 1 ) {
326
        my $plugins_dir1 = tempdir( CLEANUP => 1 );
327
        t::lib::Mocks::mock_config('pluginsdir', $plugins_dir1);
328
        $plugins_dir = $plugins_dir1;
329
        push @INC, $plugins_dir1;
330
    } else {
331
        my $plugins_dir1 = tempdir( CLEANUP => 1 );
332
        my $plugins_dir2 = tempdir( CLEANUP => 1 );
333
        t::lib::Mocks::mock_config('pluginsdir', [ $plugins_dir2, $plugins_dir1 ]);
334
        $plugins_dir = $plugins_dir2;
335
        pop @INC;
336
        push @INC, $plugins_dir2;
337
        push @INC, $plugins_dir1;
338
    }
339
    my $full_pm_path = $plugins_dir . '/' . $pm_path;
340
341
    my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' );
342
    unless ( $ae->extract( to => $plugins_dir ) ) {
343
        warn "ERROR: " . $ae->error;
344
    }
345
    use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink');
346
    $plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1});
347
    my $table = $plugin->get_qualified_table_name( 'mytable' );
348
349
    ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
350
    $INC{$pm_path} = $full_pm_path; # FIXME I do not really know why, but if this is moved before the $plugin constructor, it will fail with Can't locate object method "new" via package "Koha::Plugin::Com::ByWaterSolutions::KitchenSink"
351
    warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef;
352
    ok( -f $full_pm_path, "Koha::Plugins::Handler::delete works correctly (pass $pass)" );
353
    Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins => 1 });
354
    my $sth = C4::Context->dbh->table_info( undef, undef, $table, 'TABLE' );
355
    my $info = $sth->fetchall_arrayref;
356
    is( @$info, 0, "Table $table does no longer exist" );
357
    ok( !( -f $full_pm_path ), "Koha::Plugins::Handler::delete works correctly (pass $pass)" );
358
}
359
360
subtest 'output and output_html tests' => sub {
322
subtest 'output and output_html tests' => sub {
361
323
362
    plan tests => 6;
324
    plan tests => 6;
Lines 445-447 subtest 'new() tests' => sub { Link Here
445
};
407
};
446
408
447
Koha::Plugins::Methods->delete;
409
Koha::Plugins::Methods->delete;
448
- 
410
$schema->storage->txn_rollback;

Return to bug 35507