From 6e6d60ccab9628935a52849fd799dc191066e47a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 16 Dec 2024 15:04:23 +0000 Subject: [PATCH] Bug 33260: (follow-up) More comprehensively test patron accessor --- t/db_dependent/Koha/Notice/Message.t | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t index 938d7e58a6b..8f34f802bce 100755 --- a/t/db_dependent/Koha/Notice/Message.t +++ b/t/db_dependent/Koha/Notice/Message.t @@ -221,10 +221,11 @@ WRAPPED subtest 'patron() tests' => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; + # Valid patron and message my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $message = $builder->build_object( { @@ -232,10 +233,26 @@ subtest 'patron() tests' => sub { value => { borrowernumber => $patron->borrowernumber } } ); + my $message_id = $message->message_id; is( ref( $message->patron ), 'Koha::Patron', 'Object type is correct' ); is( $message->patron->borrowernumber, $patron->borrowernumber, 'Right patron linked' ); + # Deleted patron + $patron->delete; + $message = Koha::Notice::Messages->find($message_id); + is( $message, undef, 'Deleting the patron also deletes the associated message' ); + + # Missing patron + $message = $builder->build_object( + { + class => 'Koha::Notice::Messages', + value => { borrowernumber => undef } + } + ); + + is( $message->patron, undef, 'Returns undef if borrowernumber is missing' ); + $schema->storage->txn_rollback; }; -- 2.47.1