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

(-)a/C4/SMS.pm (-1 / +14 lines)
Lines 116-124 sub send_sms { Link Here
116
            %args,
116
            %args,
117
        );
117
        );
118
118
119
        my $default_country_code = C4::Context->preference("SMSSendDefaultCountryCode");
120
        my $destination = $params->{destination};
121
122
        # Default country code set and is local phone number
123
        if ($default_country_code && $destination =~ /^[^+]/) {
124
            # Ensure country code has leading '+'
125
            $default_country_code =~ s/^[^+]/+$&/;
126
            # Strip leading zeroes
127
            $destination =~ s/^0+//;
128
            # Prepend default country code
129
            $destination = $default_country_code . $destination;
130
        }
131
119
        # Send a message
132
        # Send a message
120
        $sent = $sender->send_sms(
133
        $sent = $sender->send_sms(
121
            to   => $params->{destination},
134
            to   => $destination,
122
            text => $params->{message},
135
            text => $params->{message},
123
        );
136
        );
124
    };
137
    };
(-)a/installer/data/mysql/atomicupdate/bug-36022-add-SMSSendDefaultCountryCode-syspref.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "36022",
5
    description => "Add SMSSendDefaultCountryCode system preference",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('SMSSendDefaultCountryCode ', NULL, NULL, 'Default SMS::Send driver recipient phone number country code', 'Integer') });
11
        # sysprefs
12
        say $out "Added new system preference 'SMSSendDefaultCountryCode'";
13
    },
14
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 680-685 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
680
('SIP2SortBinMapping','',NULL,'Use the following mappings to determine the sort_bin of a returned item. The mapping should be on the form \"branchcode:item field:item field value:sort bin number\", with one mapping per line.','free'),
680
('SIP2SortBinMapping','',NULL,'Use the following mappings to determine the sort_bin of a returned item. The mapping should be on the form \"branchcode:item field:item field value:sort bin number\", with one mapping per line.','free'),
681
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
681
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
682
('SlipCSS','',NULL,'Slips CSS url.','free'),
682
('SlipCSS','',NULL,'Slips CSS url.','free'),
683
('SMSSendDefaultCountryCode ',NULL,NULL,'Default SMS::Send driver recipient phone number country code','Integer'),
683
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
684
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
684
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
685
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
685
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
686
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+5 lines)
Lines 217-222 Patrons: Link Here
217
         - driver to send SMS messages.
217
         - driver to send SMS messages.
218
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
218
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
219
         - "<br><strong>NOTE:</strong> Many mobile providers have deprecated support for this feature and it is not recommended for use unless you have a dedicated SMS to Email gateway."
219
         - "<br><strong>NOTE:</strong> Many mobile providers have deprecated support for this feature and it is not recommended for use unless you have a dedicated SMS to Email gateway."
220
     -
221
         - "Prepend the country code"
222
         - pref: SMSSendDefaultCountryCode
223
         - class: integer
224
         - "for SMS::Driver recipient phone numbers. The country code shound not include a leading \"+\"."
220
     -
225
     -
221
         - "Define a username/login"
226
         - "Define a username/login"
222
         - pref: SMSSendUsername
227
         - pref: SMSSendUsername
(-)a/t/SMS.t (-1 / +28 lines)
Lines 17-30 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use FindBin;
21
use lib "$FindBin::Bin/lib";
22
20
use t::lib::Mocks;
23
use t::lib::Mocks;
21
24
22
use Test::More tests => 7;
25
use Test::More tests => 9;
23
26
24
BEGIN {
27
BEGIN {
25
    use_ok('C4::SMS', qw( driver send_sms ));
28
    use_ok('C4::SMS', qw( driver send_sms ));
26
}
29
}
27
30
31
t::lib::Mocks::mock_preference('SMSSendDefaultCountryCode', '');
28
32
29
my $driver = 'my mock driver';
33
my $driver = 'my mock driver';
30
t::lib::Mocks::mock_preference('SMSSendDriver', $driver);
34
t::lib::Mocks::mock_preference('SMSSendDriver', $driver);
Lines 60-62 $send_sms = C4::SMS->send_sms({ Link Here
60
});
64
});
61
is( $send_sms, 1, 'send_sms returns 1' );
65
is( $send_sms, 1, 'send_sms returns 1' );
62
66
67
68
t::lib::Mocks::mock_preference('SMSSendDriver', 'KohaTest');
69
t::lib::Mocks::mock_preference('SMSSendDefaultCountryCode', '46');
70
71
my $driver_arguments = C4::SMS->send_sms({
72
    destination => '+33123456789',
73
    message => 'my message'
74
});
75
76
is( $driver_arguments->{to},
77
    '+33123456789',
78
    'country code has been preserved when SMSSendDefaultCountryCode is set and destination is international phone number'
79
);
80
81
$driver_arguments = C4::SMS->send_sms({
82
    destination => '0123456789',
83
    message => 'my message'
84
});
85
86
is( $driver_arguments->{to},
87
    '+46123456789',
88
    'default country code has been prepended when SMSSendDefaultCountryCode is set and destination is non international phone number'
89
);
(-)a/t/lib/SMS/Send/KohaTest.pm (-1 / +42 lines)
Line 0 Link Here
0
- 
1
package SMS::Send::KohaTest;
2
3
=pod
4
5
=head1 NAME
6
7
SMS::Send::KohaTest - SMS::Sent Testing Driver for C4::SMS tests
8
9
=head1 SYNOPSIS
10
  my $send = SMS::Send->new( 'KohaTest' )
11
  $message = $send->send_sms(
12
      text => 'Hi there',
13
      to   => '+61 (4) 1234 5678',
14
  )
15
16
=head1 DESCRIPTION
17
When writing tests for L<C4::SMS> we are unable to trap messages using the
18
L<SMS::Send::Test> driver since the L<SMS::Send> instance cannot be accessed
19
directly. We do however have access to the return value of the driver's
20
send_sms method, so by returning the incoming arguments here we are able
21
verify these have been set correctly.
22
=cut
23
24
use 5.006;
25
use strict;
26
use parent 'SMS::Send::Driver';
27
28
sub new {
29
    my $class = shift;
30
    my $self = bless {
31
    }, $class;
32
    $self;
33
}
34
35
sub send_sms {
36
    # Shift $self
37
    shift;
38
    use Data::Dumper;
39
    # Return arguments
40
    return { @_ };
41
}
42
1;

Return to bug 36022