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

(-)a/Koha/Exceptions/Patron.pm (-1 / +5 lines)
Lines 23-29 use Exception::Class ( Link Here
23
        isa         => 'Koha::Exceptions::Patron',
23
        isa         => 'Koha::Exceptions::Patron',
24
        description => "Mandatory extended attribute missing",
24
        description => "Mandatory extended attribute missing",
25
        fields      => ['type']
25
        fields      => ['type']
26
    }
26
    },
27
    'Koha::Exceptions::Patron::NotFound' => {
28
        isa => 'Koha::Exceptions::Patron',
29
        description => "Patron not found"
30
    },
27
);
31
);
28
32
29
sub full_message {
33
sub full_message {
(-)a/Koha/Exceptions/Patron/Category.pm (+30 lines)
Line 0 Link Here
1
package Koha::Exceptions::Patron::Category;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Exception::Class (
21
    'Koha::Exceptions::Patron::Category' => {
22
        description => "Something went wrong!"
23
    },
24
    'Koha::Exceptions::Patron::Category::NotFound' => {
25
        isa => 'Koha::Exceptions::Patron::Category',
26
        description => "Patron category not found"
27
    },
28
);
29
30
1;
(-)a/Koha/Exceptions/Patron/Message/Preference.pm (+67 lines)
Line 0 Link Here
1
package Koha::Exceptions::Patron::Message::Preference;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Exception::Class (
21
22
    'Koha::Exceptions::Patron::Message::Preference' => {
23
        description => 'Something went wrong'
24
    },
25
    'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound' => {
26
        isa => 'Koha::Exceptions::Patron::Message::Preference',
27
        description => "Message attribute not found",
28
        fields => ['message_attribute_id']
29
    },
30
    'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange' => {
31
        isa => 'Koha::Exceptions::Patron::Message::Preference',
32
        description => "Days in advance is out of range",
33
        fields => ['min','max', 'message_name']
34
    },
35
    'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable' => {
36
        isa => 'Koha::Exceptions::Patron::Message::Preference',
37
        description => "Days in advance cannot be selected for this preference",
38
        fields => ['message_name']
39
    },
40
    'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable' => {
41
        isa => 'Koha::Exceptions::Patron::Message::Preference',
42
        description => "Digest is not available for this message type",
43
        fields => ['message_name']
44
    },
45
    'Koha::Exceptions::Patron::Message::Preference::DigestRequired' => {
46
        isa => 'Koha::Exceptions::Patron::Message::Preference',
47
        description => "Digest must be selected for this message type",
48
        fields => ['message_name']
49
    },
50
    'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired' => {
51
        isa => 'Koha::Exceptions::Patron::Message::Preference',
52
        description => "Patron has no email address, cannot use email transport type.",
53
        fields => ['message_name', 'borrowernumber' ]
54
    },
55
    'Koha::Exceptions::Patron::Message::Preference::NoTransportType' => {
56
        isa => 'Koha::Exceptions::Patron::Message::Preference',
57
        description => "Transport type not available for this message.",
58
        fields => ['message_name', 'transport_type']
59
    },
60
    'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired' => {
61
        isa => 'Koha::Exceptions::Patron::Message::Preference',
62
        description => "Patron has no SMS number, cannot use sms transport type.",
63
        fields => ['message_name', 'borrowernumber' ]
64
    },
65
);
66
67
1;
(-)a/Koha/Exceptions/Patron/Message/Transport.pm (+32 lines)
Line 0 Link Here
1
package Koha::Exceptions::Patron::Message::Transport;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Exception::Class (
21
22
    'Koha::Exceptions::Patron::Message::Transport' => {
23
        description => 'Something went wrong'
24
    },
25
    'Koha::Exceptions::Patron::Message::Transport::TypeNotFound' => {
26
        isa => 'Koha::Exceptions::Patron::Message::Transport',
27
        description => "Transport type does not exist.",
28
        fields => ['transport_type']
29
    },
30
);
31
32
1;
(-)a/Koha/Patron/Message/Preference.pm (-36 / +40 lines)
Lines 21-26 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;
25
use Koha::Exceptions::Patron::Message::Transport;
26
use Koha::Exceptions::Patron::Category;
24
use Koha::Patron::Categories;
27
use Koha::Patron::Categories;
25
use Koha::Patron::Message::Attributes;
28
use Koha::Patron::Message::Attributes;
26
use Koha::Patron::Message::Preferences;
29
use Koha::Patron::Message::Preferences;
Lines 284-299 sub store { Link Here
284
287
285
Makes a basic validation for object.
288
Makes a basic validation for object.
286
289
287
Throws following exceptions regarding parameters.
290
Returns Koha::Patron::Message::Preference object, or throws and exception.
288
- Koha::Exceptions::MissingParameter
289
- Koha::Exceptions::TooManyParameters
290
- Koha::Exceptions::BadParameter
291
292
See $_->parameter to identify the parameter causing the exception.
293
294
Throws Koha::Exceptions::DuplicateObject if this preference already exists.
295
296
Returns Koha::Patron::Message::Preference object.
297
291
298
=cut
292
=cut
299
293
Lines 311-325 sub validate { Link Here
311
        );
305
        );
312
    }
306
    }
313
    if ($self->borrowernumber) {
307
    if ($self->borrowernumber) {
314
        Koha::Exceptions::BadParameter->throw(
308
        Koha::Exceptions::Patron::NotFound->throw(
315
            error => 'Patron not found.',
309
            error => 'Patron not found.',
316
            parameter => 'borrowernumber',
317
        ) unless Koha::Patrons->find($self->borrowernumber);
310
        ) unless Koha::Patrons->find($self->borrowernumber);
318
    }
311
    }
319
    if ($self->categorycode) {
312
    if ($self->categorycode) {
320
        Koha::Exceptions::BadParameter->throw(
313
        Koha::Exceptions::Patron::Category::NotFound->throw(
321
            error => 'Category not found.',
314
            error => 'Category not found.',
322
            parameter => 'categorycode',
323
        ) unless Koha::Patron::Categories->find($self->categorycode);
315
        ) unless Koha::Patron::Categories->find($self->categorycode);
324
    }
316
    }
325
317
Lines 341-365 sub validate { Link Here
341
        $self->message_attribute_id
333
        $self->message_attribute_id
342
    );
334
    );
343
    unless ($attr) {
335
    unless ($attr) {
344
        Koha::Exceptions::BadParameter->throw(
336
        Koha::Exceptions::Patron::Message::Preference::AttributeNotFound->throw(
345
            error => 'Message attribute with id '.$self->message_attribute_id
337
            error => 'Message attribute with id '.$self->message_attribute_id
346
            .' not found',
338
            .' not found',
347
            parameter => 'message_attribute_id'
339
            message_attribute_id => $self->message_attribute_id,
348
        );
340
        );
349
    }
341
    }
350
    if (defined $self->days_in_advance) {
342
    if (defined $self->days_in_advance) {
351
        if ($attr && $attr->takes_days == 0) {
343
        if ($attr && $attr->takes_days == 0) {
352
            Koha::Exceptions::BadParameter->throw(
344
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable->throw(
353
                error => 'days_in_advance cannot be defined for '.
345
                error => 'days_in_advance cannot be defined for '.
354
                $attr->message_name . '.',
346
                $attr->message_name . '.',
355
                parameter => 'days_in_advance',
347
                message_name => $attr->message_name,
356
            );
348
            );
357
        }
349
        }
358
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
350
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
359
            Koha::Exceptions::BadParameter->throw(
351
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange->throw(
360
                error => 'days_in_advance has to be a value between 0-30 for '.
352
                error => 'days_in_advance has to be a value between 0-30 for '.
361
                $attr->message_name . '.',
353
                $attr->message_name . '.',
362
                parameter => 'days_in_advance',
354
                message_name => $attr->message_name,
355
                min => 0,
356
                max => 30,
363
            );
357
            );
364
        }
358
        }
365
    }
359
    }
Lines 368-379 sub validate { Link Here
368
            message_attribute_id => $self->message_attribute_id,
362
            message_attribute_id => $self->message_attribute_id,
369
            is_digest            => $self->wants_digest ? 1 : 0,
363
            is_digest            => $self->wants_digest ? 1 : 0,
370
        });
364
        });
371
        Koha::Exceptions::BadParameter->throw(
365
        unless ($transports->count) {
372
            error => (!$self->wants_digest ? 'Digest must be selected'
366
            if (!$self->wants_digest) {
373
                                           : 'Digest cannot be selected')
367
                Koha::Exceptions::Patron::Message::Preference::DigestRequired->throw(
374
            . ' for '.$attr->message_name.'.',
368
                    error => 'Digest must be selected for '.$attr->message_name.'.',
375
            parameter => 'wants_digest',
369
                    message_name => $attr->message_name
376
        ) if $transports->count == 0;
370
                );
371
            } else {
372
                Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable->throw(
373
                    error => 'Digest cannot be selected for '.$attr->message_name.'.',
374
                    message_name => $attr->message_name
375
                );
376
            }
377
        }
377
    }
378
    }
378
379
379
    return $self;
380
    return $self;
Lines 395-404 sub _set_message_transport_types { Link Here
395
                message_transport_type => $type
396
                message_transport_type => $type
396
            });
397
            });
397
            unless ($transport) {
398
            unless ($transport) {
398
                Koha::Exceptions::BadParameter->throw(
399
                Koha::Exceptions::Patron::Message::Preference::NoTransportType->throw(
399
                    error => 'No transport configured for '.$self->message_name.
400
                    error => 'No transport configured for '.$self->message_name.
400
                        " transport type $type.",
401
                        " transport type $type.",
401
                    parameter => 'message_transport_types'
402
                    message_name => $self->message_name,
403
                    transport_type => $type,
402
                );
404
                );
403
            }
405
            }
404
            if (defined $self->borrowernumber) {
406
            if (defined $self->borrowernumber) {
Lines 406-424 sub _set_message_transport_types { Link Here
406
                if ($type eq 'email') {
408
                if ($type eq 'email') {
407
                    if ( !$patron->email )
409
                    if ( !$patron->email )
408
                    {
410
                    {
409
                        Koha::Exceptions::BadParameter->throw(
411
                        Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired->throw(
410
                            error => 'Patron has not set email address, '.
412
                            error => 'Patron has not set email address, '.
411
                                     'cannot use email as message transport',
413
                                     'cannot use email as message transport',
412
                            parameter => 'message_transport_types'
414
                            message_name => $self->message_name,
415
                            borrowernumber => $self->borrowernumber,
413
                        );
416
                        );
414
                    }
417
                    }
415
                }
418
                }
416
                elsif ($type eq 'sms') {
419
                elsif ($type eq 'sms') {
417
                    if ( !$patron->smsalertnumber ){
420
                    if ( !$patron->smsalertnumber ){
418
                        Koha::Exceptions::BadParameter->throw(
421
                        Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
419
                            error => 'Patron has not set sms number, '.
422
                            error => 'Patron has not set SMS number'.
420
                                     'cannot set sms as message transport',
423
                                     'cannot use sms as message transport',
421
                            parameter => 'message_transport_types'
424
                            message_name => $self->message_name,
425
                            borrowernumber => $self->borrowernumber,
422
                        );
426
                        );
423
                    }
427
                    }
424
                }
428
                }
Lines 443-451 sub _validate_message_transport_types { Link Here
443
            unless (Koha::Patron::Message::Transport::Types->find({
447
            unless (Koha::Patron::Message::Transport::Types->find({
444
                message_transport_type => $type
448
                message_transport_type => $type
445
            })) {
449
            })) {
446
                Koha::Exceptions::BadParameter->throw(
450
                Koha::Exceptions::Patron::Message::Transport::TypeNotFound->throw(
447
                    error => "Message transport type '$type' does not exist",
451
                    error => "Message transport type '$type' does not exist",
448
                    parameter => 'message_transport_types',
452
                    transport_type => $type,
449
                );
453
                );
450
            }
454
            }
451
        }
455
        }
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-62 / +57 lines)
Lines 360-382 HERE Link Here
360
        eval {
360
        eval {
361
            $preference->message_transport_types('email')->store;
361
            $preference->message_transport_types('email')->store;
362
        };
362
        };
363
        is (ref $@, 'Koha::Exceptions::BadParameter',
363
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired',
364
            'Adding a message preference with invalid message_transport_type'
364
            'Adding a message preference with invalid message_transport_type'
365
            .' => Koha::Exceptions::BadParameter');
365
            .' => Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired');
366
        is ($@->parameter, 'message_transport_types', 'The previous exception '
366
        is ($@->message_name, $preference->message_name, 'The previous exception '
367
            .' tells us it was the message_transport_types');
367
            .' tells us it which message name it was.');
368
        like ($@->error, qr/^Patron has not set email address/, 'Exception '
368
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
369
            .' is because of patron has not set email address.');
369
            .' tells us which patron it was.');
370
        eval {
370
        eval {
371
            $preference->message_transport_types('sms')->store;
371
            $preference->message_transport_types('sms')->store;
372
        };
372
        };
373
        is (ref $@, 'Koha::Exceptions::BadParameter',
373
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired',
374
            'Adding a message preference with invalid message_transport_type'
374
            'Adding a message preference with invalid message_transport_type'
375
            .' => Koha::Exceptions::BadParameter');
375
            .' => Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired');
376
        is ($@->parameter, 'message_transport_types', 'The previous exception '
376
        is ($@->message_name, $preference->message_name, 'The previous exception '
377
            .' tells us it was the message_transport_types');
377
            .' tells us it which message name it was.');
378
        like ($@->error, qr/^Patron has not set sms number/, 'Exception '
378
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
379
            .' is because of patron has not set sms number.');
379
            .' tells us which patron it was.');
380
380
381
        $schema->storage->txn_rollback;
381
        $schema->storage->txn_rollback;
382
    };
382
    };
Lines 466-492 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
466
    };
466
    };
467
467
468
    subtest 'Bad parameter' => sub {
468
    subtest 'Bad parameter' => sub {
469
        plan tests => 22;
469
        plan tests => 18;
470
470
471
        $schema->storage->txn_begin;
471
        $schema->storage->txn_begin;
472
472
473
        eval { Koha::Patron::Message::Preference->new({
473
        eval { Koha::Patron::Message::Preference->new({
474
                borrowernumber => -999,
474
                borrowernumber => -999,
475
            })->store };
475
            })->store };
476
        is(ref $@, 'Koha::Exceptions::BadParameter',
476
        is(ref $@, 'Koha::Exceptions::Patron::NotFound',
477
            'Adding a message preference with invalid borrowernumber'
477
            'Adding a message preference with invalid borrowernumber'
478
            .' => Koha::Exceptions::BadParameter');
478
            .' => Koha::Exceptions::Patron::NotFound');
479
        is ($@->parameter, 'borrowernumber', 'The previous exception tells us it'
480
            .' was the borrowernumber.');
481
479
482
        eval { Koha::Patron::Message::Preference->new({
480
        eval { Koha::Patron::Message::Preference->new({
483
                categorycode => 'nonexistent',
481
                categorycode => 'nonexistent',
484
            })->store };
482
            })->store };
485
        is(ref $@, 'Koha::Exceptions::BadParameter',
483
        is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound',
486
            'Adding a message preference with invalid categorycode'
484
            'Adding a message preference with invalid categorycode'
487
            .' => Koha::Exceptions::BadParameter');
485
            .' => Koha::Exceptions::Patron::Category::NotFound');
488
        is($@->parameter, 'categorycode', 'The previous exception tells us it'
489
            .' was the categorycode.');
490
486
491
        my $attribute = build_a_test_attribute({ takes_days => 0 });
487
        my $attribute = build_a_test_attribute({ takes_days => 0 });
492
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
488
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
Lines 495-527 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
495
                message_attribute_id => $attribute->message_attribute_id,
491
                message_attribute_id => $attribute->message_attribute_id,
496
                days_in_advance => 10,
492
                days_in_advance => 10,
497
            })->store };
493
            })->store };
498
        is(ref $@, 'Koha::Exceptions::BadParameter',
494
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable',
499
            'Adding a message preference with days in advance option when not'
495
            'Adding a message preference with days in advance option when not'
500
            .' available => Koha::Exceptions::BadParameter');
496
            .' available => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable');
501
        is($@->parameter, 'days_in_advance', 'The previous exception tells us it'
502
            .' was the days_in_advance.');
503
497
504
        $attribute->set({ takes_days => 1 })->store;
498
        $attribute->set({ takes_days => 1 })->store;
499
        eval { Koha::Patron::Message::Preference->new({
500
                borrowernumber => $patron->borrowernumber,
501
                message_attribute_id => $attribute->message_attribute_id,
502
                days_in_advance => -1,
503
            })->store };
504
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange',
505
            'Adding a message preference with days in advance option is out of range'
506
            .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange');
507
        is ($@->min, 0, 'The previous exception min value is 0.');
508
505
        eval { Koha::Patron::Message::Preference->new({
509
        eval { Koha::Patron::Message::Preference->new({
506
                borrowernumber => $patron->borrowernumber,
510
                borrowernumber => $patron->borrowernumber,
507
                message_attribute_id => $attribute->message_attribute_id,
511
                message_attribute_id => $attribute->message_attribute_id,
508
                days_in_advance => 31,
512
                days_in_advance => 31,
509
            })->store };
513
            })->store };
510
        is(ref $@, 'Koha::Exceptions::BadParameter',
514
        is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange',
511
            'Adding a message preference with days in advance option too large'
515
            'Adding a message preference with days in advance option is out of range'
512
            .' => Koha::Exceptions::BadParameter');
516
            .' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange');
513
        is($@->parameter, 'days_in_advance', 'The previous exception tells us it'
517
        is ($@->max, 30, 'The previous exception max value is 30.');
514
            .' was the days_in_advance.');
515
518
516
        eval { Koha::Patron::Message::Preference->new({
519
        eval { Koha::Patron::Message::Preference->new({
517
                borrowernumber => $patron->borrowernumber,
520
                borrowernumber => $patron->borrowernumber,
518
                message_transport_types => ['nonexistent']
521
                message_transport_types => ['nonexistent']
519
            })->store };
522
            })->store };
520
        is (ref $@, 'Koha::Exceptions::BadParameter',
523
        is (ref $@, 'Koha::Exceptions::Patron::Message::Transport::TypeNotFound',
521
            'Adding a message preference with invalid message_transport_type'
524
            'Adding a message preference with invalid message_transport_type'
522
            .' => Koha::Exceptions::BadParameter');
525
            .' => Koha::Exceptions::Patron::Message::Transport::TypeNotFound');
523
        is ($@->parameter, 'message_transport_types', 'The previous exception '
526
        is ($@->transport_type, 'nonexistent', 'The previous exception '
524
            .'tells us it was the message_transport_types.');
527
            .'tells us it which transport type it was.');
525
528
526
        my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
529
        my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
527
        eval {
530
        eval {
Lines 531-543 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
531
                message_transport_types => [$mtt_new->message_transport_type],
534
                message_transport_types => [$mtt_new->message_transport_type],
532
                wants_digest => 1,
535
                wants_digest => 1,
533
            })->store };
536
            })->store };
534
        is (ref $@, 'Koha::Exceptions::BadParameter',
537
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::NoTransportType',
535
            'Adding a message preference with invalid message_transport_type'
538
            'Adding a message preference with invalid message_transport_type'
536
           .' => Koha::Exceptions::BadParameter');
539
           .' => Koha::Exceptions::Patron::Message::Preference::NoTransportType');
537
        is ($@->parameter, 'message_transport_types', 'The previous exception '
540
        is ($@->message_name, $attribute->message_name, 'The previous exception '
538
            .'tells us it was the message_transport_types.');
541
            .'tells us which message it was.');
539
        like ($@->error, qr/^No transport configured/, 'Exception is because of '
542
        is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception '
540
            .'given message_transport_type is not a valid option.');
543
            .'tells us which message transport type it was.');
541
544
542
        eval {
545
        eval {
543
            Koha::Patron::Message::Preference->new({
546
            Koha::Patron::Message::Preference->new({
Lines 546-558 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
546
                message_transport_types => [],
549
                message_transport_types => [],
547
                wants_digest => 1,
550
                wants_digest => 1,
548
            })->store };
551
            })->store };
549
        is (ref $@, 'Koha::Exceptions::BadParameter',
552
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable',
550
            'Adding a message preference with invalid message_transport_type'
553
            'Adding a message preference that has no digest setting'
551
            .' => Koha::Exceptions::BadParameter');
554
            .' => Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable');
552
        is ($@->parameter, 'wants_digest', 'The previous exception tells us it'
555
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
553
            .' was the wants_digest');
556
            .' which message it was');
554
        like ($@->error, qr/^Digest cannot be selected/, 'Exception s because of'
555
            .' given digest is not available for this transport.');
556
557
557
        eval {
558
        eval {
558
            Koha::Patron::Message::Preference->new({
559
            Koha::Patron::Message::Preference->new({
Lines 561-587 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
561
                message_transport_types => [],
562
                message_transport_types => [],
562
                wants_digest => 0,
563
                wants_digest => 0,
563
            })->store };
564
            })->store };
564
        is (ref $@, 'Koha::Exceptions::BadParameter',
565
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestRequired',
565
            'Adding a message preference with invalid message_transport_type'
566
            'Adding a message preference, that requires digest, with no digest'
566
            .' => Koha::Exceptions::BadParameter');
567
            .' => Koha::Exceptions::Patron::Message::Preference::DigestRequired');
567
        is ($@->parameter, 'wants_digest', 'The previous exception tells us it'
568
        is ($@->message_name, $attribute->message_name, 'The previous exception tells us'
568
            .' was the wants_digest');
569
            .' which message it was');
569
        like ($@->error, qr/^Digest must be selected/, 'Exception s because of'
570
            .' digest has to be on for this transport.');
571
572
        eval {
570
        eval {
573
            Koha::Patron::Message::Preference->new({
571
            Koha::Patron::Message::Preference->new({
574
                borrowernumber => $patron->borrowernumber,
572
                borrowernumber => $patron->borrowernumber,
575
                message_attribute_id => -1,
573
                message_attribute_id => -1,
576
                message_transport_types => [],
574
                message_transport_types => [],
577
            })->store };
575
            })->store };
578
        is (ref $@, 'Koha::Exceptions::BadParameter',
576
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound',
579
            'Adding a message preference with invalid message_transport_type'
577
            'Adding a message preference with invalid message_transport_type'
580
            .' => Koha::Exceptions::BadParameter');
578
            .' => KKoha::Exceptions::Patron::Message::Preference::AttributeNotFound');
581
        is ($@->parameter, 'message_attribute_id', 'The previous exception tells'
579
        is ($@->message_attribute_id, -1, 'The previous exception tells'
582
            .' us it was the message_attribute_id');
580
            .' us which message attribute id it was.');
583
        like ($@->error, qr/^Message attribute with id -1 not found/, 'Exception '
584
            .' is because of given message attribute id is not found.');
585
581
586
        $schema->storage->txn_rollback;
582
        $schema->storage->txn_rollback;
587
    };
583
    };
588
- 

Return to bug 17499