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

(-)a/Koha/Exceptions/Patron.pm (+3 lines)
Lines 9-14 use Exception::Class ( Link Here
9
    'Koha::Exceptions::Patron::FailedDelete' => {
9
    'Koha::Exceptions::Patron::FailedDelete' => {
10
        description => "Deleting patron failed"
10
        description => "Deleting patron failed"
11
    },
11
    },
12
    'Koha::Exceptions::Patron::NotFound' => {
13
        description => "Patron not found"
14
    },
12
);
15
);
13
16
14
1;
17
1;
(-)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/Patron/Message/Preference.pm (-26 / +39 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 314-328 sub validate { Link Here
314
        );
317
        );
315
    }
318
    }
316
    if ($self->borrowernumber) {
319
    if ($self->borrowernumber) {
317
        Koha::Exceptions::BadParameter->throw(
320
        Koha::Exceptions::Patron::NotFound->throw(
318
            error => 'Patron not found.',
321
            error => 'Patron not found.',
319
            parameter => 'borrowernumber',
320
        ) unless Koha::Patrons->find($self->borrowernumber);
322
        ) unless Koha::Patrons->find($self->borrowernumber);
321
    }
323
    }
322
    if ($self->categorycode) {
324
    if ($self->categorycode) {
323
        Koha::Exceptions::BadParameter->throw(
325
        Koha::Exceptions::Patron::Category::NotFound->throw(
324
            error => 'Category not found.',
326
            error => 'Category not found.',
325
            parameter => 'categorycode',
326
        ) unless Koha::Patron::Categories->find($self->categorycode);
327
        ) unless Koha::Patron::Categories->find($self->categorycode);
327
    }
328
    }
328
329
Lines 344-368 sub validate { Link Here
344
        $self->message_attribute_id
345
        $self->message_attribute_id
345
    );
346
    );
346
    unless ($attr) {
347
    unless ($attr) {
347
        Koha::Exceptions::BadParameter->throw(
348
        Koha::Exceptions::Patron::Message::Preference::AttributeNotFound->throw(
348
            error => 'Message attribute with id '.$self->message_attribute_id
349
            error => 'Message attribute with id '.$self->message_attribute_id
349
            .' not found',
350
            .' not found',
350
            parameter => 'message_attribute_id'
351
            message_attribute_id => $self->message_attribute_id,
351
        );
352
        );
352
    }
353
    }
353
    if (defined $self->days_in_advance) {
354
    if (defined $self->days_in_advance) {
354
        if ($attr && $attr->takes_days == 0) {
355
        if ($attr && $attr->takes_days == 0) {
355
            Koha::Exceptions::BadParameter->throw(
356
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable->throw(
356
                error => 'days_in_advance cannot be defined for '.
357
                error => 'days_in_advance cannot be defined for '.
357
                $attr->message_name . '.',
358
                $attr->message_name . '.',
358
                parameter => 'days_in_advance',
359
                message_name => $attr->message_name,
359
            );
360
            );
360
        }
361
        }
361
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
362
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
362
            Koha::Exceptions::BadParameter->throw(
363
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange->throw(
363
                error => 'days_in_advance has to be a value between 0-30 for '.
364
                error => 'days_in_advance has to be a value between 0-30 for '.
364
                $attr->message_name . '.',
365
                $attr->message_name . '.',
365
                parameter => 'days_in_advance',
366
                message_name => $attr->message_name,
367
                min => 0,
368
                max => 30,
366
            );
369
            );
367
        }
370
        }
368
    }
371
    }
Lines 371-382 sub validate { Link Here
371
            message_attribute_id => $self->message_attribute_id,
374
            message_attribute_id => $self->message_attribute_id,
372
            is_digest            => $self->wants_digest ? 1 : 0,
375
            is_digest            => $self->wants_digest ? 1 : 0,
373
        });
376
        });
374
        Koha::Exceptions::BadParameter->throw(
377
        unless ($transports->count) {
375
            error => (!$self->wants_digest ? 'Digest must be selected'
378
            if (!$self->wants_digest) {
376
                                           : 'Digest cannot be selected')
379
                Koha::Exceptions::Patron::Message::Preference::DigestRequired->throw(
377
            . ' for '.$attr->message_name.'.',
380
                    error => 'Digest must be selected for '.$attr->message_name.'.',
378
            parameter => 'wants_digest',
381
                    message_name => $attr->message_name
379
        ) if $transports->count == 0;
382
                );
383
            } else {
384
                Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable->throw(
385
                    error => 'Digest cannot be selected for '.$attr->message_name.'.',
386
                    message_name => $attr->message_name
387
                );
388
            }
389
        }
380
    }
390
    }
381
391
382
    return $self;
392
    return $self;
Lines 398-407 sub _set_message_transport_types { Link Here
398
                message_transport_type => $type
408
                message_transport_type => $type
399
            });
409
            });
400
            unless ($transport) {
410
            unless ($transport) {
401
                Koha::Exceptions::BadParameter->throw(
411
                Koha::Exceptions::Patron::Message::Preference::NoTransportType->throw(
402
                    error => 'No transport configured for '.$self->message_name.
412
                    error => 'No transport configured for '.$self->message_name.
403
                        " transport type $type.",
413
                        " transport type $type.",
404
                    parameter => 'message_transport_types'
414
                    message_name => $self->message_name,
415
                    transport_type => $type,
405
                );
416
                );
406
            }
417
            }
407
            if (defined $self->borrowernumber) {
418
            if (defined $self->borrowernumber) {
Lines 409-427 sub _set_message_transport_types { Link Here
409
                if ($type eq 'email') {
420
                if ($type eq 'email') {
410
                    if ( !$patron->email )
421
                    if ( !$patron->email )
411
                    {
422
                    {
412
                        Koha::Exceptions::BadParameter->throw(
423
                        Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired->throw(
413
                            error => 'Patron has not set email address, '.
424
                            error => 'Patron has not set email address, '.
414
                                     'cannot use email as message transport',
425
                                     'cannot use email as message transport',
415
                            parameter => 'message_transport_types'
426
                            message_name => $self->message_name,
427
                            borrowernumber => $self->borrowernumber,
416
                        );
428
                        );
417
                    }
429
                    }
418
                }
430
                }
419
                elsif ($type eq 'sms') {
431
                elsif ($type eq 'sms') {
420
                    if ( !$patron->smsalertnumber ){
432
                    if ( !$patron->smsalertnumber ){
421
                        Koha::Exceptions::BadParameter->throw(
433
                        Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
422
                            error => 'Patron has not set sms number, '.
434
                            error => 'Patron has not set SMS number'.
423
                                     'cannot set sms as message transport',
435
                                     'cannot use sms as message transport',
424
                            parameter => 'message_transport_types'
436
                            message_name => $self->message_name,
437
                            borrowernumber => $self->borrowernumber,
425
                        );
438
                        );
426
                    }
439
                    }
427
                }
440
                }
Lines 446-454 sub _validate_message_transport_types { Link Here
446
            unless (Koha::Patron::Message::Transport::Types->find({
459
            unless (Koha::Patron::Message::Transport::Types->find({
447
                message_transport_type => $type
460
                message_transport_type => $type
448
            })) {
461
            })) {
449
                Koha::Exceptions::BadParameter->throw(
462
                Koha::Exceptions::Patron::Message::Transport::TypeNotFound->throw(
450
                    error => "Message transport type '$type' does not exist",
463
                    error => "Message transport type '$type' does not exist",
451
                    parameter => 'message_transport_types',
464
                    transport_type => $type,
452
                );
465
                );
453
            }
466
            }
454
        }
467
        }
(-)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