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

(-)a/Koha/Exceptions/Patron.pm (-1 / +5 lines)
Lines 18-24 use Exception::Class ( Link Here
18
        isa         => 'Koha::Exceptions::Patron',
18
        isa         => 'Koha::Exceptions::Patron',
19
        description => "Mandatory extended attribute missing",
19
        description => "Mandatory extended attribute missing",
20
        fields      => ['type']
20
        fields      => ['type']
21
    }
21
    },
22
    'Koha::Exceptions::Patron::NotFound' => {
23
        isa => 'Koha::Exceptions::Patron',
24
        description => "Patron not found"
25
    },
22
);
26
);
23
27
24
sub full_message {
28
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 285-300 sub store { Link Here
285
288
286
Makes a basic validation for object.
289
Makes a basic validation for object.
287
290
288
Throws following exceptions regarding parameters.
291
Returns Koha::Patron::Message::Preference object, or throws and exception.
289
- Koha::Exceptions::MissingParameter
290
- Koha::Exceptions::TooManyParameters
291
- Koha::Exceptions::BadParameter
292
293
See $_->parameter to identify the parameter causing the exception.
294
295
Throws Koha::Exceptions::DuplicateObject if this preference already exists.
296
297
Returns Koha::Patron::Message::Preference object.
298
292
299
=cut
293
=cut
300
294
Lines 314-328 sub validate { Link Here
314
        );
308
        );
315
    }
309
    }
316
    if ($self->borrowernumber) {
310
    if ($self->borrowernumber) {
317
        Koha::Exceptions::BadParameter->throw(
311
        Koha::Exceptions::Patron::NotFound->throw(
318
            error => 'Patron not found.',
312
            error => 'Patron not found.',
319
            parameter => 'borrowernumber',
320
        ) unless Koha::Patrons->find($self->borrowernumber);
313
        ) unless Koha::Patrons->find($self->borrowernumber);
321
    }
314
    }
322
    if ($self->categorycode) {
315
    if ($self->categorycode) {
323
        Koha::Exceptions::BadParameter->throw(
316
        Koha::Exceptions::Patron::Category::NotFound->throw(
324
            error => 'Category not found.',
317
            error => 'Category not found.',
325
            parameter => 'categorycode',
326
        ) unless Koha::Patron::Categories->find($self->categorycode);
318
        ) unless Koha::Patron::Categories->find($self->categorycode);
327
    }
319
    }
328
320
Lines 344-368 sub validate { Link Here
344
        $self->message_attribute_id
336
        $self->message_attribute_id
345
    );
337
    );
346
    unless ($attr) {
338
    unless ($attr) {
347
        Koha::Exceptions::BadParameter->throw(
339
        Koha::Exceptions::Patron::Message::Preference::AttributeNotFound->throw(
348
            error => 'Message attribute with id '.$self->message_attribute_id
340
            error => 'Message attribute with id '.$self->message_attribute_id
349
            .' not found',
341
            .' not found',
350
            parameter => 'message_attribute_id'
342
            message_attribute_id => $self->message_attribute_id,
351
        );
343
        );
352
    }
344
    }
353
    if (defined $self->days_in_advance) {
345
    if (defined $self->days_in_advance) {
354
        if ($attr && $attr->takes_days == 0) {
346
        if ($attr && $attr->takes_days == 0) {
355
            Koha::Exceptions::BadParameter->throw(
347
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable->throw(
356
                error => 'days_in_advance cannot be defined for '.
348
                error => 'days_in_advance cannot be defined for '.
357
                $attr->message_name . '.',
349
                $attr->message_name . '.',
358
                parameter => 'days_in_advance',
350
                message_name => $attr->message_name,
359
            );
351
            );
360
        }
352
        }
361
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
353
        elsif ($self->days_in_advance < 0 || $self->days_in_advance > 30) {
362
            Koha::Exceptions::BadParameter->throw(
354
            Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange->throw(
363
                error => 'days_in_advance has to be a value between 0-30 for '.
355
                error => 'days_in_advance has to be a value between 0-30 for '.
364
                $attr->message_name . '.',
356
                $attr->message_name . '.',
365
                parameter => 'days_in_advance',
357
                message_name => $attr->message_name,
358
                min => 0,
359
                max => 30,
366
            );
360
            );
367
        }
361
        }
368
    }
362
    }
Lines 371-382 sub validate { Link Here
371
            message_attribute_id => $self->message_attribute_id,
365
            message_attribute_id => $self->message_attribute_id,
372
            is_digest            => $self->wants_digest ? 1 : 0,
366
            is_digest            => $self->wants_digest ? 1 : 0,
373
        });
367
        });
374
        Koha::Exceptions::BadParameter->throw(
368
        unless ($transports->count) {
375
            error => (!$self->wants_digest ? 'Digest must be selected'
369
            if (!$self->wants_digest) {
376
                                           : 'Digest cannot be selected')
370
                Koha::Exceptions::Patron::Message::Preference::DigestRequired->throw(
377
            . ' for '.$attr->message_name.'.',
371
                    error => 'Digest must be selected for '.$attr->message_name.'.',
378
            parameter => 'wants_digest',
372
                    message_name => $attr->message_name
379
        ) if $transports->count == 0;
373
                );
374
            } else {
375
                Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable->throw(
376
                    error => 'Digest cannot be selected for '.$attr->message_name.'.',
377
                    message_name => $attr->message_name
378
                );
379
            }
380
        }
380
    }
381
    }
381
382
382
    return $self;
383
    return $self;
Lines 398-407 sub _set_message_transport_types { Link Here
398
                message_transport_type => $type
399
                message_transport_type => $type
399
            });
400
            });
400
            unless ($transport) {
401
            unless ($transport) {
401
                Koha::Exceptions::BadParameter->throw(
402
                Koha::Exceptions::Patron::Message::Preference::NoTransportType->throw(
402
                    error => 'No transport configured for '.$self->message_name.
403
                    error => 'No transport configured for '.$self->message_name.
403
                        " transport type $type.",
404
                        " transport type $type.",
404
                    parameter => 'message_transport_types'
405
                    message_name => $self->message_name,
406
                    transport_type => $type,
405
                );
407
                );
406
            }
408
            }
407
            if (defined $self->borrowernumber) {
409
            if (defined $self->borrowernumber) {
Lines 409-427 sub _set_message_transport_types { Link Here
409
                if ($type eq 'email') {
411
                if ($type eq 'email') {
410
                    if ( !$patron->email )
412
                    if ( !$patron->email )
411
                    {
413
                    {
412
                        Koha::Exceptions::BadParameter->throw(
414
                        Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired->throw(
413
                            error => 'Patron has not set email address, '.
415
                            error => 'Patron has not set email address, '.
414
                                     'cannot use email as message transport',
416
                                     'cannot use email as message transport',
415
                            parameter => 'message_transport_types'
417
                            message_name => $self->message_name,
418
                            borrowernumber => $self->borrowernumber,
416
                        );
419
                        );
417
                    }
420
                    }
418
                }
421
                }
419
                elsif ($type eq 'sms') {
422
                elsif ($type eq 'sms') {
420
                    if ( !$patron->smsalertnumber ){
423
                    if ( !$patron->smsalertnumber ){
421
                        Koha::Exceptions::BadParameter->throw(
424
                        Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
422
                            error => 'Patron has not set sms number, '.
425
                            error => 'Patron has not set SMS number'.
423
                                     'cannot set sms as message transport',
426
                                     'cannot use sms as message transport',
424
                            parameter => 'message_transport_types'
427
                            message_name => $self->message_name,
428
                            borrowernumber => $self->borrowernumber,
425
                        );
429
                        );
426
                    }
430
                    }
427
                }
431
                }
Lines 446-454 sub _validate_message_transport_types { Link Here
446
            unless (Koha::Patron::Message::Transport::Types->find({
450
            unless (Koha::Patron::Message::Transport::Types->find({
447
                message_transport_type => $type
451
                message_transport_type => $type
448
            })) {
452
            })) {
449
                Koha::Exceptions::BadParameter->throw(
453
                Koha::Exceptions::Patron::Message::Transport::TypeNotFound->throw(
450
                    error => "Message transport type '$type' does not exist",
454
                    error => "Message transport type '$type' does not exist",
451
                    parameter => 'message_transport_types',
455
                    transport_type => $type,
452
                );
456
                );
453
            }
457
            }
454
        }
458
        }
(-)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