Bug 17617: Unit tests

Signed-off-by: Kelly <kelly@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Aleisha Amohia 2023-10-26 21:06:35 +00:00 committed by Tomas Cohen Arazi
parent b62699dff0
commit 9e865b9f03
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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;
};