From 80af5847eac08c31b1a54d5da9188de0ba0c5cf6 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 Signed-off-by: Sam Lau Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- 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 996ea4d2ee..18e9d234e0 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -681,6 +681,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 5d05a16efd..b2c82dfb9c 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 => 24; +use Test::More tests => 25; use Test::Exception; use Test::Warn; @@ -288,6 +288,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.39.5