From e1a5baf4460063d36195685c0db102e399e9a89f Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Wed, 2 Nov 2016 16:20:12 +0200 Subject: [PATCH] Bug 18595: Unit tests preparing for GetMessagingPreferences move MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch prepares removing GetMessagingPreferences by adding some useful unit tests for subroutines that the move targets. Reserves.t already covers print notice, but this patch adds tests for a set transport type. To test: 1. Run t/db_dependent/Circulation.t 2. Run t/db_dependent/Reserves.t 3. Observe test pass Works together with followup patch Signed-off-by: Marc VĂ©ron Signed-off-by: David Bourgault Rebased-by: Emmi Takkinen --- t/db_dependent/Circulation.t | 48 +++++++++++++++++++++++++++++++++++- t/db_dependent/Reserves.t | 23 ++++++++--------- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 2ecb44bec4..e32a89ee6f 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 65; +use Test::More tests => 66; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -41,6 +41,7 @@ use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ModReserveAffect use C4::Overdues qw( CalcFine UpdateFine get_chargeable_units ); use C4::Members::Messaging qw( SetMessagingPreference ); use Koha::DateUtils qw( dt_from_string output_pref ); +use C4::Message; use Koha::Database; use Koha::Items; use Koha::Item::Transfers; @@ -49,6 +50,8 @@ use Koha::Patrons; use Koha::Patron::Debarments qw( AddDebarment DelUniqueDebarment ); use Koha::Holds; use Koha::CirculationRules; +use Koha::Patron::MessagePreference::Attributes; +use Koha::Patron::MessagePreferences; use Koha::Subscriptions; use Koha::Account::Lines; use Koha::Account::Offsets; @@ -4223,6 +4226,49 @@ subtest 'ItemsDeniedRenewal rules are checked' => sub { $mock_item_class->unmock( 'is_denied_renewal' ); }; +subtest 'SendCirculationAlert test' => sub { + plan tests => 4; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower' } ); + my $attribute = Koha::Patron::MessagePreference::Attributes->find({ + message_name => 'Item_Checkout', + }); + Koha::Patron::MessagePreference->new({ + borrowernumber => $patron->{'borrowernumber'}, + message_attribute_id => $attribute->message_attribute_id, + days_in_advance => undef, + 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."); +}; + subtest 'CanBookBeIssued | item-level_itypes=biblio' => sub { plan tests => 2; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 3371c9539d..27ac97a89f 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -42,6 +42,7 @@ use Koha::Libraries; use Koha::Notice::Templates; use Koha::Patrons; use Koha::Patron::Categories; +use Koha::Patron::MessagePreference; use Koha::CirculationRules; BEGIN { @@ -804,19 +805,6 @@ subtest '_koha_notify_reserve() tests' => sub { holdingbranch => $branch->branchcode }); - my $wants_hold_and_email = { - wants_digest => '0', - transports => { - sms => 'HOLD', - email => 'HOLD', - }, - letter_code => 'HOLD' - }; - - my $mp = Test::MockModule->new( 'C4::Members::Messaging' ); - - $mp->mock("GetMessagingPreferences",$wants_hold_and_email); - $dbh->do('DELETE FROM letter'); my $email_hold_notice = $builder->build({ @@ -857,6 +845,15 @@ subtest '_koha_notify_reserve() tests' => sub { } ); + my $message_attr_id = Koha::Patron::MessagePreference::Attributes->find({ + message_name => 'Hold_Filled' + })->message_attribute_id; + Koha::Patron::MessagePreference->new({ + borrowernumber => $hold_borrower, + message_attribute_id => $message_attr_id, + message_transport_types => ['sms', 'email'], + wants_digest => 0, + })->store; ModReserveAffect($item->itemnumber, $hold_borrower, 0); my $sms_message_address = $schema->resultset('MessageQueue')->search({ letter_code => 'HOLD', -- 2.25.1