From d55b2ffa843fb3c70e5271893e629c5e0cc35f2e 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 8f34f802bce..d727b7fafa6 100755 --- a/t/db_dependent/Koha/Notice/Message.t +++ b/t/db_dependent/Koha/Notice/Message.t @@ -257,10 +257,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( { @@ -272,6 +273,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.47.1