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

(-)a/C4/SMS.pm (-1 / +14 lines)
Lines 129-137 sub send_sms { Link Here
129
            %args,
129
            %args,
130
        );
130
        );
131
131
132
        my $default_country_code = C4::Context->preference("SMSSendDefaultCountryCode");
133
        my $destination = $params->{destination};
134
135
        # Default country code set and is local phone number
136
        if ($default_country_code && $destination =~ /^[^+]/) {
137
            # Ensure country code has leading '+'
138
            $default_country_code =~ s/^[^+]/+$&/;
139
            # Strip leading zeroes
140
            $destination =~ s/^0+//;
141
            # Prepend default country code
142
            $destination = $default_country_code . $destination;
143
        }
144
132
        # Send a message
145
        # Send a message
133
        $sent = $sender->send_sms(
146
        $sent = $sender->send_sms(
134
            to   => $params->{destination},
147
            to   => $destination,
135
            text => $params->{message},
148
            text => $params->{message},
136
        );
149
        );
137
    };
150
    };
(-)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 759-764 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
759
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
759
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
760
('SlipCSS','',NULL,'Slips CSS url.','free'),
760
('SlipCSS','',NULL,'Slips CSS url.','free'),
761
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
761
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
762
('SMSSendDefaultCountryCode ',NULL,NULL,'Default SMS::Send driver recipient phone number country code','Integer'),
762
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
763
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
763
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
764
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
764
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
765
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+5 lines)
Lines 254-259 Patrons: Link Here
254
         - pref: SMSSendMaxChar
254
         - pref: SMSSendMaxChar
255
           class: integer
255
           class: integer
256
         - "characters (no limitation if empty)."
256
         - "characters (no limitation if empty)."
257
     -
258
         - "Prepend the country code"
259
         - pref: SMSSendDefaultCountryCode
260
         - class: integer
261
         - "for SMS::Driver recipient phone numbers. The country code shound not include a leading \"+\"."
257
     -
262
     -
258
         - "Define a username/login"
263
         - "Define a username/login"
259
         - pref: SMSSendUsername
264
         - pref: SMSSendUsername
(-)a/t/SMS.t (-1 / +30 lines)
Lines 17-31 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::NoWarnings;
25
use Test::NoWarnings;
23
use Test::More tests => 9;
26
27
use Test::More tests => 11;
24
28
25
BEGIN {
29
BEGIN {
26
    use_ok( 'C4::SMS', qw( driver send_sms ) );
30
    use_ok( 'C4::SMS', qw( driver send_sms ) );
27
}
31
}
28
32
33
t::lib::Mocks::mock_preference('SMSSendDefaultCountryCode', '');
34
29
my $driver = 'my mock driver';
35
my $driver = 'my mock driver';
30
t::lib::Mocks::mock_preference( 'SMSSendDriver', $driver );
36
t::lib::Mocks::mock_preference( 'SMSSendDriver', $driver );
31
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
37
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
Lines 69-71 is( $error, 'SMS_SEND_DRIVER_MISSING', 'Error code returned is SMS_SEND_DRIVE Link Here
69
);
75
);
70
is( $send_sms, 1, 'send_sms returns 1' );
76
is( $send_sms, 1, 'send_sms returns 1' );
71
77
78
79
t::lib::Mocks::mock_preference('SMSSendDriver', 'KohaTest');
80
t::lib::Mocks::mock_preference('SMSSendDefaultCountryCode', '46');
81
82
my $driver_arguments = C4::SMS->send_sms({
83
    destination => '+33123456789',
84
    message => 'my message'
85
});
86
87
is( $driver_arguments->{to},
88
    '+33123456789',
89
    'country code has been preserved when SMSSendDefaultCountryCode is set and destination is international phone number'
90
);
91
92
$driver_arguments = C4::SMS->send_sms({
93
    destination => '0123456789',
94
    message => 'my message'
95
});
96
97
is( $driver_arguments->{to},
98
    '+46123456789',
99
    'default country code has been prepended when SMSSendDefaultCountryCode is set and destination is non international phone number'
100
);
(-)a/t/lib/SMS/Send/KohaTest.pm (-1 / +45 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
11
  my $send = SMS::Send->new( 'KohaTest' )
12
  $message = $send->send_sms(
13
      text => 'Hi there',
14
      to   => '+61 (4) 1234 5678',
15
  )
16
17
=head1 DESCRIPTION
18
19
When writing tests for L<C4::SMS> we are unable to trap messages using the
20
L<SMS::Send::Test> driver since the L<SMS::Send> instance cannot be accessed
21
directly. We do however have access to the return value of the driver's
22
send_sms method, so by returning the incoming arguments here we are able
23
verify these have been set correctly.
24
25
=cut
26
27
use 5.006;
28
use strict;
29
use parent 'SMS::Send::Driver';
30
31
sub new {
32
    my $class = shift;
33
    my $self = bless {
34
    }, $class;
35
    $self;
36
}
37
38
sub send_sms {
39
    # Shift $self
40
    shift;
41
    use Data::Dumper;
42
    # Return arguments
43
    return { @_ };
44
}
45
1;

Return to bug 36022