From 27456a217ce5eb70444681d727f3bae0b8673c24 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 --- 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 3a5144006d..a8c8200df8 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.30.2