From c9a481006fd5ba65a7e84ec0d5ac54340a260232 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Thu, 21 Nov 2024 10:01:56 +0000 Subject: [PATCH] Bug 38501: Prevent failures of Koha/Booking.t when run on MySQL8 --- t/db_dependent/Koha/Booking.t | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/t/db_dependent/Koha/Booking.t b/t/db_dependent/Koha/Booking.t index 19aa536b12..3e17810870 100755 --- a/t/db_dependent/Koha/Booking.t +++ b/t/db_dependent/Koha/Booking.t @@ -25,6 +25,8 @@ use Test::More tests => 2; use Test::Exception; use Koha::DateUtils qw( dt_from_string ); +use Koha::Notice::Template; +use Koha::Notice::Templates; use t::lib::TestBuilder; use t::lib::Mocks; @@ -369,6 +371,39 @@ subtest 'store() tests' => sub { subtest 'confirmation notice trigger' => sub { plan tests => 2; + # FIXME: This is a bandaid solution to prevent test failures on MySQL8 where notices are + # not added at upgrade time. + my $template = Koha::Notice::Templates->search( + { + module => 'bookings', + code => 'BOOKING_CONFIRMATION', + message_transport_type => 'email', + } + )->single; + + if ( !$template ) { + my $default_content = Koha::Notice::Template->new( + { + module => 'bookings', + code => 'BOOKING_CONFIRMATION', + lang => 'default', + message_transport_type => 'email', + } + )->get_default(); + + Koha::Notice::Template->new( + { + module => 'bookings', + code => 'BOOKING_CONFIRMATION', + name => 'BOOKING_CONFIRMATION Test Notice', + title => 'BOOKING_CONFIRMATION Test Notice', + content => $default_content || 'Dummy content for BOOKING_CONFIRMATION.', + branchcode => undef, + message_transport_type => 'email', + } + )->store; + } + my $original_notices_count = Koha::Notice::Messages->search( { letter_code => 'BOOKING_CONFIRMATION', @@ -420,6 +455,41 @@ subtest 'store() tests' => sub { subtest 'modification/cancellation notice triggers' => sub { plan tests => 5; + # FIXME: This is a bandaid solution to prevent test failures on MySQL8 where notices are + # not added at upgrade time. + for my $notice_type (qw(BOOKING_MODIFICATION BOOKING_CANCELLATION)) { + my $template = Koha::Notice::Templates->search( + { + module => 'bookings', + code => $notice_type, + message_transport_type => 'email', + } + )->single; + + unless ($template) { + my $default_content = Koha::Notice::Template->new( + { + module => 'bookings', + code => $notice_type, + lang => 'default', + message_transport_type => 'email', + } + )->get_default(); + + Koha::Notice::Template->new( + { + module => 'bookings', + code => $notice_type, + name => "$notice_type Test Notice", + title => "$notice_type Test Notice", + content => $default_content || "Dummy content for $notice_type.", + branchcode => undef, + message_transport_type => 'email', + } + )->store; + } + } + my $original_modification_notices_count = Koha::Notice::Messages->search( { letter_code => 'BOOKING_MODIFICATION', -- 2.39.5