@@ -, +, @@ move --- t/db_dependent/Circulation.t | 49 ++++++++++++++++++++++++++++++++++++- t/db_dependent/Reserves.t | 57 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 2 deletions(-) --- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 94; +use Test::More tests => 95; use DateTime; @@ -29,11 +29,14 @@ use C4::Biblio; use C4::Items; use C4::Log; use C4::Members; +use C4::Message; use C4::Reserves; use C4::Overdues qw(UpdateFine CalcFine); use Koha::DateUtils; use Koha::Database; use Koha::IssuingRules; +use Koha::Patron::Message::Attributes; +use Koha::Patron::Message::Preferences; use Koha::Subscriptions; my $schema = Koha::Database->schema; @@ -1480,6 +1483,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { } } ); + my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } ); my $item_2 = $builder->build( { @@ -1585,6 +1589,49 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { ); is( $debarments->[0]->{expiration}, $expected_expiration ); }; + +subtest 'SendCirculationAlert test' => sub { + plan tests => 4; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower' } ); + my $attribute = Koha::Patron::Message::Attributes->find({ + message_name => 'Item_Checkout', + }); + Koha::Patron::Message::Preference->new({ + borrowernumber => $patron->{'borrowernumber'}, + message_attribute_id => $attribute->message_attribute_id, + days_in_advance => 0, + wants_digest => 0, + message_transport_types => ['email'], + })->store; + my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } ); + my $item_1 = $builder->build( + { source => 'Item', + value => { + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + notforloan => 0, + itemlost => 0, + withdrawn => 0, + biblionumber => $biblioitem_1->{biblionumber} + } + } + ); + + my $old_message = C4::Message->find_last_message($patron, 'CHECKOUT', 'email'); + $old_message->{'message_id'} = 0 unless $old_message; + is(C4::Circulation::SendCirculationAlert({ + type => 'CHECKOUT', + item => $item_1, + borrower => $patron, + branch => $library->{'branchcode'}, + }), undef, "SendCirculationAlert called."); + my $new_message = C4::Message->find_last_message($patron, 'CHECKOUT', 'email'); + ok($old_message->{'message_id'} != $new_message->{'message_id'}, "New message has appeared."); + is($new_message->{'letter_code'}, 'CHECKOUT', "New message letter code is CHECKOUT."); + is($new_message->{'borrowernumber'}, $patron->{'borrowernumber'}, "New message is to our test patron."); +}; sub set_userenv { my ( $library ) = @_; --- a/t/db_dependent/Reserves.t +++ a/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 71; +use Test::More tests => 72; use Test::MockModule; use Test::Warn; @@ -31,12 +31,15 @@ use C4::Biblio; use C4::Circulation; use C4::Items; use C4::Members; +use C4::Message; use C4::Reserves; use Koha::Caches; use Koha::DateUtils; use Koha::Holds; use Koha::Libraries; use Koha::Patron::Categories; +use Koha::Patron::Message::Preference; +use Koha::Patrons; BEGIN { require_ok('C4::Reserves'); @@ -713,6 +716,58 @@ $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); +subtest '_koha_notify_reserve tests' => sub { + plan tests => 4; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); + my $attribute = Koha::Patron::Message::Attributes->find({ + message_name => 'Hold_Filled', + }); + Koha::Patron::Message::Preference->new({ + borrowernumber => $patron->{'borrowernumber'}, + message_attribute_id => $attribute->message_attribute_id, + days_in_advance => 0, + wants_digest => 0, + message_transport_types => ['email'], + })->store; + my $biblio_1 = $builder->build( { source => 'Biblio' } ); + my $item_1 = $builder->build( + { source => 'Item', + value => { + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + notforloan => 0, + itemlost => 0, + withdrawn => 0, + biblionumber => $biblio_1->{biblionumber} + } + } + ); + my $reserve_id = AddReserve( + $library->{branchcode}, + $patron->{'borrowernumber'}, + $biblio_1->{'biblionumber'}, + undef, + '1', + undef, + undef, + '', + $title, + $item_1->{'itemnumber'}, + 'W' + ); + + my $old_message = C4::Message->find_last_message($patron, 'HOLD', 'email'); + $old_message->{'message_id'} = 0 unless $old_message; + is(C4::Reserves::_koha_notify_reserve($reserve_id), '', + "_koha_notify_reserve called."); + my $new_message = C4::Message->find_last_message($patron, 'HOLD', 'email'); + ok($old_message->{'message_id'} != $new_message->{'message_id'}, "New message has appeared."); + is($new_message->{'letter_code'}, 'HOLD', "New message letter code is HOLD."); + is($new_message->{'borrowernumber'}, $patron->{'borrowernumber'}, "New message is to our test patron."); +}; + # we reached the finish $schema->storage->txn_rollback(); --