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

(-)a/C4/SMS.pm (-1 / +14 lines)
Lines 128-136 sub send_sms { Link Here
128
            %args,
128
            %args,
129
        );
129
        );
130
130
131
        my $default_country_code = C4::Context->preference("SMSSendDefaultCountryCode");
132
        my $destination = $params->{destination};
133
134
        # Default country code set and is local phone number
135
        if ($default_country_code && $destination =~ /^[^+]/) {
136
            # Ensure country code has leading '+'
137
            $default_country_code =~ s/^[^+]/+$&/;
138
            # Strip leading zeroes
139
            $destination =~ s/^0+//;
140
            # Prepend default country code
141
            $destination = $default_country_code . $destination;
142
        }
143
131
        # Send a message
144
        # Send a message
132
        $sent = $sender->send_sms(
145
        $sent = $sender->send_sms(
133
            to   => $params->{destination},
146
            to   => $destination,
134
            text => $params->{message},
147
            text => $params->{message},
135
        );
148
        );
136
    };
149
    };
(-)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 739-744 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
739
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
739
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
740
('SlipCSS','',NULL,'Slips CSS url.','free'),
740
('SlipCSS','',NULL,'Slips CSS url.','free'),
741
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
741
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
742
('SMSSendDefaultCountryCode ',NULL,NULL,'Default SMS::Send driver recipient phone number country code','Integer'),
742
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
743
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
743
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
744
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
744
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
745
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+5 lines)
Lines 245-250 Patrons: Link Here
245
         - pref: SMSSendMaxChar
245
         - pref: SMSSendMaxChar
246
           class: integer
246
           class: integer
247
         - "characters (no limitation if empty)."
247
         - "characters (no limitation if empty)."
248
     -
249
         - "Prepend the country code"
250
         - pref: SMSSendDefaultCountryCode
251
         - class: integer
252
         - "for SMS::Driver recipient phone numbers. The country code shound not include a leading \"+\"."
248
     -
253
     -
249
         - "Define a username/login"
254
         - "Define a username/login"
250
         - pref: SMSSendUsername
255
         - pref: SMSSendUsername
(-)a/t/SMS.t (-1 / +29 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 => 8;
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', '');
32
28
my $driver = 'my mock driver';
33
my $driver = 'my mock driver';
29
t::lib::Mocks::mock_preference( 'SMSSendDriver', $driver );
34
t::lib::Mocks::mock_preference( 'SMSSendDriver', $driver );
30
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
35
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
Lines 68-70 is( $error, 'SMS_SEND_DRIVER_MISSING', 'Error code returned is SMS_SEND_DRIVE Link Here
68
);
73
);
69
is( $send_sms, 1, 'send_sms returns 1' );
74
is( $send_sms, 1, 'send_sms returns 1' );
70
75
76
77
t::lib::Mocks::mock_preference('SMSSendDriver', 'KohaTest');
78
t::lib::Mocks::mock_preference('SMSSendDefaultCountryCode', '46');
79
80
my $driver_arguments = C4::SMS->send_sms({
81
    destination => '+33123456789',
82
    message => 'my message'
83
});
84
85
is( $driver_arguments->{to},
86
    '+33123456789',
87
    'country code has been preserved when SMSSendDefaultCountryCode is set and destination is international phone number'
88
);
89
90
$driver_arguments = C4::SMS->send_sms({
91
    destination => '0123456789',
92
    message => 'my message'
93
});
94
95
is( $driver_arguments->{to},
96
    '+46123456789',
97
    'default country code has been prepended when SMSSendDefaultCountryCode is set and destination is non international phone number'
98
);
(-)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