From 313f50854490beefdacc7034297d303ea4356dd2 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 12 Dec 2023 14:07:49 +0000 Subject: [PATCH] Bug 35507: Plugins.t - Mock SessionStorage, remove KitchenSink Removing the CGI::Session behavior to auto-commit by mocking SessionStorage makes that the $plugin->test_template does no longer commit. Since KitchenSink includes a CREATE TABLE, removing that code removes the second implicit commit. We might move that code to its own script? Adds a missing rollback too at the end. Test plan: Run prove t/db_dependent/Koha/Plugins/Plugins.t Verify that no records got added to plugin_data/methods table. Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer (cherry picked from commit dc62d9bed5799b9583bbc1ed59ea37972d7fe472) Signed-off-by: Fridolin Somers (cherry picked from commit bfb2a929e30e30e7bf490364fc216ca69c966e62) Signed-off-by: Lucas Gass --- t/db_dependent/Koha/Plugins/Plugins.t | 45 +++------------------------ 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t index db68b9d195..5fc4cb3378 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -16,7 +16,6 @@ use Modern::Perl; -use Archive::Extract; use CGI; use Cwd qw(abs_path); use File::Basename; @@ -25,7 +24,7 @@ use File::Temp qw( tempdir tempfile ); use FindBin qw($Bin); use Module::Load::Conditional qw(can_load); use Test::MockModule; -use Test::More tests => 61; +use Test::More tests => 49; use Test::Warn; use C4::Context; @@ -48,6 +47,8 @@ BEGIN { my $schema = Koha::Database->new->schema; +t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); + subtest 'call() tests' => sub { plan tests => 4; @@ -286,45 +287,6 @@ is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disable @names = map { $_->get_metadata()->{'name'} } @plugins; is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); -for my $pass ( 1 .. 2 ) { - my $plugins_dir; - my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink'; - my $pm_path = 'Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm'; - if ( $pass == 1 ) { - my $plugins_dir1 = tempdir( CLEANUP => 1 ); - t::lib::Mocks::mock_config('pluginsdir', $plugins_dir1); - $plugins_dir = $plugins_dir1; - push @INC, $plugins_dir1; - } else { - my $plugins_dir1 = tempdir( CLEANUP => 1 ); - my $plugins_dir2 = tempdir( CLEANUP => 1 ); - t::lib::Mocks::mock_config('pluginsdir', [ $plugins_dir2, $plugins_dir1 ]); - $plugins_dir = $plugins_dir2; - pop @INC; - push @INC, $plugins_dir2; - push @INC, $plugins_dir1; - } - my $full_pm_path = $plugins_dir . '/' . $pm_path; - - my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' ); - unless ( $ae->extract( to => $plugins_dir ) ) { - warn "ERROR: " . $ae->error; - } - use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink'); - $plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1}); - my $table = $plugin->get_qualified_table_name( 'mytable' ); - - ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" ); - $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" - warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; - ok( -f $full_pm_path, "Koha::Plugins::Handler::delete works correctly (pass $pass)" ); - Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins => 1 }); - my $sth = C4::Context->dbh->table_info( undef, undef, $table, 'TABLE' ); - my $info = $sth->fetchall_arrayref; - is( @$info, 0, "Table $table does no longer exist" ); - ok( !( -f $full_pm_path ), "Koha::Plugins::Handler::delete works correctly (pass $pass)" ); -} - subtest 'output and output_html tests' => sub { plan tests => 6; @@ -413,3 +375,4 @@ subtest 'new() tests' => sub { }; Koha::Plugins::Methods->delete; +$schema->storage->txn_rollback; -- 2.39.5