Bug 36542: Update unit test

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2026-02-17 09:59:13 -05:00 committed by Lucas Gass
parent c3ce3b17c7
commit 3487b56e20
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 13 additions and 3 deletions

View File

@ -62,11 +62,11 @@ subtest 'after_biblio_action() and after_item_action() hooks tests' => sub {
my $biblio_id;
warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
qr/after_biblio_action called with action: create, ref: Koha::Biblio/,
qr/after_biblio_action called with action: create, ref: Koha::Biblio, biblio found/,
'AddBiblio calls the hook with action=create';
warning_like { C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id, '' ); }
qr/after_biblio_action called with action: modify, ref: Koha::Biblio/,
qr/after_biblio_action called with action: modify, ref: Koha::Biblio, biblio found/,
'ModBiblio calls the hook with action=modify';
my $item;

View File

@ -6,6 +6,8 @@ use Modern::Perl;
use Koha::Exception;
use Koha::Plugins::Tab;
use Koha::Biblios;
use MARC::Field;
use Mojo::JSON qw( decode_json );
@ -192,7 +194,15 @@ sub after_biblio_action {
my $biblio_id = $payload->{biblio_id};
if ( $action ne 'delete' ) {
Koha::Exception->throw( "after_biblio_action called with action: $action, ref: " . ref($biblio) );
$biblio = Koha::Biblios->find($biblio_id);
if ($biblio) {
$biblio_id = $biblio->id;
Koha::Exception->throw(
"after_biblio_action called with action: $action, ref: " . ref($biblio) . ", biblio found" );
} else {
Koha::Exception->throw(
"after_biblio_action called with action: $action, ref: " . ref($biblio) . ", biblio not found" );
}
} else {
Koha::Exception->throw("after_biblio_action called with action: $action, id: $biblio_id") if $biblio_id;
}