From e39350b65facbf97f7f7599939482c5925e99ada Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 18 Mar 2021 03:16:11 +0000 Subject: [PATCH] Bug 17499: (follow-up) Add $patron->messaging_preferences accessor To test: 1. prove t/db_dependent/Koha/Patron.t Sponsored-by: The National Library of Finland Signed-off-by: Michal Denar --- Koha/Patron.pm | 14 ++++++++++ t/db_dependent/Koha/Patron.t | 53 +++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index cd5357ab5a..923e079eac 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -668,6 +668,20 @@ sub merge_with { } +=head3 messaging_preferences + + my $patron = Koha::Patrons->find($id); + $patron->messaging_preferences(); + +=cut + +sub messaging_preferences { + my ( $self ) = @_; + + return Koha::Patron::MessagePreferences->search({ + borrowernumber => $self->borrowernumber, + }); +} =head3 wants_check_for_previous_checkout diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index e92b054d86..6c2e708d51 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 19; +use Test::More tests => 20; use Test::Exception; use Test::Warn; @@ -287,6 +287,57 @@ subtest 'add_enrolment_fee_if_needed() tests' => sub { }; }; +subtest 'messaging_preferences() tests' => sub { + plan tests => 5; + + $schema->storage->txn_begin; + + my $mtt = $builder->build_object({ + class => 'Koha::Patron::MessagePreference::Transport::Types' + }); + my $attribute = $builder->build_object({ + class => 'Koha::Patron::MessagePreference::Attributes' + }); + my $branchcode = $builder->build({ + source => 'Branch' })->{branchcode}; + my $letter = $builder->build_object({ + class => 'Koha::Notice::Templates', + value => { + branchcode => '', + is_html => 0, + message_transport_type => $mtt->message_transport_type + } + }); + + Koha::Patron::MessagePreference::Transport->new({ + message_attribute_id => $attribute->message_attribute_id, + message_transport_type => $mtt->message_transport_type, + is_digest => 0, + letter_module => $letter->module, + letter_code => $letter->code, + })->store; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + + my $preference = Koha::Patron::MessagePreference->new({ + borrowernumber => $patron->borrowernumber, + message_attribute_id => $attribute->message_attribute_id, + wants_digest => 0, + days_in_advance => undef, + })->store; + + my $messaging_preferences = $patron->messaging_preferences(); + is($messaging_preferences->count, 1, 'Found one preference'); + + my $messaging_preference = $messaging_preferences->next; + is($messaging_preference->borrowernumber, $patron->borrowernumber); + is($messaging_preference->message_attribute_id, $attribute->message_attribute_id); + is($messaging_preference->wants_digest, 0); + is($messaging_preference->days_in_advance, undef); + + $schema->storage->txn_rollback; +}; + subtest 'to_api() tests' => sub { plan tests => 6; -- 2.25.1