From e5a0e1764ed0f36ec41aef9f2068db4ce90dde4a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 16 Dec 2024 15:08:55 +0000 Subject: [PATCH] Bug 33260: (follow-up) More comprehensively test template accessor --- t/db_dependent/Koha/Notice/Message.t | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t index 201e8fd3197..11c86e2143c 100755 --- a/t/db_dependent/Koha/Notice/Message.t +++ b/t/db_dependent/Koha/Notice/Message.t @@ -404,10 +404,11 @@ subtest 'patron() tests' => sub { }; subtest 'template() tests' => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; + # Valid template and message my $template = $builder->build_object( { class => 'Koha::Notice::Templates' } ); my $message = $builder->build_object( { @@ -419,6 +420,21 @@ subtest 'template() tests' => sub { is( ref( $message->template ), 'Koha::Notice::Template', 'Object type is correct' ); is( $message->template->id, $template->id, 'Right template linked' ); + # Deleted template + $template->delete; + $message->discard_changes; + is( $message->template, undef, 'Returns undef if template was deleted' ); + + # Missing template + $message = $builder->build_object( + { + class => 'Koha::Notice::Messages', + value => { letter_id => undef } + } + ); + + is( $message->template, undef, 'Returns undef if no template used for message' ); + $schema->storage->txn_rollback; }; -- 2.53.0