From 0667b3c814db9e3743277d8b5644e0fd09b071c1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 5 Mar 2026 15:45:55 +0100 Subject: [PATCH] Bug 41991: Unit tests Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Koha/Plugins/Plugins.t Signed-off-by: Marcel de Rooy Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha/Plugins/Plugins.t | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t index 9988bfff14..3339d450c5 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -26,7 +26,7 @@ use List::MoreUtils qw(none); use Module::Load::Conditional qw(can_load); use Test::MockModule; use Test::NoWarnings; -use Test::More tests => 20; +use Test::More tests => 21; use Test::Warn; use Test::Exception; @@ -137,6 +137,39 @@ subtest 'more call() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'call with SUSPEND_PLUGIN' => sub { + plan tests => 4; + $schema->storage->txn_begin; + + # Mocks; make sure that TestItemBarcodeTransform can install/report + t::lib::Mocks::mock_config( 'enable_plugins', 1 ); + Koha::Cache::Memory::Lite->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); + my $mock_plugin = Test::MockModule->new('Koha::Plugin::TestItemBarcodeTransform'); + $mock_plugin->mock( 'install', sub { return 1; } ); + $mock_plugin->mock( 'report', sub { return 'What a report' } ); + + my $plugin1 = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } ); + my $plugin2 = Koha::Plugin::TestItemBarcodeTransform->new( { enable_plugins => 1, cgi => CGI->new } ); + + my $count1 = Koha::Plugins->call('report') // 0; + ok( $count1 >= 2, 'We expect at least two report responses' ); + + # Suspend the report method + $ENV{'SUSPEND_PLUGIN_report'} = 1; + my $count2 = Koha::Plugins->call('report') // 0; + is( $count2, 0, 'No responses expected when suspending method' ); + delete $ENV{'SUSPEND_PLUGIN_report'}; + + # Suspend a class + $ENV{'SUSPEND_PLUGIN_Koha_Plugin_Test'} = 1; + $count2 = Koha::Plugins->call('report') // 0; + is( $count2, $count1 - 1, 'One response less expected when suspending class' ); + is( scalar grep( /What a report/, Koha::Plugins->call('report') ), 1, 'Output of TestItemBarcodeTransform found' ); + delete $ENV{'SUSPEND_PLUGIN_Koha_Plugin_Test'}; + + $schema->storage->txn_rollback; +}; + subtest 'feature_enabled tests' => sub { plan tests => 4; -- 2.39.5