View | Details | Raw Unified | Return to bug 17499
Collapse All | Expand All

(-)a/Koha/Exceptions/Patron/Message/Preference.pm (-22 / +22 lines)
Lines 1-4 Link Here
1
package Koha::Exceptions::Patron::Message::Preference;
1
package Koha::Exceptions::Patron::MessagePreference;
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
Lines 19-74 use Modern::Perl; Link Here
19
19
20
use Exception::Class (
20
use Exception::Class (
21
21
22
    'Koha::Exceptions::Patron::Message::Preference' => {
22
    'Koha::Exceptions::Patron::MessagePreference' => {
23
        description => 'Something went wrong'
23
        description => 'Something went wrong'
24
    },
24
    },
25
    'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound' => {
25
    'Koha::Exceptions::Patron::MessagePreference::AttributeNotFound' => {
26
        isa => 'Koha::Exceptions::Patron::Message::Preference',
26
        isa => 'Koha::Exceptions::Patron::MessagePreference',
27
        description => "Message attribute not found",
27
        description => "Message attribute not found",
28
        fields => ['message_attribute_id']
28
        fields => ['message_attribute_id']
29
    },
29
    },
30
    'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange' => {
30
    'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange' => {
31
        isa => 'Koha::Exceptions::Patron::Message::Preference',
31
        isa => 'Koha::Exceptions::Patron::MessagePreference',
32
        description => "Days in advance is out of range",
32
        description => "Days in advance is out of range",
33
        fields => ['min','max', 'message_name']
33
        fields => ['min','max', 'message_name']
34
    },
34
    },
35
    'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable' => {
35
    'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable' => {
36
        isa => 'Koha::Exceptions::Patron::Message::Preference',
36
        isa => 'Koha::Exceptions::Patron::MessagePreference',
37
        description => "Days in advance cannot be selected for this preference",
37
        description => "Days in advance cannot be selected for this preference",
38
        fields => ['message_name']
38
        fields => ['message_name']
39
    },
39
    },
40
    'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable' => {
40
    'Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable' => {
41
        isa => 'Koha::Exceptions::Patron::Message::Preference',
41
        isa => 'Koha::Exceptions::Patron::MessagePreference',
42
        description => "Digest is not available for this message type",
42
        description => "Digest is not available for this message type",
43
        fields => ['message_name']
43
        fields => ['message_name']
44
    },
44
    },
45
    'Koha::Exceptions::Patron::Message::Preference::DigestRequired' => {
45
    'Koha::Exceptions::Patron::MessagePreference::DigestRequired' => {
46
        isa => 'Koha::Exceptions::Patron::Message::Preference',
46
        isa => 'Koha::Exceptions::Patron::MessagePreference',
47
        description => "Digest must be selected for this message type",
47
        description => "Digest must be selected for this message type",
48
        fields => ['message_name']
48
        fields => ['message_name']
49
    },
49
    },
50
    'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired' => {
50
    'Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired' => {
51
        isa => 'Koha::Exceptions::Patron::Message::Preference',
51
        isa => 'Koha::Exceptions::Patron::MessagePreference',
52
        description => "Patron has no email address, cannot use email transport type.",
52
        description => "Patron has no email address, cannot use email transport type.",
53
        fields => ['message_name', 'borrowernumber' ]
53
        fields => ['message_name', 'borrowernumber' ]
54
    },
54
    },
55
    'Koha::Exceptions::Patron::Message::Preference::NoTransportType' => {
55
    'Koha::Exceptions::Patron::MessagePreference::NoTransportType' => {
56
        isa => 'Koha::Exceptions::Patron::Message::Preference',
56
        isa => 'Koha::Exceptions::Patron::MessagePreference',
57
        description => "Transport type not available for this message.",
57
        description => "Transport type not available for this message.",
58
        fields => ['message_name', 'transport_type']
58
        fields => ['message_name', 'transport_type']
59
    },
59
    },
60
    'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired' => {
60
    'Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired' => {
61
        isa => 'Koha::Exceptions::Patron::Message::Preference',
61
        isa => 'Koha::Exceptions::Patron::MessagePreference',
62
        description => "Patron has no phone number, cannot use phone transport type.",
62
        description => "Patron has no phone number, cannot use phone transport type.",
63
        fields => ['message_name', 'borrowernumber' ]
63
        fields => ['message_name', 'borrowernumber' ]
64
    },
64
    },
65
    'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired' => {
65
    'Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired' => {
66
        isa => 'Koha::Exceptions::Patron::Message::Preference',
66
        isa => 'Koha::Exceptions::Patron::MessagePreference',
67
        description => "Patron has no SMS number, cannot use sms transport type.",
67
        description => "Patron has no SMS number, cannot use sms transport type.",
68
        fields => ['message_name', 'borrowernumber' ]
68
        fields => ['message_name', 'borrowernumber' ]
69
    },
69
    },
70
    'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired' => {
70
    'Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired' => {
71
        isa => 'Koha::Exceptions::Patron::Message::Preference',
71
        isa => 'Koha::Exceptions::Patron::MessagePreference',
72
        description => "System preference TalkingTechItivaPhoneNotification is disabled, cannot use itiva transport type.",
72
        description => "System preference TalkingTechItivaPhoneNotification is disabled, cannot use itiva transport type.",
73
        fields => ['message_name', 'borrowernumber' ]
73
        fields => ['message_name', 'borrowernumber' ]
74
    },
74
    },
(-)a/Koha/Exceptions/Patron/Message/Transport.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Exceptions::Patron::Message::Transport;
1
package Koha::Exceptions::Patron::MessagePreference::Transport;
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
Lines 19-29 use Modern::Perl; Link Here
19
19
20
use Exception::Class (
20
use Exception::Class (
21
21
22
    'Koha::Exceptions::Patron::Message::Transport' => {
22
    'Koha::Exceptions::Patron::MessagePreference::Transport' => {
23
        description => 'Something went wrong'
23
        description => 'Something went wrong'
24
    },
24
    },
25
    'Koha::Exceptions::Patron::Message::Transport::TypeNotFound' => {
25
    'Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound' => {
26
        isa => 'Koha::Exceptions::Patron::Message::Transport',
26
        isa => 'Koha::Exceptions::Patron::MessagePreference::Transport',
27
        description => "Transport type does not exist.",
27
        description => "Transport type does not exist.",
28
        fields => ['transport_type']
28
        fields => ['transport_type']
29
    },
29
    },
(-)a/Koha/Patron.pm (-6 / +6 lines)
Lines 50-56 use Koha::Patron::HouseboundRole; Link Here
50
use Koha::Patron::Images;
50
use Koha::Patron::Images;
51
use Koha::Patron::Messages;
51
use Koha::Patron::Messages;
52
use Koha::Patron::Modifications;
52
use Koha::Patron::Modifications;
53
use Koha::Patron::Message::Preferences;
53
use Koha::Patron::MessagePreferences;
54
use Koha::Patron::Relationships;
54
use Koha::Patron::Relationships;
55
use Koha::Patron::Restrictions;
55
use Koha::Patron::Restrictions;
56
use Koha::Patrons;
56
use Koha::Patrons;
Lines 2057-2063 sub get_extended_attribute { Link Here
2057
2057
2058
Sets default messaging preferences on patron.
2058
Sets default messaging preferences on patron.
2059
2059
2060
See Koha::Patron::Message::Preference(s) for more documentation, especially on
2060
See Koha::Patron::MessagePreference(s) for more documentation, especially on
2061
thrown exceptions.
2061
thrown exceptions.
2062
2062
2063
=cut
2063
=cut
Lines 2065-2075 thrown exceptions. Link Here
2065
sub set_default_messaging_preferences {
2065
sub set_default_messaging_preferences {
2066
    my ($self, $categorycode) = @_;
2066
    my ($self, $categorycode) = @_;
2067
2067
2068
    my $options = Koha::Patron::Message::Preferences->get_options;
2068
    my $options = Koha::Patron::MessagePreferences->get_options;
2069
2069
2070
    foreach my $option (@$options) {
2070
    foreach my $option (@$options) {
2071
        # Check that this option has preference configuration for this category
2071
        # Check that this option has preference configuration for this category
2072
        unless (Koha::Patron::Message::Preferences->search({
2072
        unless (Koha::Patron::MessagePreferences->search({
2073
            message_attribute_id => $option->{message_attribute_id},
2073
            message_attribute_id => $option->{message_attribute_id},
2074
            categorycode         => $categorycode || $self->categorycode,
2074
            categorycode         => $categorycode || $self->categorycode,
2075
        })->count) {
2075
        })->count) {
Lines 2077-2088 sub set_default_messaging_preferences { Link Here
2077
        }
2077
        }
2078
2078
2079
        # Delete current setting
2079
        # Delete current setting
2080
        Koha::Patron::Message::Preferences->search({
2080
        Koha::Patron::MessagePreferences->search({
2081
             borrowernumber => $self->borrowernumber,
2081
             borrowernumber => $self->borrowernumber,
2082
             message_attribute_id => $option->{message_attribute_id},
2082
             message_attribute_id => $option->{message_attribute_id},
2083
        })->delete;
2083
        })->delete;
2084
2084
2085
        Koha::Patron::Message::Preference->new_from_default({
2085
        Koha::Patron::MessagePreference->new_from_default({
2086
            borrowernumber => $self->borrowernumber,
2086
            borrowernumber => $self->borrowernumber,
2087
            categorycode   => $categorycode || $self->categorycode,
2087
            categorycode   => $categorycode || $self->categorycode,
2088
            message_attribute_id => $option->{message_attribute_id},
2088
            message_attribute_id => $option->{message_attribute_id},
(-)a/Koha/Patron/Message/Preference.pm (-36 / +36 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Preference;
1
package Koha::Patron::MessagePreference;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 21-42 use Modern::Perl; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Exceptions;
23
use Koha::Exceptions;
24
use Koha::Exceptions::Patron::Message::Preference;
24
use Koha::Exceptions::Patron::MessagePreference;
25
use Koha::Exceptions::Patron::Message::Transport;
25
use Koha::Exceptions::Patron::MessagePreference::Transport;
26
use Koha::Exceptions::Patron::Category;
26
use Koha::Exceptions::Patron::Category;
27
use Koha::Patron::Categories;
27
use Koha::Patron::Categories;
28
use Koha::Patron::Message::Attributes;
28
use Koha::Patron::MessagePreference::Attributes;
29
use Koha::Patron::Message::Preferences;
29
use Koha::Patron::MessagePreferences;
30
use Koha::Patron::Message::Transport::Preferences;
30
use Koha::Patron::MessagePreference::Transport::Preferences;
31
use Koha::Patron::Message::Transport::Types;
31
use Koha::Patron::MessagePreference::Transport::Types;
32
use Koha::Patron::Message::Transports;
32
use Koha::Patron::MessagePreference::Transports;
33
use Koha::Patrons;
33
use Koha::Patrons;
34
34
35
use base qw(Koha::Object);
35
use base qw(Koha::Object);
36
36
37
=head1 NAME
37
=head1 NAME
38
38
39
Koha::Patron::Message::Preference - Koha Patron Message Preference object class
39
Koha::Patron::MessagePreference - Koha Patron Message Preference object class
40
40
41
=head1 API
41
=head1 API
42
42
Lines 46-52 Koha::Patron::Message::Preference - Koha Patron Message Preference object class Link Here
46
46
47
=head3 new
47
=head3 new
48
48
49
my $preference = Koha::Patron::Message::Preference->new({
49
my $preference = Koha::Patron::MessagePreference->new({
50
   borrowernumber => 123,
50
   borrowernumber => 123,
51
   #categorycode => 'ABC',
51
   #categorycode => 'ABC',
52
   message_attribute_id => 4,
52
   message_attribute_id => 4,
Lines 89-95 sub new { Link Here
89
89
90
=head3 new_from_default
90
=head3 new_from_default
91
91
92
my $preference = Koha::Patron::Message::Preference->new_from_default({
92
my $preference = Koha::Patron::MessagePreference->new_from_default({
93
    borrowernumber => 123,
93
    borrowernumber => 123,
94
    categorycode   => 'ABC',   # if not given, patron's categorycode will be used
94
    categorycode   => 'ABC',   # if not given, patron's categorycode will be used
95
    message_attribute_id => 1,
95
    message_attribute_id => 1,
Lines 124-130 sub new_from_default { Link Here
124
        $params->{'categorycode'} = $patron->categorycode;
124
        $params->{'categorycode'} = $patron->categorycode;
125
    }
125
    }
126
126
127
    my $default = Koha::Patron::Message::Preferences->find({
127
    my $default = Koha::Patron::MessagePreferences->find({
128
        categorycode => $params->{'categorycode'},
128
        categorycode => $params->{'categorycode'},
129
        message_attribute_id => $params->{'message_attribute_id'},
129
        message_attribute_id => $params->{'message_attribute_id'},
130
    });
130
    });
Lines 144-155 sub new_from_default { Link Here
144
144
145
    # Set default messaging transport types
145
    # Set default messaging transport types
146
    my $default_transport_types =
146
    my $default_transport_types =
147
    Koha::Patron::Message::Transport::Preferences->search({
147
    Koha::Patron::MessagePreference::Transport::Preferences->search({
148
        borrower_message_preference_id =>
148
        borrower_message_preference_id =>
149
                    $default->{'borrower_message_preference_id'}
149
                    $default->{'borrower_message_preference_id'}
150
    });
150
    });
151
    while (my $transport = $default_transport_types->next) {
151
    while (my $transport = $default_transport_types->next) {
152
        Koha::Patron::Message::Transport::Preference->new({
152
        Koha::Patron::MessagePreference::Transport::Preference->new({
153
            borrower_message_preference_id => $self->borrower_message_preference_id,
153
            borrower_message_preference_id => $self->borrower_message_preference_id,
154
            message_transport_type => $transport->message_transport_type,
154
            message_transport_type => $transport->message_transport_type,
155
        })->store;
155
        })->store;
Lines 174-180 sub message_name { Link Here
174
    if ($self->{'_message_name'}) {
174
    if ($self->{'_message_name'}) {
175
        return $self->{'_message_name'};
175
        return $self->{'_message_name'};
176
    }
176
    }
177
    $self->{'_message_name'} = Koha::Patron::Message::Attributes->find({
177
    $self->{'_message_name'} = Koha::Patron::MessagePreference::Attributes->find({
178
        message_attribute_id => $self->message_attribute_id,
178
        message_attribute_id => $self->message_attribute_id,
179
    })->message_name;
179
    })->message_name;
180
    return $self->{'_message_name'};
180
    return $self->{'_message_name'};
Lines 201-207 sub message_transport_types { Link Here
201
            return $self->{'_message_transport_types'};
201
            return $self->{'_message_transport_types'};
202
        }
202
        }
203
        map {
203
        map {
204
            my $transport = Koha::Patron::Message::Transports->find({
204
            my $transport = Koha::Patron::MessagePreference::Transports->find({
205
                message_attribute_id => $self->message_attribute_id,
205
                message_attribute_id => $self->message_attribute_id,
206
                message_transport_type => $_->message_transport_type,
206
                message_transport_type => $_->message_transport_type,
207
                is_digest => $self->wants_digest
207
                is_digest => $self->wants_digest
Lines 217-223 sub message_transport_types { Link Here
217
            $self->{'_message_transport_types'}->{$_->message_transport_type}
217
            $self->{'_message_transport_types'}->{$_->message_transport_type}
218
                = $transport ? $transport->letter_code : ' ';
218
                = $transport ? $transport->letter_code : ' ';
219
        }
219
        }
220
        Koha::Patron::Message::Transport::Preferences->search({
220
        Koha::Patron::MessagePreference::Transport::Preferences->search({
221
            borrower_message_preference_id => $self->borrower_message_preference_id,
221
            borrower_message_preference_id => $self->borrower_message_preference_id,
222
        })->as_list;
222
        })->as_list;
223
        return $self->{'_message_transport_types'} || {};
223
        return $self->{'_message_transport_types'} || {};
Lines 295-306 sub store { Link Here
295
295
296
    # store message transport types
296
    # store message transport types
297
    if (exists $self->{'_message_transport_types'}) {
297
    if (exists $self->{'_message_transport_types'}) {
298
        Koha::Patron::Message::Transport::Preferences->search({
298
        Koha::Patron::MessagePreference::Transport::Preferences->search({
299
            borrower_message_preference_id =>
299
            borrower_message_preference_id =>
300
                $self->borrower_message_preference_id,
300
                $self->borrower_message_preference_id,
301
        })->delete;
301
        })->delete;
302
        foreach my $type (keys %{$self->{'_message_transport_types'}}) {
302
        foreach my $type (keys %{$self->{'_message_transport_types'}}) {
303
            Koha::Patron::Message::Transport::Preference->new({
303
            Koha::Patron::MessagePreference::Transport::Preference->new({
304
                borrower_message_preference_id =>
304
                borrower_message_preference_id =>
305
                    $self->borrower_message_preference_id,
305
                    $self->borrower_message_preference_id,
306
                message_transport_type => $type,
306
                message_transport_type => $type,
Lines 315-321 sub store { Link Here
315
315
316
Makes a basic validation for object.
316
Makes a basic validation for object.
317
317
318
Returns Koha::Patron::Message::Preference object, or throws and exception.
318
Returns Koha::Patron::MessagePreference object, or throws and exception.
319
319
320
=cut
320
=cut
321
321
Lines 344-350 sub validate { Link Here
344
    }
344
    }
345
345
346
    if (!$self->in_storage) {
346
    if (!$self->in_storage) {
347
        my $previous = Koha::Patron::Message::Preferences->search({
347
        my $previous = Koha::Patron::MessagePreferences->search({
348
            borrowernumber => $self->borrowernumber,
348
            borrowernumber => $self->borrowernumber,
349
            categorycode   => $self->categorycode,
349
            categorycode   => $self->categorycode,
350
            message_attribute_id => $self->message_attribute_id,
350
            message_attribute_id => $self->message_attribute_id,
Lines 357-367 sub validate { Link Here
357
        }
357
        }
358
    }
358
    }
359
359
360
    my $attr = Koha::Patron::Message::Attributes->find(
360
    my $attr = Koha::Patron::MessagePreference::Attributes->find(
361
        $self->message_attribute_id
361
        $self->message_attribute_id
362
    );
362
    );
363
    unless ($attr) {
363
    unless ($attr) {
364
        Koha::Exceptions::Patron::Message::Preference::AttributeNotFound->throw(
364
        Koha::Exceptions::Patron::MessagePreference::AttributeNotFound->throw(
365
            error => 'Message attribute with id '.$self->message_attribute_id
365
            error => 'Message attribute with id '.$self->message_attribute_id
366
            .' not found',
366
            .' not found',
367
            message_attribute_id => $self->message_attribute_id,
367
            message_attribute_id => $self->message_attribute_id,
Lines 369-382 sub validate { Link Here
369
    }
369
    }
370
    if (defined $self->days_in_advance) {
370
    if (defined $self->days_in_advance) {
371
        if ($attr && $attr->takes_days == 0) {
371
        if ($attr && $attr->takes_days == 0) {
372
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable->throw(
372
            Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable->throw(
373
                error => 'days_in_advance cannot be defined for '.
373
                error => 'days_in_advance cannot be defined for '.
374
                $attr->message_name . '.',
374
                $attr->message_name . '.',
375
                message_name => $attr->message_name,
375
                message_name => $attr->message_name,
376
            );
376
            );
377
        }
377
        }
378
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
378
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
379
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange->throw(
379
            Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange->throw(
380
                error => 'days_in_advance has to be a value between 0-30 for '.
380
                error => 'days_in_advance has to be a value between 0-30 for '.
381
                $attr->message_name . '.',
381
                $attr->message_name . '.',
382
                message_name => $attr->message_name,
382
                message_name => $attr->message_name,
Lines 386-403 sub validate { Link Here
386
        }
386
        }
387
    }
387
    }
388
    if (defined $self->wants_digest) {
388
    if (defined $self->wants_digest) {
389
        my $transports = Koha::Patron::Message::Transports->search({
389
        my $transports = Koha::Patron::MessagePreference::Transports->search({
390
            message_attribute_id => $self->message_attribute_id,
390
            message_attribute_id => $self->message_attribute_id,
391
            is_digest            => $self->wants_digest ? 1 : 0,
391
            is_digest            => $self->wants_digest ? 1 : 0,
392
        });
392
        });
393
        unless ($transports->count) {
393
        unless ($transports->count) {
394
            if (!$self->wants_digest) {
394
            if (!$self->wants_digest) {
395
                Koha::Exceptions::Patron::Message::Preference::DigestRequired->throw(
395
                Koha::Exceptions::Patron::MessagePreference::DigestRequired->throw(
396
                    error => 'Digest must be selected for '.$attr->message_name.'.',
396
                    error => 'Digest must be selected for '.$attr->message_name.'.',
397
                    message_name => $attr->message_name
397
                    message_name => $attr->message_name
398
                );
398
                );
399
            } else {
399
            } else {
400
                Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable->throw(
400
                Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable->throw(
401
                    error => 'Digest cannot be selected for '.$attr->message_name.'.',
401
                    error => 'Digest cannot be selected for '.$attr->message_name.'.',
402
                    message_name => $attr->message_name
402
                    message_name => $attr->message_name
403
                );
403
                );
Lines 419-430 sub _set_message_transport_types { Link Here
419
    $self->_validate_message_transport_types({ message_transport_types => $types });
419
    $self->_validate_message_transport_types({ message_transport_types => $types });
420
    foreach my $type (@$types) {
420
    foreach my $type (@$types) {
421
        unless (exists $self->{'_message_transport_types'}->{$type}) {
421
        unless (exists $self->{'_message_transport_types'}->{$type}) {
422
            my $transport = Koha::Patron::Message::Transports->search({
422
            my $transport = Koha::Patron::MessagePreference::Transports->search({
423
                message_attribute_id => $self->message_attribute_id,
423
                message_attribute_id => $self->message_attribute_id,
424
                message_transport_type => $type
424
                message_transport_type => $type
425
            })->next;
425
            })->next;
426
            unless ($transport) {
426
            unless ($transport) {
427
                Koha::Exceptions::Patron::Message::Preference::NoTransportType->throw(
427
                Koha::Exceptions::Patron::MessagePreference::NoTransportType->throw(
428
                    error => 'No transport configured for '.$self->message_name.
428
                    error => 'No transport configured for '.$self->message_name.
429
                        " transport type $type.",
429
                        " transport type $type.",
430
                    message_name => $self->message_name,
430
                    message_name => $self->message_name,
Lines 433-457 sub _set_message_transport_types { Link Here
433
            }
433
            }
434
            if (defined $self->borrowernumber) {
434
            if (defined $self->borrowernumber) {
435
                if ( ! $self->mtt_deliverable($type) ) {
435
                if ( ! $self->mtt_deliverable($type) ) {
436
                    Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired->throw(
436
                    Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired->throw(
437
                        error => 'Patron has not set email address, '.
437
                        error => 'Patron has not set email address, '.
438
                                  'cannot use email as message transport',
438
                                  'cannot use email as message transport',
439
                        message_name => $self->message_name,
439
                        message_name => $self->message_name,
440
                        borrowernumber => $self->borrowernumber,
440
                        borrowernumber => $self->borrowernumber,
441
                    ) if $type eq 'email';
441
                    ) if $type eq 'email';
442
                    Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired->throw(
442
                    Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired->throw(
443
                        error => 'System preference TalkingTechItivaPhoneNotification disabled'.
443
                        error => 'System preference TalkingTechItivaPhoneNotification disabled'.
444
                                 'cannot use itiva as message transport',
444
                                 'cannot use itiva as message transport',
445
                        message_name => $self->message_name,
445
                        message_name => $self->message_name,
446
                        borrowernumber => $self->borrowernumber,
446
                        borrowernumber => $self->borrowernumber,
447
                    ) if $type eq 'itiva';
447
                    ) if $type eq 'itiva';
448
                    Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired->throw(
448
                    Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired->throw(
449
                        error => 'Patron has not set phone number'.
449
                        error => 'Patron has not set phone number'.
450
                                 'cannot use phone as message transport',
450
                                 'cannot use phone as message transport',
451
                        message_name => $self->message_name,
451
                        message_name => $self->message_name,
452
                        borrowernumber => $self->borrowernumber,
452
                        borrowernumber => $self->borrowernumber,
453
                    ) if $type eq 'phone';
453
                    ) if $type eq 'phone';
454
                    Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
454
                    Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired->throw(
455
                        error => 'Patron has not set SMS number'.
455
                        error => 'Patron has not set SMS number'.
456
                                 'cannot use sms as message transport',
456
                                 'cannot use sms as message transport',
457
                        message_name => $self->message_name,
457
                        message_name => $self->message_name,
Lines 476-485 sub _validate_message_transport_types { Link Here
476
        my $types = $params->{'message_transport_types'};
476
        my $types = $params->{'message_transport_types'};
477
477
478
        foreach my $type (@{$types}) {
478
        foreach my $type (@{$types}) {
479
            unless (Koha::Patron::Message::Transport::Types->find({
479
            unless (Koha::Patron::MessagePreference::Transport::Types->find({
480
                message_transport_type => $type
480
                message_transport_type => $type
481
            })) {
481
            })) {
482
                Koha::Exceptions::Patron::Message::Transport::TypeNotFound->throw(
482
                Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound->throw(
483
                    error => "Message transport type '$type' does not exist",
483
                    error => "Message transport type '$type' does not exist",
484
                    transport_type => $type,
484
                    transport_type => $type,
485
                );
485
                );
(-)a/Koha/Patron/Message/Attribute.pm (-2 / +2 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Attribute;
1
package Koha::Patron::MessagePreference::Attribute;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
Koha::Patron::Message::Attribute - Koha Patron Message Attribute object class
28
Koha::Patron::MessagePreference::Attribute - Koha Patron Message Attribute object class
29
29
30
=head1 API
30
=head1 API
31
31
(-)a/Koha/Patron/Message/Attributes.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Attributes;
1
package Koha::Patron::MessagePreference::Attributes;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 20-32 package Koha::Patron::Message::Attributes; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Attribute;
23
use Koha::Patron::MessagePreference::Attribute;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Koha::Patron::Message::Attributes - Koha Patron Message Attributes object class
29
Koha::Patron::MessagePreference::Attributes - Koha Patron Message Attributes object class
30
30
31
=head1 API
31
=head1 API
32
32
Lines 49-55 sub _type { Link Here
49
=cut
49
=cut
50
50
51
sub object_class {
51
sub object_class {
52
    return 'Koha::Patron::Message::Attribute';
52
    return 'Koha::Patron::MessagePreference::Attribute';
53
}
53
}
54
54
55
=head1 AUTHOR
55
=head1 AUTHOR
(-)a/Koha/Patron/Message/Transport.pm (-2 / +2 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transport;
1
package Koha::Patron::MessagePreference::Transport;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
Koha::Patron::Message::Transport - Koha Patron Message Transport object class
28
Koha::Patron::MessagePreference::Transport - Koha Patron Message Transport object class
29
29
30
=head1 API
30
=head1 API
31
31
(-)a/Koha/Patron/Message/Transport/Preference.pm (-2 / +2 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transport::Preference;
1
package Koha::Patron::MessagePreference::Transport::Preference;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
Koha::Patron::Message::Transport::Preference - Koha Patron Message Transport
28
Koha::Patron::MessagePreference::Transport::Preference - Koha Patron Message Transport
29
Preference object class
29
Preference object class
30
30
31
=head1 API
31
=head1 API
(-)a/Koha/Patron/Message/Transport/Preferences.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transport::Preferences;
1
package Koha::Patron::MessagePreference::Transport::Preferences;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 20-32 package Koha::Patron::Message::Transport::Preferences; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Transport::Preference;
23
use Koha::Patron::MessagePreference::Transport::Preference;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Koha::Patron::Message::Transport::Preferences - Koha Patron Message Transport
29
Koha::Patron::MessagePreference::Transport::Preferences - Koha Patron Message Transport
30
Preferences object class
30
Preferences object class
31
31
32
=head1 API
32
=head1 API
Lines 48-54 sub _type { Link Here
48
=cut
48
=cut
49
49
50
sub object_class {
50
sub object_class {
51
    return 'Koha::Patron::Message::Transport::Preference';
51
    return 'Koha::Patron::MessagePreference::Transport::Preference';
52
}
52
}
53
53
54
=head1 AUTHOR
54
=head1 AUTHOR
(-)a/Koha/Patron/Message/Transport/Type.pm (-2 / +2 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transport::Type;
1
package Koha::Patron::MessagePreference::Transport::Type;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
Koha::Patron::Message::Transport::Type - Koha Patron Message Transport Type
28
Koha::Patron::MessagePreference::Transport::Type - Koha Patron Message Transport Type
29
object class
29
object class
30
30
31
=head1 API
31
=head1 API
(-)a/Koha/Patron/Message/Transport/Types.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transport::Types;
1
package Koha::Patron::MessagePreference::Transport::Types;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 20-32 package Koha::Patron::Message::Transport::Types; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Transport::Type;
23
use Koha::Patron::MessagePreference::Transport::Type;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Koha::Patron::Message::Transport::Types - Koha Patron Message Transport Types
29
Koha::Patron::MessagePreference::Transport::Types - Koha Patron Message Transport Types
30
object class
30
object class
31
31
32
=head1 API
32
=head1 API
Lines 50-56 sub _type { Link Here
50
=cut
50
=cut
51
51
52
sub object_class {
52
sub object_class {
53
    return 'Koha::Patron::Message::Transport::Type';
53
    return 'Koha::Patron::MessagePreference::Transport::Type';
54
}
54
}
55
55
56
=head1 AUTHOR
56
=head1 AUTHOR
(-)a/Koha/Patron/Message/Transports.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Transports;
1
package Koha::Patron::MessagePreference::Transports;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 20-32 package Koha::Patron::Message::Transports; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Transport;
23
use Koha::Patron::MessagePreference::Transport;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Koha::Patron::Message::Transports - Koha Patron Message Transports object class
29
Koha::Patron::MessagePreference::Transports - Koha Patron Message Transports object class
30
30
31
=head1 API
31
=head1 API
32
32
Lines 49-55 sub _type { Link Here
49
=cut
49
=cut
50
50
51
sub object_class {
51
sub object_class {
52
    return 'Koha::Patron::Message::Transport';
52
    return 'Koha::Patron::MessagePreference::Transport';
53
}
53
}
54
54
55
=head1 AUTHOR
55
=head1 AUTHOR
(-)a/Koha/Patron/Message/Preferences.pm (-13 / +13 lines)
Lines 1-4 Link Here
1
package Koha::Patron::Message::Preferences;
1
package Koha::Patron::MessagePreferences;
2
2
3
# Copyright Koha-Suomi Oy 2016
3
# Copyright Koha-Suomi Oy 2016
4
#
4
#
Lines 20-34 package Koha::Patron::Message::Preferences; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Attributes;
23
use Koha::Patron::MessagePreference::Attributes;
24
use Koha::Patron::Message::Preference;
24
use Koha::Patron::MessagePreference;
25
use Koha::Patron::Message::Transports;
25
use Koha::Patron::MessagePreference::Transports;
26
26
27
use base qw(Koha::Objects);
27
use base qw(Koha::Objects);
28
28
29
=head1 NAME
29
=head1 NAME
30
30
31
Koha::Patron::Message::Preferences - Koha Patron Message Preferences object class
31
Koha::Patron::MessagePreferences - Koha Patron Message Preferences object class
32
32
33
=head1 API
33
=head1 API
34
34
Lines 38-44 Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas Link Here
38
38
39
=head3 find_with_message_name
39
=head3 find_with_message_name
40
40
41
Koha::Patron::Message::Preferences->find_with_message_name({
41
Koha::Patron::MessagePreferences->find_with_message_name({
42
    borrowernumber => 123,
42
    borrowernumber => 123,
43
    message_name => 'Hold_Filled',
43
    message_name => 'Hold_Filled',
44
});
44
});
Lines 51-57 sub find_with_message_name { Link Here
51
    my ($self, $id) = @_;
51
    my ($self, $id) = @_;
52
52
53
    if (ref($id) eq "HASH" && $id->{'message_name'}) {
53
    if (ref($id) eq "HASH" && $id->{'message_name'}) {
54
        my $attr = Koha::Patron::Message::Attributes->find({
54
        my $attr = Koha::Patron::MessagePreference::Attributes->find({
55
            message_name => $id->{'message_name'},
55
            message_name => $id->{'message_name'},
56
        });
56
        });
57
        $id->{'message_attribute_id'} = ($attr) ?
57
        $id->{'message_attribute_id'} = ($attr) ?
Lines 64-70 sub find_with_message_name { Link Here
64
64
65
=head3 get_options
65
=head3 get_options
66
66
67
my $messaging_options = Koha::Patron::Message::Preferences->get_options
67
my $messaging_options = Koha::Patron::MessagePreferences->get_options
68
68
69
Returns an ARRAYref of HASHrefs on available messaging options.
69
Returns an ARRAYref of HASHrefs on available messaging options.
70
70
Lines 73-79 Returns an ARRAYref of HASHrefs on available messaging options. Link Here
73
sub get_options {
73
sub get_options {
74
    my ($self) = @_;
74
    my ($self) = @_;
75
75
76
    my $transports = Koha::Patron::Message::Transports->search(undef,
76
    my $transports = Koha::Patron::MessagePreference::Transports->search(undef,
77
        {
77
        {
78
            join => ['message_attribute'],
78
            join => ['message_attribute'],
79
            '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'],
79
            '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'],
Lines 99-111 sub get_options { Link Here
99
99
100
=head3 search_with_message_name
100
=head3 search_with_message_name
101
101
102
Koha::Patron::Message::Preferences->search_with_message_name({
102
Koha::Patron::MessagePreferences->search_with_message_name({
103
    borrowernumber => 123,
103
    borrowernumber => 123,
104
    message_name => 'Hold_Filled',
104
    message_name => 'Hold_Filled',
105
});
105
});
106
106
107
Converts C<message_name> into C<message_attribute_id> and continues search. Use
107
Converts C<message_name> into C<message_attribute_id> and continues search. Use
108
Koha::Patron::Message::Preferences->search with a proper join for more complicated
108
Koha::Patron::MessagePreferences->search with a proper join for more complicated
109
searches.
109
searches.
110
110
111
=cut
111
=cut
Lines 114-120 sub search_with_message_name { Link Here
114
    my ($self, $params, $attributes) = @_;
114
    my ($self, $params, $attributes) = @_;
115
115
116
    if (ref($params) eq "HASH" && $params->{'message_name'}) {
116
    if (ref($params) eq "HASH" && $params->{'message_name'}) {
117
        my $attr = Koha::Patron::Message::Attributes->find({
117
        my $attr = Koha::Patron::MessagePreference::Attributes->find({
118
            message_name => $params->{'message_name'},
118
            message_name => $params->{'message_name'},
119
        });
119
        });
120
        $params->{'message_attribute_id'} = ($attr) ?
120
        $params->{'message_attribute_id'} = ($attr) ?
Lines 138-144 sub _type { Link Here
138
=cut
138
=cut
139
139
140
sub object_class {
140
sub object_class {
141
    return 'Koha::Patron::Message::Preference';
141
    return 'Koha::Patron::MessagePreference';
142
}
142
}
143
143
144
=head1 AUTHOR
144
=head1 AUTHOR
(-)a/Koha/Schema/Result/BorrowerMessagePreference.pm (-2 / +2 lines)
Lines 196-205 __PACKAGE__->many_to_many( Link Here
196
# You can replace this text with custom content, and it will be preserved on regeneration
196
# You can replace this text with custom content, and it will be preserved on regeneration
197
197
198
sub koha_object_class {
198
sub koha_object_class {
199
  'Koha::Patron::Message::Preference';
199
  'Koha::Patron::MessagePreference';
200
}
200
}
201
sub koha_objects_class {
201
sub koha_objects_class {
202
  'Koha::Patron::Message::Preferences';
202
  'Koha::Patron::MessagePreferences';
203
}
203
}
204
204
205
1;
205
1;
(-)a/Koha/Schema/Result/BorrowerMessageTransportPreference.pm (-2 / +2 lines)
Lines 114-123 __PACKAGE__->belongs_to( Link Here
114
# You can replace this text with custom content, and it will be preserved on regeneration
114
# You can replace this text with custom content, and it will be preserved on regeneration
115
115
116
sub koha_object_class {
116
sub koha_object_class {
117
  'Koha::Patron::Message::Transport::Preference';
117
  'Koha::Patron::MessagePreference::Transport::Preference';
118
}
118
}
119
sub koha_objects_class {
119
sub koha_objects_class {
120
  'Koha::Patron::Message::Transport::Preferences';
120
  'Koha::Patron::MessagePreference::Transport::Preferences';
121
}
121
}
122
122
123
1;
123
1;
(-)a/Koha/Schema/Result/MessageAttribute.pm (-2 / +2 lines)
Lines 119-128 __PACKAGE__->has_many( Link Here
119
# You can replace this text with custom content, and it will be preserved on regeneration
119
# You can replace this text with custom content, and it will be preserved on regeneration
120
120
121
sub koha_object_class {
121
sub koha_object_class {
122
  'Koha::Patron::Message::Attribute';
122
  'Koha::Patron::MessagePreference::Attribute';
123
}
123
}
124
sub koha_objects_class {
124
sub koha_objects_class {
125
  'Koha::Patron::Message::Attributes';
125
  'Koha::Patron::MessagePreference::Attributes';
126
}
126
}
127
127
128
1;
128
1;
(-)a/Koha/Schema/Result/MessageTransport.pm (-2 / +2 lines)
Lines 136-145 __PACKAGE__->belongs_to( Link Here
136
# You can replace this text with custom content, and it will be preserved on regeneration
136
# You can replace this text with custom content, and it will be preserved on regeneration
137
137
138
sub koha_object_class {
138
sub koha_object_class {
139
  'Koha::Patron::Message::Transport';
139
  'Koha::Patron::MessagePreference::Transport';
140
}
140
}
141
sub koha_objects_class {
141
sub koha_objects_class {
142
  'Koha::Patron::Message::Transports';
142
  'Koha::Patron::MessagePreference::Transports';
143
}
143
}
144
144
145
1;
145
1;
(-)a/Koha/Schema/Result/MessageTransportType.pm (-2 / +2 lines)
Lines 157-166 __PACKAGE__->many_to_many( Link Here
157
# You can replace this text with custom content, and it will be preserved on regeneration
157
# You can replace this text with custom content, and it will be preserved on regeneration
158
158
159
sub koha_object_class {
159
sub koha_object_class {
160
  'Koha::Patron::Message::Transport::Type';
160
  'Koha::Patron::MessagePreference::Transport::Type';
161
}
161
}
162
sub koha_objects_class {
162
sub koha_objects_class {
163
  'Koha::Patron::Message::Transport::Types';
163
  'Koha::Patron::MessagePreference::Transport::Types';
164
}
164
}
165
165
166
1;
166
1;
(-)a/t/db_dependent/Koha/Patron/Message/Attributes.t (-9 / +9 lines)
Lines 28-53 my $schema = Koha::Database->new->schema; Link Here
28
subtest 'Test class imports' => sub {
28
subtest 'Test class imports' => sub {
29
    plan tests => 2;
29
    plan tests => 2;
30
30
31
    use_ok('Koha::Patron::Message::Attribute');
31
    use_ok('Koha::Patron::MessagePreference::Attribute');
32
    use_ok('Koha::Patron::Message::Attributes');
32
    use_ok('Koha::Patron::MessagePreference::Attributes');
33
};
33
};
34
34
35
subtest 'Test Koha::Patron::Message::Attributes' => sub {
35
subtest 'Test Koha::Patron::MessagePreference::Attributes' => sub {
36
    plan tests => 6;
36
    plan tests => 6;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
40
    Koha::Patron::Message::Attribute->new({
40
    Koha::Patron::MessagePreference::Attribute->new({
41
        message_name => 'Test_Attribute'
41
        message_name => 'Test_Attribute'
42
    })->store;
42
    })->store;
43
    Koha::Patron::Message::Attribute->new({
43
    Koha::Patron::MessagePreference::Attribute->new({
44
        message_name => 'Test_Attribute2',
44
        message_name => 'Test_Attribute2',
45
        takes_days   => 1
45
        takes_days   => 1
46
    })->store;
46
    })->store;
47
47
48
    my $attribute  = Koha::Patron::Message::Attributes->find({
48
    my $attribute  = Koha::Patron::MessagePreference::Attributes->find({
49
        message_name => 'Test_Attribute' });
49
        message_name => 'Test_Attribute' });
50
    my $attribute2 = Koha::Patron::Message::Attributes->find({
50
    my $attribute2 = Koha::Patron::MessagePreference::Attributes->find({
51
        message_name => 'Test_Attribute2' });
51
        message_name => 'Test_Attribute2' });
52
52
53
    is($attribute->message_name, 'Test_Attribute',
53
    is($attribute->message_name, 'Test_Attribute',
Lines 61-70 subtest 'Test Koha::Patron::Message::Attributes' => sub { Link Here
61
61
62
    $attribute->delete;
62
    $attribute->delete;
63
    $attribute2->delete;
63
    $attribute2->delete;
64
    is(Koha::Patron::Message::Attributes->find({
64
    is(Koha::Patron::MessagePreference::Attributes->find({
65
        message_name => 'Test_Attribute' }), undef,
65
        message_name => 'Test_Attribute' }), undef,
66
       'Deleted the first message attribute.');
66
       'Deleted the first message attribute.');
67
    is(Koha::Patron::Message::Attributes->find({
67
    is(Koha::Patron::MessagePreference::Attributes->find({
68
        message_name => 'Test_Attribute2' }), undef,
68
        message_name => 'Test_Attribute2' }), undef,
69
       'Deleted the second message attribute.');
69
       'Deleted the second message attribute.');
70
70
(-)a/t/db_dependent/Koha/Patron/Message/Transport/Preferences.t (-18 / +18 lines)
Lines 26-35 use t::lib::TestBuilder; Link Here
26
26
27
use Koha::Notice::Templates;
27
use Koha::Notice::Templates;
28
use Koha::Patron::Categories;
28
use Koha::Patron::Categories;
29
use Koha::Patron::Message::Attributes;
29
use Koha::Patron::MessagePreference::Attributes;
30
use Koha::Patron::Message::Preferences;
30
use Koha::Patron::MessagePreferences;
31
use Koha::Patron::Message::Transport::Types;
31
use Koha::Patron::MessagePreference::Transport::Types;
32
use Koha::Patron::Message::Transports;
32
use Koha::Patron::MessagePreference::Transports;
33
use Koha::Patrons;
33
use Koha::Patrons;
34
34
35
my $schema  = Koha::Database->new->schema;
35
my $schema  = Koha::Database->new->schema;
Lines 38-58 my $builder = t::lib::TestBuilder->new; Link Here
38
subtest 'Test class imports' => sub {
38
subtest 'Test class imports' => sub {
39
    plan tests => 2;
39
    plan tests => 2;
40
40
41
    use_ok('Koha::Patron::Message::Transport::Preference');
41
    use_ok('Koha::Patron::MessagePreference::Transport::Preference');
42
    use_ok('Koha::Patron::Message::Transport::Preferences');
42
    use_ok('Koha::Patron::MessagePreference::Transport::Preferences');
43
};
43
};
44
44
45
subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
45
subtest 'Test Koha::Patron::MessagePreference::Transport::Preferences' => sub {
46
    plan tests => 2;
46
    plan tests => 2;
47
47
48
    $schema->storage->txn_begin;
48
    $schema->storage->txn_begin;
49
49
50
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
50
    my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
51
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
51
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
52
    my $letter    = build_a_test_letter({
52
    my $letter    = build_a_test_letter({
53
        mtt => $mtt->message_transport_type
53
        mtt => $mtt->message_transport_type
54
    });
54
    });
55
    Koha::Patron::Message::Transport->new({
55
    Koha::Patron::MessagePreference::Transport->new({
56
        message_attribute_id   => $attribute->message_attribute_id,
56
        message_attribute_id   => $attribute->message_attribute_id,
57
        message_transport_type => $mtt->message_transport_type,
57
        message_transport_type => $mtt->message_transport_type,
58
        is_digest              => 0,
58
        is_digest              => 0,
Lines 62-68 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
62
62
63
    subtest 'For a patron' => sub {
63
    subtest 'For a patron' => sub {
64
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
64
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
65
        my $preference = Koha::Patron::Message::Preference->new({
65
        my $preference = Koha::Patron::MessagePreference->new({
66
            borrowernumber       => $patron->borrowernumber,
66
            borrowernumber       => $patron->borrowernumber,
67
            message_attribute_id => $attribute->message_attribute_id,
67
            message_attribute_id => $attribute->message_attribute_id,
68
            wants_digest         => 0,
68
            wants_digest         => 0,
Lines 70-84 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
70
        })->store;
70
        })->store;
71
71
72
        my $pref_id = $preference->borrower_message_preference_id;
72
        my $pref_id = $preference->borrower_message_preference_id;
73
        my $transport_pref = Koha::Patron::Message::Transport::Preference->new({
73
        my $transport_pref = Koha::Patron::MessagePreference::Transport::Preference->new({
74
            borrower_message_preference_id => $pref_id,
74
            borrower_message_preference_id => $pref_id,
75
            message_transport_type => $mtt->message_transport_type,
75
            message_transport_type => $mtt->message_transport_type,
76
        })->store;
76
        })->store;
77
        is(ref($transport_pref), 'Koha::Patron::Message::Transport::Preference',
77
        is(ref($transport_pref), 'Koha::Patron::MessagePreference::Transport::Preference',
78
           'Added a new messaging transport preference for patron.');
78
           'Added a new messaging transport preference for patron.');
79
79
80
        $transport_pref->delete;
80
        $transport_pref->delete;
81
        is(Koha::Patron::Message::Transport::Preferences->search({
81
        is(Koha::Patron::MessagePreference::Transport::Preferences->search({
82
            borrower_message_preference_id => $pref_id,
82
            borrower_message_preference_id => $pref_id,
83
            message_transport_type => $mtt->message_transport_type,
83
            message_transport_type => $mtt->message_transport_type,
84
        })->count, 0, 'Deleted the messaging transport preference.');
84
        })->count, 0, 'Deleted the messaging transport preference.');
Lines 86-92 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
86
86
87
    subtest 'For a category' => sub {
87
    subtest 'For a category' => sub {
88
        my $category   = $builder->build_object({ class => 'Koha::Patron::Categories' });
88
        my $category   = $builder->build_object({ class => 'Koha::Patron::Categories' });
89
        my $preference = Koha::Patron::Message::Preference->new({
89
        my $preference = Koha::Patron::MessagePreference->new({
90
            categorycode         => $category->categorycode,
90
            categorycode         => $category->categorycode,
91
            message_attribute_id => $attribute->message_attribute_id,
91
            message_attribute_id => $attribute->message_attribute_id,
92
            wants_digest         => 0,
92
            wants_digest         => 0,
Lines 94-108 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
94
        })->store;
94
        })->store;
95
95
96
        my $pref_id = $preference->borrower_message_preference_id;
96
        my $pref_id = $preference->borrower_message_preference_id;
97
        my $transport_pref = Koha::Patron::Message::Transport::Preference->new({
97
        my $transport_pref = Koha::Patron::MessagePreference::Transport::Preference->new({
98
            borrower_message_preference_id => $pref_id,
98
            borrower_message_preference_id => $pref_id,
99
            message_transport_type => $mtt->message_transport_type,
99
            message_transport_type => $mtt->message_transport_type,
100
        })->store;
100
        })->store;
101
        is(ref($transport_pref), 'Koha::Patron::Message::Transport::Preference',
101
        is(ref($transport_pref), 'Koha::Patron::MessagePreference::Transport::Preference',
102
           'Added a new messaging transport preference for category.');
102
           'Added a new messaging transport preference for category.');
103
103
104
        $transport_pref->delete;
104
        $transport_pref->delete;
105
        is(Koha::Patron::Message::Transport::Preferences->search({
105
        is(Koha::Patron::MessagePreference::Transport::Preferences->search({
106
            borrower_message_preference_id => $pref_id,
106
            borrower_message_preference_id => $pref_id,
107
            message_transport_type => $mtt->message_transport_type,
107
            message_transport_type => $mtt->message_transport_type,
108
        })->count, 0, 'Deleted the messaging transport preference.');
108
        })->count, 0, 'Deleted the messaging transport preference.');
(-)a/t/db_dependent/Koha/Patron/Message/Transport/Types.t (-5 / +5 lines)
Lines 28-43 my $schema = Koha::Database->new->schema; Link Here
28
subtest 'Test class imports' => sub {
28
subtest 'Test class imports' => sub {
29
    plan tests => 2;
29
    plan tests => 2;
30
30
31
    use_ok('Koha::Patron::Message::Transport::Type');
31
    use_ok('Koha::Patron::MessagePreference::Transport::Type');
32
    use_ok('Koha::Patron::Message::Transport::Types');
32
    use_ok('Koha::Patron::MessagePreference::Transport::Types');
33
};
33
};
34
34
35
subtest 'Test Koha::Patron::Message::Transport::Types' => sub {
35
subtest 'Test Koha::Patron::MessagePreference::Transport::Types' => sub {
36
    plan tests => 2;
36
    plan tests => 2;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
40
    my $transport_type = Koha::Patron::Message::Transport::Type->new({
40
    my $transport_type = Koha::Patron::MessagePreference::Transport::Type->new({
41
        message_transport_type => 'test'
41
        message_transport_type => 'test'
42
    })->store;
42
    })->store;
43
43
Lines 45-51 subtest 'Test Koha::Patron::Message::Transport::Types' => sub { Link Here
45
       'Added a new message transport type.');
45
       'Added a new message transport type.');
46
46
47
    $transport_type->delete;
47
    $transport_type->delete;
48
    is(Koha::Patron::Message::Transport::Types->find('test'), undef,
48
    is(Koha::Patron::MessagePreference::Transport::Types->find('test'), undef,
49
       'Deleted the message transport type.');
49
       'Deleted the message transport type.');
50
50
51
    $schema->storage->txn_rollback;
51
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Patron/Message/Transports.t (-9 / +9 lines)
Lines 24-31 use Test::More tests => 2; Link Here
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use Koha::Notice::Templates;
26
use Koha::Notice::Templates;
27
use Koha::Patron::Message::Attributes;
27
use Koha::Patron::MessagePreference::Attributes;
28
use Koha::Patron::Message::Transport::Types;
28
use Koha::Patron::MessagePreference::Transport::Types;
29
29
30
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
Lines 33-54 my $builder = t::lib::TestBuilder->new; Link Here
33
subtest 'Test class imports' => sub {
33
subtest 'Test class imports' => sub {
34
    plan tests => 2;
34
    plan tests => 2;
35
35
36
    use_ok('Koha::Patron::Message::Transport');
36
    use_ok('Koha::Patron::MessagePreference::Transport');
37
    use_ok('Koha::Patron::Message::Transports');
37
    use_ok('Koha::Patron::MessagePreference::Transports');
38
};
38
};
39
39
40
subtest 'Test Koha::Patron::Message::Transports' => sub {
40
subtest 'Test Koha::Patron::MessagePreference::Transports' => sub {
41
    plan tests => 2;
41
    plan tests => 2;
42
42
43
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
44
44
45
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
45
    my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
46
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
46
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
47
    my $letter    = build_a_test_letter({
47
    my $letter    = build_a_test_letter({
48
        mtt => $mtt->message_transport_type
48
        mtt => $mtt->message_transport_type
49
    });
49
    });
50
50
51
    my $transport = Koha::Patron::Message::Transport->new({
51
    my $transport = Koha::Patron::MessagePreference::Transport->new({
52
        message_attribute_id   => $attribute->message_attribute_id,
52
        message_attribute_id   => $attribute->message_attribute_id,
53
        message_transport_type => $mtt->message_transport_type,
53
        message_transport_type => $mtt->message_transport_type,
54
        is_digest              => 0,
54
        is_digest              => 0,
Lines 60-66 subtest 'Test Koha::Patron::Message::Transports' => sub { Link Here
60
       'Added a new messaging transport.');
60
       'Added a new messaging transport.');
61
61
62
    $transport->delete;
62
    $transport->delete;
63
    is(Koha::Patron::Message::Transports->search({
63
    is(Koha::Patron::MessagePreference::Transports->search({
64
        message_attribute_id => $attribute->message_attribute_id,
64
        message_attribute_id => $attribute->message_attribute_id,
65
        message_transport_type => $mtt->message_transport_type,
65
        message_transport_type => $mtt->message_transport_type,
66
        is_digest => 0
66
        is_digest => 0
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-121 / +120 lines)
Lines 28-36 use C4::Context; Link Here
28
28
29
use Koha::Notice::Templates;
29
use Koha::Notice::Templates;
30
use Koha::Patron::Categories;
30
use Koha::Patron::Categories;
31
use Koha::Patron::Message::Attributes;
31
use Koha::Patron::MessagePreference::Attributes;
32
use Koha::Patron::Message::Transport::Types;
32
use Koha::Patron::MessagePreference::Transport::Types;
33
use Koha::Patron::Message::Transports;
33
use Koha::Patron::MessagePreference::Transports;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
35
36
use File::Temp qw/tempfile/;
36
use File::Temp qw/tempfile/;
Lines 42-60 my $builder = t::lib::TestBuilder->new; Link Here
42
subtest 'Test class imports' => sub {
42
subtest 'Test class imports' => sub {
43
    plan tests => 2;
43
    plan tests => 2;
44
44
45
    use_ok('Koha::Patron::Message::Preference');
45
    use_ok('Koha::Patron::MessagePreference');
46
    use_ok('Koha::Patron::Message::Preferences');
46
    use_ok('Koha::Patron::MessagePreferences');
47
};
47
};
48
48
49
subtest 'Test Koha::Patron::Message::Preferences' => sub {
49
subtest 'Test Koha::Patron::MessagePreferences' => sub {
50
    plan tests => 2;
50
    plan tests => 2;
51
51
52
    $schema->storage->txn_begin;
52
    $schema->storage->txn_begin;
53
53
54
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
54
    my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
55
    my $letter = build_a_test_letter();
55
    my $letter = build_a_test_letter();
56
    my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
56
    my $mtt = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
57
    Koha::Patron::Message::Transport->new({
57
    Koha::Patron::MessagePreference::Transport->new({
58
        message_attribute_id   => $attribute->message_attribute_id,
58
        message_attribute_id   => $attribute->message_attribute_id,
59
        message_transport_type => $mtt->message_transport_type,
59
        message_transport_type => $mtt->message_transport_type,
60
        is_digest              => 0,
60
        is_digest              => 0,
Lines 66-79 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
66
        plan tests => 3;
66
        plan tests => 3;
67
67
68
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
68
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
69
        Koha::Patron::Message::Preference->new({
69
        Koha::Patron::MessagePreference->new({
70
            borrowernumber       => $patron->borrowernumber,
70
            borrowernumber       => $patron->borrowernumber,
71
            message_attribute_id => $attribute->message_attribute_id,
71
            message_attribute_id => $attribute->message_attribute_id,
72
            wants_digest         => 0,
72
            wants_digest         => 0,
73
            days_in_advance      => undef,
73
            days_in_advance      => undef,
74
        })->store;
74
        })->store;
75
75
76
        my $preference = Koha::Patron::Message::Preferences->find({
76
        my $preference = Koha::Patron::MessagePreferences->find({
77
            borrowernumber       => $patron->borrowernumber,
77
            borrowernumber       => $patron->borrowernumber,
78
            message_attribute_id => $attribute->message_attribute_id
78
            message_attribute_id => $attribute->message_attribute_id
79
        });
79
        });
Lines 83-98 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
83
        subtest 'Test set not throwing an exception on duplicate object' => sub {
83
        subtest 'Test set not throwing an exception on duplicate object' => sub {
84
            plan tests => 1;
84
            plan tests => 1;
85
85
86
            Koha::Patron::Message::Attributes->find({
86
            Koha::Patron::MessagePreference::Attributes->find({
87
                message_attribute_id => $attribute->message_attribute_id
87
                message_attribute_id => $attribute->message_attribute_id
88
            })->set({ takes_days => 1 })->store;
88
            })->set({ takes_days => 1 })->store;
89
            $preference->set({ days_in_advance => 1 })->store;
89
            $preference->set({ days_in_advance => 1 })->store;
90
            is(ref($preference), 'Koha::Patron::Message::Preference',
90
            is(ref($preference), 'Koha::Patron::MessagePreference',
91
             'Updating the preference does not cause duplicate object exception');
91
             'Updating the preference does not cause duplicate object exception');
92
        };
92
        };
93
93
94
        $preference->delete;
94
        $preference->delete;
95
        is(Koha::Patron::Message::Preferences->search({
95
        is(Koha::Patron::MessagePreferences->search({
96
            borrowernumber       => $patron->borrowernumber,
96
            borrowernumber       => $patron->borrowernumber,
97
            message_attribute_id => $attribute->message_attribute_id
97
            message_attribute_id => $attribute->message_attribute_id
98
        })->count, 0, 'Deleted the messaging preference.');
98
        })->count, 0, 'Deleted the messaging preference.');
Lines 100-113 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
100
100
101
    subtest 'Test for a category' => sub {
101
    subtest 'Test for a category' => sub {
102
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
102
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
103
        Koha::Patron::Message::Preference->new({
103
        Koha::Patron::MessagePreference->new({
104
            categorycode         => $category->categorycode,
104
            categorycode         => $category->categorycode,
105
            message_attribute_id => $attribute->message_attribute_id,
105
            message_attribute_id => $attribute->message_attribute_id,
106
            wants_digest         => 0,
106
            wants_digest         => 0,
107
            days_in_advance      => undef,
107
            days_in_advance      => undef,
108
        })->store;
108
        })->store;
109
109
110
        my $preference = Koha::Patron::Message::Preferences->find({
110
        my $preference = Koha::Patron::MessagePreferences->find({
111
            categorycode         => $category->categorycode,
111
            categorycode         => $category->categorycode,
112
            message_attribute_id => $attribute->message_attribute_id
112
            message_attribute_id => $attribute->message_attribute_id
113
        });
113
        });
Lines 115-121 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
115
           'Added a new messaging preference for category.');
115
           'Added a new messaging preference for category.');
116
116
117
        $preference->delete;
117
        $preference->delete;
118
        is(Koha::Patron::Message::Preferences->search({
118
        is(Koha::Patron::MessagePreferences->search({
119
            categorycode         => $category->categorycode,
119
            categorycode         => $category->categorycode,
120
            message_attribute_id => $attribute->message_attribute_id
120
            message_attribute_id => $attribute->message_attribute_id
121
        })->count, 0, 'Deleted the messaging preference.');
121
        })->count, 0, 'Deleted the messaging preference.');
Lines 124-154 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
124
    $schema->storage->txn_rollback;
124
    $schema->storage->txn_rollback;
125
};
125
};
126
126
127
subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub {
127
subtest 'Test Koha::Patron::MessagePreferences->get_options' => sub {
128
    plan tests => 2;
128
    plan tests => 2;
129
129
130
    subtest 'Test method availability and return value' => sub {
130
    subtest 'Test method availability and return value' => sub {
131
        plan tests => 3;
131
        plan tests => 3;
132
132
133
        ok(Koha::Patron::Message::Preferences->can('get_options'),
133
        ok(Koha::Patron::MessagePreferences->can('get_options'),
134
            'Method get_options is available.');
134
            'Method get_options is available.');
135
        ok(my $options = Koha::Patron::Message::Preferences->get_options,
135
        ok(my $options = Koha::Patron::MessagePreferences->get_options,
136
            'Called get_options successfully.');
136
            'Called get_options successfully.');
137
        is(ref($options), 'ARRAY', 'get_options returns a ARRAYref');
137
        is(ref($options), 'ARRAY', 'get_options returns a ARRAYref');
138
    };
138
    };
139
139
140
    subtest 'Make sure options are correct' => sub {
140
    subtest 'Make sure options are correct' => sub {
141
        $schema->storage->txn_begin;
141
        $schema->storage->txn_begin;
142
        my $options = Koha::Patron::Message::Preferences->get_options;
142
        my $options = Koha::Patron::MessagePreferences->get_options;
143
143
144
        foreach my $option (@$options) {
144
        foreach my $option (@$options) {
145
            my $n = $option->{'message_name'};
145
            my $n = $option->{'message_name'};
146
            my $attr = Koha::Patron::Message::Attributes->find($option->{'message_attribute_id'});
146
            my $attr = Koha::Patron::MessagePreference::Attributes->find($option->{'message_attribute_id'});
147
            is($option->{'message_attribute_id'}, $attr->message_attribute_id,
147
            is($option->{'message_attribute_id'}, $attr->message_attribute_id,
148
               '$n: message_attribute_id is set');
148
               '$n: message_attribute_id is set');
149
            is($option->{'message_name'}, $attr->message_name, '$n: message_name is set');
149
            is($option->{'message_name'}, $attr->message_name, '$n: message_name is set');
150
            is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set');
150
            is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set');
151
            my $transports = Koha::Patron::Message::Transports->search({
151
            my $transports = Koha::Patron::MessagePreference::Transports->search({
152
                message_attribute_id => $option->{'message_attribute_id'},
152
                message_attribute_id => $option->{'message_attribute_id'},
153
                is_digest => $option->{'has_digest'} || 0,
153
                is_digest => $option->{'has_digest'} || 0,
154
            });
154
            });
Lines 171-196 subtest 'Add preferences from defaults' => sub { Link Here
171
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
171
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
172
        patron => $patron,
172
        patron => $patron,
173
    });
173
    });
174
    ok(Koha::Patron::Message::Preference->new_from_default({
174
    ok(Koha::Patron::MessagePreference->new_from_default({
175
        borrowernumber       => $patron->borrowernumber,
175
        borrowernumber       => $patron->borrowernumber,
176
        categorycode         => $patron->categorycode,
176
        categorycode         => $patron->categorycode,
177
        message_attribute_id => $default->message_attribute_id,
177
        message_attribute_id => $default->message_attribute_id,
178
    })->store, 'Added a default preference to patron.');
178
    })->store, 'Added a default preference to patron.');
179
    ok(my $pref = Koha::Patron::Message::Preferences->find({
179
    ok(my $pref = Koha::Patron::MessagePreferences->find({
180
        borrowernumber       => $patron->borrowernumber,
180
        borrowernumber       => $patron->borrowernumber,
181
        message_attribute_id => $default->message_attribute_id,
181
        message_attribute_id => $default->message_attribute_id,
182
    }), 'Found the default preference from patron.');
182
    }), 'Found the default preference from patron.');
183
    is(Koha::Patron::Message::Transport::Preferences->search({
183
    is(Koha::Patron::MessagePreference::Transport::Preferences->search({
184
        borrower_message_preference_id => $pref->borrower_message_preference_id
184
        borrower_message_preference_id => $pref->borrower_message_preference_id
185
    })->count, 2, 'Found the two transport types that we set earlier');
185
    })->count, 2, 'Found the two transport types that we set earlier');
186
186
187
    $schema->storage->txn_rollback;
187
    $schema->storage->txn_rollback;
188
};
188
};
189
189
190
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub {
190
subtest 'Test Koha::Patron::MessagePreference->message_transport_types' => sub {
191
    plan tests => 4;
191
    plan tests => 4;
192
192
193
    ok(Koha::Patron::Message::Preference->can('message_transport_types'),
193
    ok(Koha::Patron::MessagePreference->can('message_transport_types'),
194
       'Method message_transport_types available');
194
       'Method message_transport_types available');
195
195
196
    subtest 'get message_transport_types' => sub {
196
    subtest 'get message_transport_types' => sub {
Lines 202-226 subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub Link Here
202
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
202
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
203
            patron => $patron
203
            patron => $patron
204
        });
204
        });
205
        Koha::Patron::Message::Transport::Preferences->search({
205
        Koha::Patron::MessagePreference::Transport::Preferences->search({
206
            borrower_message_preference_id => $preference->borrower_message_preference_id,
206
            borrower_message_preference_id => $preference->borrower_message_preference_id,
207
        })->delete;
207
        })->delete;
208
        Koha::Patron::Message::Transport::Preference->new({
208
        Koha::Patron::MessagePreference::Transport::Preference->new({
209
            borrower_message_preference_id => $preference->borrower_message_preference_id,
209
            borrower_message_preference_id => $preference->borrower_message_preference_id,
210
            message_transport_type => $mtt1->message_transport_type,
210
            message_transport_type => $mtt1->message_transport_type,
211
        })->store;
211
        })->store;
212
        Koha::Patron::Message::Transport::Preference->new({
212
        Koha::Patron::MessagePreference::Transport::Preference->new({
213
            borrower_message_preference_id => $preference->borrower_message_preference_id,
213
            borrower_message_preference_id => $preference->borrower_message_preference_id,
214
            message_transport_type => $mtt2->message_transport_type,
214
            message_transport_type => $mtt2->message_transport_type,
215
        })->store;
215
        })->store;
216
        my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({
216
        my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({
217
            borrower_message_preference_id => $preference->borrower_message_preference_id,
217
            borrower_message_preference_id => $preference->borrower_message_preference_id,
218
        });
218
        });
219
        my $transport1 = Koha::Patron::Message::Transports->find({
219
        my $transport1 = Koha::Patron::MessagePreference::Transports->find({
220
            message_attribute_id => $preference->message_attribute_id,
220
            message_attribute_id => $preference->message_attribute_id,
221
            message_transport_type => $mtt1->message_transport_type,
221
            message_transport_type => $mtt1->message_transport_type,
222
        });
222
        });
223
        my $transport2 = Koha::Patron::Message::Transports->find({
223
        my $transport2 = Koha::Patron::MessagePreference::Transports->find({
224
            message_attribute_id => $preference->message_attribute_id,
224
            message_attribute_id => $preference->message_attribute_id,
225
            message_transport_type => $mtt2->message_transport_type,
225
            message_transport_type => $mtt2->message_transport_type,
226
        });
226
        });
Lines 255-273 HERE Link Here
255
            my $appenders = Log::Log4perl->appenders;
255
            my $appenders = Log::Log4perl->appenders;
256
            my $appender = Log::Log4perl->appenders->{OPAC};
256
            my $appender = Log::Log4perl->appenders->{OPAC};
257
257
258
            my $pref = Koha::Patron::Message::Preferences->find(
258
            my $pref = Koha::Patron::MessagePreferences->find(
259
                $preference->borrower_message_preference_id
259
                $preference->borrower_message_preference_id
260
            );
260
            );
261
            my $transports = $pref->message_transport_types;
261
            my $transports = $pref->message_transport_types;
262
            is($appender, undef, 'Nothing in buffer yet');
262
            is($appender, undef, 'Nothing in buffer yet');
263
263
264
            my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
264
            my $mtt_new = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
265
            Koha::Patron::Message::Transport::Preference->new({
265
            Koha::Patron::MessagePreference::Transport::Preference->new({
266
                borrower_message_preference_id =>
266
                borrower_message_preference_id =>
267
                                $pref->borrower_message_preference_id,
267
                                $pref->borrower_message_preference_id,
268
                message_transport_type => $mtt_new->message_transport_type,
268
                message_transport_type => $mtt_new->message_transport_type,
269
            })->store;
269
            })->store;
270
            $pref = Koha::Patron::Message::Preferences->find(
270
            $pref = Koha::Patron::MessagePreferences->find(
271
                $pref->borrower_message_preference_id
271
                $pref->borrower_message_preference_id
272
            );
272
            );
273
            $transports = $pref->message_transport_types;
273
            $transports = $pref->message_transport_types;
Lines 294-305 HERE Link Here
294
        my $mtt1_str = $mtt1->message_transport_type;
294
        my $mtt1_str = $mtt1->message_transport_type;
295
        my $mtt2_str = $mtt2->message_transport_type;
295
        my $mtt2_str = $mtt2->message_transport_type;
296
        # 1/3, use message_transport_types(list)
296
        # 1/3, use message_transport_types(list)
297
        Koha::Patron::Message::Transport::Preferences->search({
297
        Koha::Patron::MessagePreference::Transport::Preferences->search({
298
            borrower_message_preference_id => $preference->borrower_message_preference_id,
298
            borrower_message_preference_id => $preference->borrower_message_preference_id,
299
        })->delete;
299
        })->delete;
300
        ok($preference->message_transport_types($mtt1_str, $mtt2_str)->store,
300
        ok($preference->message_transport_types($mtt1_str, $mtt2_str)->store,
301
           '1/3 Set returned true.');
301
           '1/3 Set returned true.');
302
        my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({
302
        my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({
303
            borrower_message_preference_id => $preference->borrower_message_preference_id,
303
            borrower_message_preference_id => $preference->borrower_message_preference_id,
304
            '-or' => [
304
            '-or' => [
305
                message_transport_type => $mtt1_str,
305
                message_transport_type => $mtt1_str,
Lines 309-320 HERE Link Here
309
        is($stored_transports->count, 2, 'Two transports selected');
309
        is($stored_transports->count, 2, 'Two transports selected');
310
310
311
        # 2/3, use message_transport_types(ARRAYREF)
311
        # 2/3, use message_transport_types(ARRAYREF)
312
        Koha::Patron::Message::Transport::Preferences->search({
312
        Koha::Patron::MessagePreference::Transport::Preferences->search({
313
            borrower_message_preference_id => $preference->borrower_message_preference_id,
313
            borrower_message_preference_id => $preference->borrower_message_preference_id,
314
        })->delete;
314
        })->delete;
315
        ok($preference->message_transport_types([$mtt1_str, $mtt2_str])->store,
315
        ok($preference->message_transport_types([$mtt1_str, $mtt2_str])->store,
316
           '2/3 Set returned true.');
316
           '2/3 Set returned true.');
317
        $stored_transports = Koha::Patron::Message::Transport::Preferences->search({
317
        $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({
318
            borrower_message_preference_id => $preference->borrower_message_preference_id,
318
            borrower_message_preference_id => $preference->borrower_message_preference_id,
319
            '-or' => [
319
            '-or' => [
320
                message_transport_type => $mtt1_str,
320
                message_transport_type => $mtt1_str,
Lines 324-336 HERE Link Here
324
        is($stored_transports->count, 2, 'Two transports selected');
324
        is($stored_transports->count, 2, 'Two transports selected');
325
325
326
        # 3/3, use set({ message_transport_types => ARRAYREF })
326
        # 3/3, use set({ message_transport_types => ARRAYREF })
327
        Koha::Patron::Message::Transport::Preferences->search({
327
        Koha::Patron::MessagePreference::Transport::Preferences->search({
328
            borrower_message_preference_id => $preference->borrower_message_preference_id,
328
            borrower_message_preference_id => $preference->borrower_message_preference_id,
329
        })->delete;
329
        })->delete;
330
        ok($preference->set({
330
        ok($preference->set({
331
            message_transport_types => [$mtt1_str, $mtt2_str]})->store,
331
            message_transport_types => [$mtt1_str, $mtt2_str]})->store,
332
           '3/3 Set returned true.');
332
           '3/3 Set returned true.');
333
        $stored_transports = Koha::Patron::Message::Transport::Preferences->search({
333
        $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({
334
            borrower_message_preference_id => $preference->borrower_message_preference_id,
334
            borrower_message_preference_id => $preference->borrower_message_preference_id,
335
            '-or' => [
335
            '-or' => [
336
                message_transport_type => $mtt1_str,
336
                message_transport_type => $mtt1_str,
Lines 340-373 HERE Link Here
340
        is($stored_transports->count, 2, 'Two transports selected');
340
        is($stored_transports->count, 2, 'Two transports selected');
341
341
342
        # Test contact information validation
342
        # Test contact information validation
343
        eval { Koha::Patron::Message::Transport::Types->new({
343
        eval { Koha::Patron::MessagePreference::Transport::Types->new({
344
                message_transport_type => 'email'
344
                message_transport_type => 'email'
345
            })->store };
345
            })->store };
346
        eval { Koha::Patron::Message::Transport::Types->new({
346
        eval { Koha::Patron::MessagePreference::Transport::Types->new({
347
                message_transport_type => 'itiva'
347
                message_transport_type => 'itiva'
348
            })->store };
348
            })->store };
349
        eval { Koha::Patron::Message::Transport::Types->new({
349
        eval { Koha::Patron::MessagePreference::Transport::Types->new({
350
                message_transport_type => 'phone'
350
                message_transport_type => 'phone'
351
            })->store };
351
            })->store };
352
        eval { Koha::Patron::Message::Transport::Types->new({
352
        eval { Koha::Patron::MessagePreference::Transport::Types->new({
353
                message_transport_type => 'sms'
353
                message_transport_type => 'sms'
354
            })->store };
354
            })->store };
355
        Koha::Patron::Message::Transport->new({
355
        Koha::Patron::MessagePreference::Transport->new({
356
            message_attribute_id   => $preference->message_attribute_id,
356
            message_attribute_id   => $preference->message_attribute_id,
357
            message_transport_type => 'email',
357
            message_transport_type => 'email',
358
            is_digest              => 1
358
            is_digest              => 1
359
        })->store;
359
        })->store;
360
        Koha::Patron::Message::Transport->new({
360
        Koha::Patron::MessagePreference::Transport->new({
361
            message_attribute_id   => $preference->message_attribute_id,
361
            message_attribute_id   => $preference->message_attribute_id,
362
            message_transport_type => 'itiva',
362
            message_transport_type => 'itiva',
363
            is_digest              => 1
363
            is_digest              => 1
364
        })->store;
364
        })->store;
365
        Koha::Patron::Message::Transport->new({
365
        Koha::Patron::MessagePreference::Transport->new({
366
            message_attribute_id   => $preference->message_attribute_id,
366
            message_attribute_id   => $preference->message_attribute_id,
367
            message_transport_type => 'phone',
367
            message_transport_type => 'phone',
368
            is_digest              => 1
368
            is_digest              => 1
369
        })->store;
369
        })->store;
370
        Koha::Patron::Message::Transport->new({
370
        Koha::Patron::MessagePreference::Transport->new({
371
            message_attribute_id   => $preference->message_attribute_id,
371
            message_attribute_id   => $preference->message_attribute_id,
372
            message_transport_type => 'sms',
372
            message_transport_type => 'sms',
373
            is_digest              => 1
373
            is_digest              => 1
Lines 377-385 HERE Link Here
377
        eval {
377
        eval {
378
            $preference->message_transport_types('email')->store;
378
            $preference->message_transport_types('email')->store;
379
        };
379
        };
380
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired',
380
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired',
381
            'Adding a message preference with invalid message_transport_type'
381
            'Adding a message preference with invalid message_transport_type'
382
            .' => Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired');
382
            .' => Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired');
383
        is ($@->message_name, $preference->message_name, 'The previous exception '
383
        is ($@->message_name, $preference->message_name, 'The previous exception '
384
            .' tells us it which message name it was.');
384
            .' tells us it which message name it was.');
385
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
385
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
Lines 387-395 HERE Link Here
387
        eval {
387
        eval {
388
            $preference->message_transport_types('itiva')->store;
388
            $preference->message_transport_types('itiva')->store;
389
        };
389
        };
390
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired',
390
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired',
391
            'Adding a message preference with invalid message_transport_type'
391
            'Adding a message preference with invalid message_transport_type'
392
            .' => Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired');
392
            .' => Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired');
393
        is ($@->message_name, $preference->message_name, 'The previous exception '
393
        is ($@->message_name, $preference->message_name, 'The previous exception '
394
            .' tells us it which message name it was.');
394
            .' tells us it which message name it was.');
395
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
395
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
Lines 397-405 HERE Link Here
397
        eval {
397
        eval {
398
            $preference->message_transport_types('phone')->store;
398
            $preference->message_transport_types('phone')->store;
399
        };
399
        };
400
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired',
400
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired',
401
            'Adding a message preference with invalid message_transport_type'
401
            'Adding a message preference with invalid message_transport_type'
402
            .' => Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired');
402
            .' => Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired');
403
        is ($@->message_name, $preference->message_name, 'The previous exception '
403
        is ($@->message_name, $preference->message_name, 'The previous exception '
404
            .' tells us it which message name it was.');
404
            .' tells us it which message name it was.');
405
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
405
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
Lines 407-415 HERE Link Here
407
        eval {
407
        eval {
408
            $preference->message_transport_types('sms')->store;
408
            $preference->message_transport_types('sms')->store;
409
        };
409
        };
410
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired',
410
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired',
411
            'Adding a message preference with invalid message_transport_type'
411
            'Adding a message preference with invalid message_transport_type'
412
            .' => Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired');
412
            .' => Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired');
413
        is ($@->message_name, $preference->message_name, 'The previous exception '
413
        is ($@->message_name, $preference->message_name, 'The previous exception '
414
            .' tells us it which message name it was.');
414
            .' tells us it which message name it was.');
415
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
415
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
Lines 425-440 HERE Link Here
425
425
426
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
426
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
427
        my $letter    = build_a_test_letter();
427
        my $letter    = build_a_test_letter();
428
        my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
428
        my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
429
        my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
429
        my $mtt       = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
430
        Koha::Patron::Message::Transport->new({
430
        Koha::Patron::MessagePreference::Transport->new({
431
            message_attribute_id   => $attribute->message_attribute_id,
431
            message_attribute_id   => $attribute->message_attribute_id,
432
            message_transport_type => $mtt->message_transport_type,
432
            message_transport_type => $mtt->message_transport_type,
433
            is_digest              => 0,
433
            is_digest              => 0,
434
            letter_module          => $letter->module,
434
            letter_module          => $letter->module,
435
            letter_code            => $letter->code,
435
            letter_code            => $letter->code,
436
        })->store;
436
        })->store;
437
        ok(my $preference = Koha::Patron::Message::Preference->new({
437
        ok(my $preference = Koha::Patron::MessagePreference->new({
438
            borrowernumber => $patron->borrowernumber,
438
            borrowernumber => $patron->borrowernumber,
439
            message_attribute_id => $attribute->message_attribute_id,
439
            message_attribute_id => $attribute->message_attribute_id,
440
            wants_digest => 0,
440
            wants_digest => 0,
Lines 443-449 HERE Link Here
443
        })->store, 'Added a new messaging preference and transport types to patron.');
443
        })->store, 'Added a new messaging preference and transport types to patron.');
444
        ok($preference->message_transport_types->{$mtt->message_transport_type},
444
        ok($preference->message_transport_types->{$mtt->message_transport_type},
445
           'The transport type is stored in the object.');
445
           'The transport type is stored in the object.');
446
        my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({
446
        my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({
447
            borrower_message_preference_id => $preference->borrower_message_preference_id,
447
            borrower_message_preference_id => $preference->borrower_message_preference_id,
448
        });
448
        });
449
        is($stored_transports->next->message_transport_type, $mtt->message_transport_type,
449
        is($stored_transports->next->message_transport_type, $mtt->message_transport_type,
Lines 453-470 HERE Link Here
453
    };
453
    };
454
};
454
};
455
455
456
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
456
subtest 'Test Koha::Patron::MessagePreference->message_name' => sub {
457
    plan tests => 1;
457
    plan tests => 1;
458
458
459
    $schema->storage->txn_begin;
459
    $schema->storage->txn_begin;
460
460
461
    my $patron      = $builder->build_object({ class => 'Koha::Patrons' });
461
    my $patron      = $builder->build_object({ class => 'Koha::Patrons' });
462
    my $attribute   = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
462
    my $attribute   = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
463
    my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
463
    my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
464
        patron => $patron,
464
        patron => $patron,
465
        attr   => $attribute,
465
        attr   => $attribute,
466
    });
466
    });
467
    my $message_name_pref = Koha::Patron::Message::Preferences->search_with_message_name({
467
    my $message_name_pref = Koha::Patron::MessagePreferences->search_with_message_name({
468
        borrowernumber => $patron->{'borrowernumber'},
468
        borrowernumber => $patron->{'borrowernumber'},
469
        message_name => $attribute->message_name,
469
        message_name => $attribute->message_name,
470
    })->next;
470
    })->next;
Lines 473-479 subtest 'Test Koha::Patron::Message::Preference->message_name' => sub { Link Here
473
    $schema->storage->txn_rollback;
473
    $schema->storage->txn_rollback;
474
};
474
};
475
475
476
subtest 'Test Koha::Patron::Message::Preference->mtt_deliverable' => sub {
476
subtest 'Test Koha::Patron::MessagePreference->mtt_deliverable' => sub {
477
    plan tests => 10;
477
    plan tests => 10;
478
478
479
    $schema->storage->txn_begin;
479
    $schema->storage->txn_begin;
Lines 484-517 subtest 'Test Koha::Patron::Message::Preference->mtt_deliverable' => sub { Link Here
484
    });
484
    });
485
485
486
    # Test email and smsalertnumber validation
486
    # Test email and smsalertnumber validation
487
    eval { Koha::Patron::Message::Transport::Types->new({
487
    eval { Koha::Patron::MessagePreference::Transport::Types->new({
488
            message_transport_type => 'email'
488
            message_transport_type => 'email'
489
        })->store };
489
        })->store };
490
    eval { Koha::Patron::Message::Transport::Types->new({
490
    eval { Koha::Patron::MessagePreference::Transport::Types->new({
491
            message_transport_type => 'sms'
491
            message_transport_type => 'sms'
492
        })->store };
492
        })->store };
493
    eval { Koha::Patron::Message::Transport::Types->new({
493
    eval { Koha::Patron::MessagePreference::Transport::Types->new({
494
            message_transport_type => 'phone'
494
            message_transport_type => 'phone'
495
        })->store };
495
        })->store };
496
    eval { Koha::Patron::Message::Transport::Types->new({
496
    eval { Koha::Patron::MessagePreference::Transport::Types->new({
497
            message_transport_type => 'itiva'
497
            message_transport_type => 'itiva'
498
        })->store };
498
        })->store };
499
    Koha::Patron::Message::Transport->new({
499
    Koha::Patron::MessagePreference::Transport->new({
500
        message_attribute_id   => $preference->message_attribute_id,
500
        message_attribute_id   => $preference->message_attribute_id,
501
        message_transport_type => 'email',
501
        message_transport_type => 'email',
502
        is_digest              => 1
502
        is_digest              => 1
503
    })->store;
503
    })->store;
504
    Koha::Patron::Message::Transport->new({
504
    Koha::Patron::MessagePreference::Transport->new({
505
        message_attribute_id   => $preference->message_attribute_id,
505
        message_attribute_id   => $preference->message_attribute_id,
506
        message_transport_type => 'sms',
506
        message_transport_type => 'sms',
507
        is_digest              => 1
507
        is_digest              => 1
508
    })->store;
508
    })->store;
509
    Koha::Patron::Message::Transport->new({
509
    Koha::Patron::MessagePreference::Transport->new({
510
        message_attribute_id   => $preference->message_attribute_id,
510
        message_attribute_id   => $preference->message_attribute_id,
511
        message_transport_type => 'phone',
511
        message_transport_type => 'phone',
512
        is_digest              => 1
512
        is_digest              => 1
513
    })->store;
513
    })->store;
514
    Koha::Patron::Message::Transport->new({
514
    Koha::Patron::MessagePreference::Transport->new({
515
        message_attribute_id   => $preference->message_attribute_id,
515
        message_attribute_id   => $preference->message_attribute_id,
516
        message_transport_type => 'itiva',
516
        message_transport_type => 'itiva',
517
        is_digest              => 1
517
        is_digest              => 1
Lines 557-563 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
557
    subtest 'Missing parameters' => sub {
557
    subtest 'Missing parameters' => sub {
558
        plan tests => 1;
558
        plan tests => 1;
559
559
560
        eval { Koha::Patron::Message::Preference->new->store };
560
        eval { Koha::Patron::MessagePreference->new->store };
561
        is(ref $@, 'Koha::Exceptions::MissingParameter',
561
        is(ref $@, 'Koha::Exceptions::MissingParameter',
562
            'Adding a message preference without parameters'
562
            'Adding a message preference without parameters'
563
            .' => Koha::Exceptions::MissingParameter');
563
            .' => Koha::Exceptions::MissingParameter');
Lines 569-575 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
569
        $schema->storage->txn_begin;
569
        $schema->storage->txn_begin;
570
570
571
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
571
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
572
        eval { Koha::Patron::Message::Preference->new({
572
        eval { Koha::Patron::MessagePreference->new({
573
            borrowernumber => $patron->borrowernumber,
573
            borrowernumber => $patron->borrowernumber,
574
            categorycode   => $patron->categorycode,
574
            categorycode   => $patron->categorycode,
575
        })->store };
575
        })->store };
Lines 585-598 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
585
585
586
        $schema->storage->txn_begin;
586
        $schema->storage->txn_begin;
587
587
588
        eval { Koha::Patron::Message::Preference->new({
588
        eval { Koha::Patron::MessagePreference->new({
589
                borrowernumber => -999,
589
                borrowernumber => -999,
590
            })->store };
590
            })->store };
591
        is(ref $@, 'Koha::Exceptions::Patron::NotFound',
591
        is(ref $@, 'Koha::Exceptions::Patron::NotFound',
592
            'Adding a message preference with invalid borrowernumber'
592
            'Adding a message preference with invalid borrowernumber'
593
            .' => Koha::Exceptions::Patron::NotFound');
593
            .' => Koha::Exceptions::Patron::NotFound');
594
594
595
        eval { Koha::Patron::Message::Preference->new({
595
        eval { Koha::Patron::MessagePreference->new({
596
                categorycode => 'nonexistent',
596
                categorycode => 'nonexistent',
597
            })->store };
597
            })->store };
598
        is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound',
598
        is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound',
Lines 601-696 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
601
601
602
        my $attribute = build_a_test_attribute({ takes_days => 0 });
602
        my $attribute = build_a_test_attribute({ takes_days => 0 });
603
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
603
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
604
        eval { Koha::Patron::Message::Preference->new({
604
        eval { Koha::Patron::MessagePreference->new({
605
                borrowernumber => $patron->borrowernumber,
605
                borrowernumber => $patron->borrowernumber,
606
                message_attribute_id => $attribute->message_attribute_id,
606
                message_attribute_id => $attribute->message_attribute_id,
607
                days_in_advance => 10,
607
                days_in_advance => 10,
608
            })->store };
608
            })->store };
609
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable',
609
        is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable',
610
            'Adding a message preference with days in advance option when not'
610
            'Adding a message preference with days in advance option when not'
611
            .' available => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable');
611
            .' available => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable');
612
612
613
        $attribute->set({ takes_days => 1 })->store;
613
        $attribute->set({ takes_days => 1 })->store;
614
        eval { Koha::Patron::Message::Preference->new({
614
        eval { Koha::Patron::MessagePreference->new({
615
                borrowernumber => $patron->borrowernumber,
615
                borrowernumber => $patron->borrowernumber,
616
                message_attribute_id => $attribute->message_attribute_id,
616
                message_attribute_id => $attribute->message_attribute_id,
617
                days_in_advance => -1,
617
                days_in_advance => -1,
618
            })->store };
618
            })->store };
619
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange',
619
        is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange',
620
            'Adding a message preference with days in advance option is out of range'
620
            'Adding a message preference with days in advance option is out of range'
621
            .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange');
621
            .' => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange');
622
        is ($@->min, 0, 'The previous exception min value is 0.');
622
        is ($@->min, 0, 'The previous exception min value is 0.');
623
623
624
        eval { Koha::Patron::Message::Preference->new({
624
        eval { Koha::Patron::MessagePreference->new({
625
                borrowernumber => $patron->borrowernumber,
625
                borrowernumber => $patron->borrowernumber,
626
                message_attribute_id => $attribute->message_attribute_id,
626
                message_attribute_id => $attribute->message_attribute_id,
627
                days_in_advance => 31,
627
                days_in_advance => 31,
628
            })->store };
628
            })->store };
629
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange',
629
        is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange',
630
            'Adding a message preference with days in advance option is out of range'
630
            'Adding a message preference with days in advance option is out of range'
631
            .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange');
631
            .' => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange');
632
        is ($@->max, 30, 'The previous exception max value is 30.');
632
        is ($@->max, 30, 'The previous exception max value is 30.');
633
633
634
        eval { Koha::Patron::Message::Preference->new({
634
        eval { Koha::Patron::MessagePreference->new({
635
                borrowernumber => $patron->borrowernumber,
635
                borrowernumber => $patron->borrowernumber,
636
                message_transport_types => ['nonexistent']
636
                message_transport_types => ['nonexistent']
637
            })->store };
637
            })->store };
638
        is (ref $@, 'Koha::Exceptions::Patron::Message::Transport::TypeNotFound',
638
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound',
639
            'Adding a message preference with invalid message_transport_type'
639
            'Adding a message preference with invalid message_transport_type'
640
            .' => Koha::Exceptions::Patron::Message::Transport::TypeNotFound');
640
            .' => Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound');
641
        is ($@->transport_type, 'nonexistent', 'The previous exception '
641
        is ($@->transport_type, 'nonexistent', 'The previous exception '
642
            .'tells us it which transport type it was.');
642
            .'tells us it which transport type it was.');
643
643
644
        my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
644
        my $mtt_new = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
645
        eval {
645
        eval {
646
            Koha::Patron::Message::Preference->new({
646
            Koha::Patron::MessagePreference->new({
647
                borrowernumber => $patron->borrowernumber,
647
                borrowernumber => $patron->borrowernumber,
648
                message_attribute_id => $attribute->message_attribute_id,
648
                message_attribute_id => $attribute->message_attribute_id,
649
                message_transport_types => [$mtt_new->message_transport_type],
649
                message_transport_types => [$mtt_new->message_transport_type],
650
                wants_digest => 1,
650
                wants_digest => 1,
651
            })->store };
651
            })->store };
652
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::NoTransportType',
652
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::NoTransportType',
653
            'Adding a message preference with invalid message_transport_type'
653
            'Adding a message preference with invalid message_transport_type'
654
           .' => Koha::Exceptions::Patron::Message::Preference::NoTransportType');
654
           .' => Koha::Exceptions::Patron::MessagePreference::NoTransportType');
655
        is ($@->message_name, $attribute->message_name, 'The previous exception '
655
        is ($@->message_name, $attribute->message_name, 'The previous exception '
656
            .'tells us which message it was.');
656
            .'tells us which message it was.');
657
        is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception '
657
        is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception '
658
            .'tells us which message transport type it was.');
658
            .'tells us which message transport type it was.');
659
659
660
        eval {
660
        eval {
661
            Koha::Patron::Message::Preference->new({
661
            Koha::Patron::MessagePreference->new({
662
                borrowernumber => $patron->borrowernumber,
662
                borrowernumber => $patron->borrowernumber,
663
                message_attribute_id => $attribute->message_attribute_id,
663
                message_attribute_id => $attribute->message_attribute_id,
664
                message_transport_types => [],
664
                message_transport_types => [],
665
                wants_digest => 1,
665
                wants_digest => 1,
666
            })->store };
666
            })->store };
667
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable',
667
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable',
668
            'Adding a message preference that has no digest setting'
668
            'Adding a message preference that has no digest setting'
669
            .' => Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable');
669
            .' => Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable');
670
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
670
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
671
            .' which message it was');
671
            .' which message it was');
672
672
673
        eval {
673
        eval {
674
            Koha::Patron::Message::Preference->new({
674
            Koha::Patron::MessagePreference->new({
675
                borrowernumber => $patron->borrowernumber,
675
                borrowernumber => $patron->borrowernumber,
676
                message_attribute_id => $attribute->message_attribute_id,
676
                message_attribute_id => $attribute->message_attribute_id,
677
                message_transport_types => [],
677
                message_transport_types => [],
678
                wants_digest => 0,
678
                wants_digest => 0,
679
            })->store };
679
            })->store };
680
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestRequired',
680
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::DigestRequired',
681
            'Adding a message preference, that requires digest, with no digest'
681
            'Adding a message preference, that requires digest, with no digest'
682
            .' => Koha::Exceptions::Patron::Message::Preference::DigestRequired');
682
            .' => Koha::Exceptions::Patron::MessagePreference::DigestRequired');
683
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
683
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
684
            .' which message it was');
684
            .' which message it was');
685
        eval {
685
        eval {
686
            Koha::Patron::Message::Preference->new({
686
            Koha::Patron::MessagePreference->new({
687
                borrowernumber => $patron->borrowernumber,
687
                borrowernumber => $patron->borrowernumber,
688
                message_attribute_id => -1,
688
                message_attribute_id => -1,
689
                message_transport_types => [],
689
                message_transport_types => [],
690
            })->store };
690
            })->store };
691
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound',
691
        is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::AttributeNotFound',
692
            'Adding a message preference with invalid message_transport_type'
692
            'Adding a message preference with invalid message_transport_type'
693
            .' => KKoha::Exceptions::Patron::Message::Preference::AttributeNotFound');
693
            .' => KKoha::Exceptions::Patron::MessagePreference::AttributeNotFound');
694
        is ($@->message_attribute_id, -1, 'The previous exception tells'
694
        is ($@->message_attribute_id, -1, 'The previous exception tells'
695
            .' us which message attribute id it was.');
695
            .' us which message attribute id it was.');
696
696
Lines 702-711 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
702
702
703
        $schema->storage->txn_begin;
703
        $schema->storage->txn_begin;
704
704
705
        my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
705
        my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' });
706
        my $letter = build_a_test_letter();
706
        my $letter = build_a_test_letter();
707
        my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
707
        my $mtt = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
708
        Koha::Patron::Message::Transport->new({
708
        Koha::Patron::MessagePreference::Transport->new({
709
            message_attribute_id   => $attribute->message_attribute_id,
709
            message_attribute_id   => $attribute->message_attribute_id,
710
            message_transport_type => $mtt->message_transport_type,
710
            message_transport_type => $mtt->message_transport_type,
711
            is_digest              => 0,
711
            is_digest              => 0,
Lines 713-719 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
713
            letter_code            => $letter->code,
713
            letter_code            => $letter->code,
714
        })->store;
714
        })->store;
715
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
715
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
716
        my $preference = Koha::Patron::Message::Preference->new({
716
        my $preference = Koha::Patron::MessagePreference->new({
717
            borrowernumber => $patron->borrowernumber,
717
            borrowernumber => $patron->borrowernumber,
718
            message_attribute_id => $attribute->message_attribute_id,
718
            message_attribute_id => $attribute->message_attribute_id,
719
            wants_digest => 0,
719
            wants_digest => 0,
Lines 721-727 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
721
        })->store;
721
        })->store;
722
        ok($preference->borrower_message_preference_id,
722
        ok($preference->borrower_message_preference_id,
723
           'Added a new messaging preference for patron.');
723
           'Added a new messaging preference for patron.');
724
        eval { Koha::Patron::Message::Preference->new({
724
        eval { Koha::Patron::MessagePreference->new({
725
            borrowernumber => $patron->borrowernumber,
725
            borrowernumber => $patron->borrowernumber,
726
            message_attribute_id => $attribute->message_attribute_id,
726
            message_attribute_id => $attribute->message_attribute_id,
727
            wants_digest => 0,
727
            wants_digest => 0,
Lines 746-752 sub build_a_test_attribute { Link Here
746
        value => $params,
746
        value => $params,
747
    });
747
    });
748
748
749
    return Koha::Patron::Message::Attributes->find(
749
    return Koha::Patron::MessagePreference::Attributes->find(
750
        $attribute->{message_attribute_id}
750
        $attribute->{message_attribute_id}
751
    );
751
    );
752
}
752
}
Lines 782-791 sub build_a_test_category_preference { Link Here
782
                    : build_a_test_attribute($params->{days_in_advance});
782
                    : build_a_test_attribute($params->{days_in_advance});
783
783
784
    my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
784
    my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
785
    my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
785
    my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
786
    my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
786
    my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' });
787
787
788
    Koha::Patron::Message::Transport->new({
788
    Koha::Patron::MessagePreference::Transport->new({
789
        message_attribute_id   => $attr->message_attribute_id,
789
        message_attribute_id   => $attr->message_attribute_id,
790
        message_transport_type => $mtt1->message_transport_type,
790
        message_transport_type => $mtt1->message_transport_type,
791
        is_digest              => $params->{digest} ? 1 : 0,
791
        is_digest              => $params->{digest} ? 1 : 0,
Lines 793-799 sub build_a_test_category_preference { Link Here
793
        letter_code            => $letter->code,
793
        letter_code            => $letter->code,
794
    })->store;
794
    })->store;
795
795
796
    Koha::Patron::Message::Transport->new({
796
    Koha::Patron::MessagePreference::Transport->new({
797
        message_attribute_id   => $attr->message_attribute_id,
797
        message_attribute_id   => $attr->message_attribute_id,
798
        message_transport_type => $mtt2->message_transport_type,
798
        message_transport_type => $mtt2->message_transport_type,
799
        is_digest              => $params->{digest} ? 1 : 0,
799
        is_digest              => $params->{digest} ? 1 : 0,
Lines 801-807 sub build_a_test_category_preference { Link Here
801
        letter_code            => $letter->code,
801
        letter_code            => $letter->code,
802
    })->store;
802
    })->store;
803
803
804
    my $default = Koha::Patron::Message::Preference->new({
804
    my $default = Koha::Patron::MessagePreference->new({
805
        categorycode         => $patron->categorycode,
805
        categorycode         => $patron->categorycode,
806
        message_attribute_id => $attr->message_attribute_id,
806
        message_attribute_id => $attr->message_attribute_id,
807
        wants_digest         => $params->{digest} ? 1 : 0,
807
        wants_digest         => $params->{digest} ? 1 : 0,
Lines 809-819 sub build_a_test_category_preference { Link Here
809
                                 ? $params->{days_in_advance} : undef,
809
                                 ? $params->{days_in_advance} : undef,
810
    })->store;
810
    })->store;
811
811
812
    Koha::Patron::Message::Transport::Preference->new({
812
    Koha::Patron::MessagePreference::Transport::Preference->new({
813
        borrower_message_preference_id => $default->borrower_message_preference_id,
813
        borrower_message_preference_id => $default->borrower_message_preference_id,
814
        message_transport_type         => $mtt1->message_transport_type,
814
        message_transport_type         => $mtt1->message_transport_type,
815
    })->store;
815
    })->store;
816
    Koha::Patron::Message::Transport::Preference->new({
816
    Koha::Patron::MessagePreference::Transport::Preference->new({
817
        borrower_message_preference_id => $default->borrower_message_preference_id,
817
        borrower_message_preference_id => $default->borrower_message_preference_id,
818
        message_transport_type         => $mtt2->message_transport_type,
818
        message_transport_type         => $mtt2->message_transport_type,
819
    })->store;
819
    })->store;
Lines 827-833 sub build_a_test_complete_preference { Link Here
827
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference($params);
827
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference($params);
828
    my $patron = $params->{patron};
828
    my $patron = $params->{patron};
829
    $patron->set_default_messaging_preferences;
829
    $patron->set_default_messaging_preferences;
830
    return (Koha::Patron::Message::Preferences->search({
830
    return (Koha::Patron::MessagePreferences->search({
831
        borrowernumber => $patron->borrowernumber
831
        borrowernumber => $patron->borrowernumber
832
    })->next, $mtt1, $mtt2);
832
    })->next, $mtt1, $mtt2);
833
}
833
}
834
- 

Return to bug 17499