3 # This file is part of Koha.
5 # Copyright (C) 2018 Andreas Jonsson <andreas.jonsson@kreablo.se>
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 1;
23 use t::lib::TestBuilder;
28 use Koha::DateUtils qw( dt_from_string );
30 my $schema = Koha::Database->new->schema;
31 my $dbh = C4::Context->dbh;
36 subtest 'Default behaviour tests' => sub {
40 $schema->storage->txn_begin;
42 # Set only to avoid exception.
43 t::lib::Mocks::mock_preference( 'dateformat', 'metric' );
45 my $builder = t::lib::TestBuilder->new;
47 $library = $builder->build(
53 $borrower = $builder->build(
57 branchcode => $library->{branchcode},
62 $dbh->do(<<DELETESQL);
64 WHERE module='circulation'
65 AND code = 'PREDUEDGST'
66 AND message_transport_type='email'
70 $dbh->do(<<DELETESQL);
71 DELETE FROM message_attributes WHERE message_name = 'Advance_Notice'
74 my $message_attribute = $builder->build(
76 source => 'MessageAttribute',
78 message_name => 'Advance_Notice'
83 my $letter = $builder->build(
87 module => 'circulation',
90 message_transport_type => 'email',
93 content => '<<count>> <<branches.branchname>>'
97 my $borrower_message_preference = $builder->build(
99 source => 'BorrowerMessagePreference',
101 borrowernumber => $borrower->{borrowernumber},
103 days_in_advance => 1,
104 message_attribute_id =>
105 $message_attribute->{message_attribute_id}
110 my $borrower_message_transport_preference = $builder->build(
112 source => 'BorrowerMessageTransportPreference',
114 borrower_message_preference_id => $borrower_message_preference
115 ->{borrower_message_preference_id},
116 message_transport_type => 'email'
121 my $borrower_message_transport_preference_1 = $builder->build(
123 source => 'BorrowerMessageTransportPreference',
125 borrower_message_preference_id => $borrower_message_preference
126 ->{borrower_message_preference_id},
127 message_transport_type => 'phone'
132 my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
134 is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'email' }), 1, "Patron has Advance_Notice email preference" );
135 is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'phone' }), 1, "Patron has Advance_Notice phone preference" );
136 is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'sms' }), 0, "Patron has no Advance_Notice sms preference" );