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

(-)a/Koha/Exceptions/Patron/Message/Preference.pm (+10 lines)
Lines 57-67 use Exception::Class ( Link Here
57
        description => "Transport type not available for this message.",
57
        description => "Transport type not available for this message.",
58
        fields => ['message_name', 'transport_type']
58
        fields => ['message_name', 'transport_type']
59
    },
59
    },
60
    'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired' => {
61
        isa => 'Koha::Exceptions::Patron::Message::Preference',
62
        description => "Patron has no phone number, cannot use phone transport type.",
63
        fields => ['message_name', 'borrowernumber' ]
64
    },
60
    'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired' => {
65
    'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired' => {
61
        isa => 'Koha::Exceptions::Patron::Message::Preference',
66
        isa => 'Koha::Exceptions::Patron::Message::Preference',
62
        description => "Patron has no SMS number, cannot use sms transport type.",
67
        description => "Patron has no SMS number, cannot use sms transport type.",
63
        fields => ['message_name', 'borrowernumber' ]
68
        fields => ['message_name', 'borrowernumber' ]
64
    },
69
    },
70
    'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired' => {
71
        isa => 'Koha::Exceptions::Patron::Message::Preference',
72
        description => "System preference TalkingTechItivaPhoneNotification is disabled, cannot use itiva transport type.",
73
        fields => ['message_name', 'borrowernumber' ]
74
    },
65
);
75
);
66
76
67
1;
77
1;
(-)a/Koha/Patron/Message/Preference.pm (+21 lines)
Lines 419-424 sub _set_message_transport_types { Link Here
419
                        );
419
                        );
420
                    }
420
                    }
421
                }
421
                }
422
                elsif ($type eq 'itiva') {
423
                    if (!C4::Context->preference('TalkingTechItivaPhoneNotification')) {
424
                        Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired->throw(
425
                            error => 'System preference TalkingTechItivaPhoneNotification disabled'.
426
                                     'cannot use itiva as message transport',
427
                            message_name => $self->message_name,
428
                            borrowernumber => $self->borrowernumber,
429
                        );
430
                    }
431
                }
432
                elsif ($type eq 'phone') {
433
                    if ( !$patron->phone ) {
434
                        Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired->throw(
435
                            error => 'Patron has not set phone number'.
436
                                     'cannot use phone as message transport',
437
                            message_name => $self->message_name,
438
                            borrowernumber => $self->borrowernumber,
439
                        );
440
                    }
441
442
                }
422
                elsif ($type eq 'sms') {
443
                elsif ($type eq 'sms') {
423
                    if ( !$patron->smsalertnumber ){
444
                    if ( !$patron->smsalertnumber ){
424
                        Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
445
                        Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw(
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-4 / +40 lines)
Lines 282-288 HERE Link Here
282
    };
282
    };
283
283
284
    subtest 'set message_transport_types' => sub {
284
    subtest 'set message_transport_types' => sub {
285
        plan tests => 12;
285
        plan tests => 18;
286
286
287
        $schema->storage->txn_begin;
287
        $schema->storage->txn_begin;
288
288
Lines 339-349 HERE Link Here
339
        });
339
        });
340
        is($stored_transports->count, 2, 'Two transports selected');
340
        is($stored_transports->count, 2, 'Two transports selected');
341
341
342
        # Test email and smsalertnumber validation
342
        # Test contact information validation
343
        eval { Koha::Patron::Message::Transport::Types->new({
343
        eval { Koha::Patron::Message::Transport::Types->new({
344
                message_transport_type => 'email'
344
                message_transport_type => 'email'
345
            })->store };
345
            })->store };
346
        eval { Koha::Patron::Message::Transport::Types->new({
346
        eval { Koha::Patron::Message::Transport::Types->new({
347
                message_transport_type => 'itiva'
348
            })->store };
349
        eval { Koha::Patron::Message::Transport::Types->new({
350
                message_transport_type => 'phone'
351
            })->store };
352
        eval { Koha::Patron::Message::Transport::Types->new({
347
                message_transport_type => 'sms'
353
                message_transport_type => 'sms'
348
            })->store };
354
            })->store };
349
        Koha::Patron::Message::Transport->new({
355
        Koha::Patron::Message::Transport->new({
Lines 353-362 HERE Link Here
353
        })->store;
359
        })->store;
354
        Koha::Patron::Message::Transport->new({
360
        Koha::Patron::Message::Transport->new({
355
            message_attribute_id   => $preference->message_attribute_id,
361
            message_attribute_id   => $preference->message_attribute_id,
362
            message_transport_type => 'itiva',
363
            is_digest              => 1
364
        })->store;
365
        Koha::Patron::Message::Transport->new({
366
            message_attribute_id   => $preference->message_attribute_id,
367
            message_transport_type => 'phone',
368
            is_digest              => 1
369
        })->store;
370
        Koha::Patron::Message::Transport->new({
371
            message_attribute_id   => $preference->message_attribute_id,
356
            message_transport_type => 'sms',
372
            message_transport_type => 'sms',
357
            is_digest              => 1
373
            is_digest              => 1
358
        })->store;
374
        })->store;
359
        $patron->set({ email => '', smsalertnumber => '' })->store;
375
        t::lib::Mocks::mock_preference('TalkingTechItivaPhoneNotification', 0);
376
        $patron->set({ email => '', phone => '', smsalertnumber => '' })->store;
360
        eval {
377
        eval {
361
            $preference->message_transport_types('email')->store;
378
            $preference->message_transport_types('email')->store;
362
        };
379
        };
Lines 368-373 HERE Link Here
368
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
385
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
369
            .' tells us which patron it was.');
386
            .' tells us which patron it was.');
370
        eval {
387
        eval {
388
            $preference->message_transport_types('itiva')->store;
389
        };
390
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired',
391
            'Adding a message preference with invalid message_transport_type'
392
            .' => Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired');
393
        is ($@->message_name, $preference->message_name, 'The previous exception '
394
            .' tells us it which message name it was.');
395
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
396
            .' tells us which patron it was.');
397
        eval {
398
            $preference->message_transport_types('phone')->store;
399
        };
400
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired',
401
            'Adding a message preference with invalid message_transport_type'
402
            .' => Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired');
403
        is ($@->message_name, $preference->message_name, 'The previous exception '
404
            .' tells us it which message name it was.');
405
        is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception '
406
            .' tells us which patron it was.');
407
        eval {
371
            $preference->message_transport_types('sms')->store;
408
            $preference->message_transport_types('sms')->store;
372
        };
409
        };
373
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired',
410
        is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired',
374
- 

Return to bug 17499