From 7be48ae9a4b0cdb1a2c562afd635bffcf40ecad4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 14 Dec 2023 07:54:22 +0000 Subject: [PATCH] Bug 35536: Reorder rollbacks Time to move all RemovePlugins calls BEFORE rollbacks. Broken.t did not even include a transaction! Some modules are removed there as well. Test plan: Search for wrong order with: grep -Pzo "txn_rollback;\n.*RemovePlugins" $(git grep -l RemovePlugins) No occurrences left? Think of another grep :) Check number of records in plugin_data/methods. Repeat: prove $(git grep -l Koha::Plugin | grep -P "^t\/db") And check number of records again. Same? Bonus: Apply TestMR plugin patch (marked DO NOT PUSH). Run perl -MKoha::Plugins -e"Koha::Plugins->new->InstallPlugins". Check plugin records in database. Keep those records but remove last patch from git. Run previous prove and verify no data changes since last check. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- t/db_dependent/Koha/Plugins/BackgroundJob.t | 2 +- .../Koha/Plugins/Barcode_transform_hooks.t | 2 +- .../Plugins/Biblio_and_Items_plugin_hooks.t | 2 +- t/db_dependent/Koha/Plugins/Broken.t | 26 +++++++++---------- .../Koha/Plugins/Circulation_hooks.t | 2 +- t/db_dependent/Koha/Plugins/Patron.t | 4 +-- t/db_dependent/Koha/Plugins/authority_hooks.t | 2 +- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/t/db_dependent/Koha/Plugins/BackgroundJob.t b/t/db_dependent/Koha/Plugins/BackgroundJob.t index a4c8e58e299..c5ccd3763f7 100755 --- a/t/db_dependent/Koha/Plugins/BackgroundJob.t +++ b/t/db_dependent/Koha/Plugins/BackgroundJob.t @@ -84,6 +84,6 @@ subtest 'background_tasks() hooks tests' => sub { is_deeply( $tasks, $bj->core_types_to_classes, 'Only core mapping returned when plugins disabled' ); - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t index 202f1bfdd9a..234f7d572f3 100755 --- a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t +++ b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t @@ -99,6 +99,6 @@ subtest 'patron_barcode_transform() and item_barcode_transform() hook tests' => qr/Plugin error \(Test Plugin\): Exception 'Koha::Exception' thrown 'item_barcode_transform called with parameter: THISISATEST'/, 'Koha::Item->store calls the item_barcode_transform hook'; - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t b/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t index 1ca1d5116e2..7f818dfd487 100755 --- a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t +++ b/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t @@ -83,6 +83,6 @@ subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { qr/after_biblio_action called with action: delete, id: $biblio_id/, 'DelBiblio calls the hook with action=delete biblio_id passed'; - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Plugins/Broken.t b/t/db_dependent/Koha/Plugins/Broken.t index d6e58fda1e5..6db153db7ed 100755 --- a/t/db_dependent/Koha/Plugins/Broken.t +++ b/t/db_dependent/Koha/Plugins/Broken.t @@ -15,15 +15,13 @@ # with Koha; if not, see . use Modern::Perl; - -use Test::More tests => 3; -use Test::MockModule; -use Test::Warn; - use File::Basename; +use Test::More tests => 2; +use Test::Warn; use t::lib::Mocks; -use t::lib::TestBuilder; + +use Koha::Database; BEGIN { # Mock pluginsdir before loading Plugins module @@ -31,17 +29,19 @@ BEGIN { t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); - use_ok('Koha::Plugins::Handler'); } -my $schema = Koha::Database->new->schema; -my $builder = t::lib::TestBuilder->new; +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; t::lib::Mocks::mock_config( 'enable_plugins', 1 ); my $plugins = Koha::Plugins->new; -warnings_are - { $plugins->InstallPlugins; } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", - "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; +warnings_are { $plugins->InstallPlugins; } +[ + "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", + "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" +]; + +$schema->storage->txn_begin; diff --git a/t/db_dependent/Koha/Plugins/Circulation_hooks.t b/t/db_dependent/Koha/Plugins/Circulation_hooks.t index 02911a01c51..47ac5d58afa 100755 --- a/t/db_dependent/Koha/Plugins/Circulation_hooks.t +++ b/t/db_dependent/Koha/Plugins/Circulation_hooks.t @@ -120,6 +120,6 @@ subtest 'after_circ_action() hook tests' => sub { 'AddReturn calls the after_circ_action hook'; }; - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Plugins/Patron.t b/t/db_dependent/Koha/Plugins/Patron.t index 363a2fa0e31..eb001c88815 100755 --- a/t/db_dependent/Koha/Plugins/Patron.t +++ b/t/db_dependent/Koha/Plugins/Patron.t @@ -87,8 +87,6 @@ subtest 'check_password hook tests' => sub { ok( $patron->set_password({ password => '4321' }), 'Patron password updated with good string' ); ok( $patron->set_password({ password => 'explosion', skip_validation => 1}), 'Patron password updated via skip validation'); - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; - -1; diff --git a/t/db_dependent/Koha/Plugins/authority_hooks.t b/t/db_dependent/Koha/Plugins/authority_hooks.t index 464fb16262c..959795d2f89 100755 --- a/t/db_dependent/Koha/Plugins/authority_hooks.t +++ b/t/db_dependent/Koha/Plugins/authority_hooks.t @@ -65,6 +65,6 @@ subtest 'after_authority_action hook' => sub { qr/after_authority_action called with action: delete, id: $id/, 'DelAuthority calls the hook with action=delete, id passed'; - $schema->storage->txn_rollback; Koha::Plugins->RemovePlugins; + $schema->storage->txn_rollback; }; -- 2.30.2