From 6a13253ba5a18f5b018a6a849c83929640185bbc Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 26 Oct 2023 21:06:35 +0000 Subject: [PATCH] Bug 17617: Unit tests --- t/db_dependent/Holds.t | 82 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 39224e99050..4c78b4c480b 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 73; +use Test::More tests => 74; use Test::Exception; use MARC::Record; @@ -15,7 +15,7 @@ use MARC::Record; use C4::Biblio; use C4::Calendar; use C4::Items; -use C4::Reserves qw( AddReserve CalculatePriority ModReserve ToggleSuspend AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves ); +use C4::Reserves qw( AddReserve CalculatePriority ModReserve ToggleSuspend AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve ); use C4::Circulation qw( CanBookBeRenewed ); use Koha::Biblios; @@ -1809,3 +1809,81 @@ subtest 'Koha::Holds->get_items_that_can_fill returns items with datecancelled o $schema->storage->txn_rollback; }; + +subtest 'EmailPatronWhenHoldIsPlaced tests' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $item = $builder->build_sample_item; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $borrowernumber = $patron->id; + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rules => { + reservesallowed => 25, + holds_per_record => 99, + } + } + ); + + t::lib::Mocks::mock_preference( 'EmailPatronWhenHoldIsPlaced', 0 ); + my $original_notices_count = Koha::Notice::Messages->search( + { + letter_code => 'HOLDPLACED_PATRON', + to_address => $patron->notice_email_address, + } + )->count; + + my $hold_id = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $borrowernumber, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + } + ); + my $post_notices_count = Koha::Notice::Messages->search( + { + letter_code => 'HOLDPLACED_PATRON', + to_address => $patron->notice_email_address, + } + )->count; + is( + $post_notices_count, $original_notices_count, + "EmailPatronWhenHoldIsPlaced is disabled so no email is queued" + ); + MoveReserve( $item->itemnumber, $borrowernumber, 1 ); + + $original_notices_count = Koha::Notice::Messages->search( + { + letter_code => 'HOLDPLACED_PATRON', + to_address => $patron->notice_email_address, + } + )->count; + t::lib::Mocks::mock_preference( 'EmailPatronWhenHoldIsPlaced', 1 ); + AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $borrowernumber, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + } + ); + $post_notices_count = Koha::Notice::Messages->search( + { + letter_code => 'HOLDPLACED_PATRON', + to_address => $patron->notice_email_address, + } + )->count; + is( + $post_notices_count, + $original_notices_count + 1, + "EmailPatronWhenHoldIsPlaced is enabled so HOLDPLACED_PATRON email is queued" + ); + + $schema->storage->txn_rollback; +}; -- 2.30.2