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

(-)a/C4/Letters.pm (+6 lines)
Lines 1008-1013 sub SendQueuedMessages { Link Here
1008
    my $params = shift;
1008
    my $params = shift;
1009
1009
1010
    my $which_unsent_messages  = {
1010
    my $which_unsent_messages  = {
1011
        'message_id'     => $params->{'message_id'},
1011
        'limit'          => $params->{'limit'} // 0,
1012
        'limit'          => $params->{'limit'} // 0,
1012
        'borrowernumber' => $params->{'borrowernumber'} // q{},
1013
        'borrowernumber' => $params->{'borrowernumber'} // q{},
1013
        'letter_code'    => $params->{'letter_code'} // q{},
1014
        'letter_code'    => $params->{'letter_code'} // q{},
Lines 1263-1268 sub _add_attachments { Link Here
1263
   message_transport_type: method of message sending (e.g. email, sms, etc.)
1264
   message_transport_type: method of message sending (e.g. email, sms, etc.)
1264
   borrowernumber        : who the message is to be sent
1265
   borrowernumber        : who the message is to be sent
1265
   letter_code           : type of message being sent (e.g. PASSWORD_RESET)
1266
   letter_code           : type of message being sent (e.g. PASSWORD_RESET)
1267
   message_id            : the message_id of the message. In that case the sub will return only 1 result
1266
   limit                 : maximum number of messages to send
1268
   limit                 : maximum number of messages to send
1267
1269
1268
  This function returns an array of matching hash referenced rows from
1270
  This function returns an array of matching hash referenced rows from
Lines 1299-1304 sub _get_unsent_messages { Link Here
1299
            $statement .= ' AND message_transport_type = ? ';
1301
            $statement .= ' AND message_transport_type = ? ';
1300
            push @query_params, $params->{'type'};
1302
            push @query_params, $params->{'type'};
1301
        }
1303
        }
1304
        if ( $params->{message_id} ) {
1305
            $statement .= ' AND message_id = ?';
1306
            push @query_params, $params->{message_id};
1307
        }
1302
        if ( $params->{'limit'} ) {
1308
        if ( $params->{'limit'} ) {
1303
            $statement .= ' limit ? ';
1309
            $statement .= ' limit ? ';
1304
            push @query_params, $params->{'limit'};
1310
            push @query_params, $params->{'limit'};
(-)a/t/db_dependent/Letters.t (-2 / +49 lines)
Lines 18-26 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 83;
21
use Test::More tests => 84;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
25
25
use Email::Sender::Failure;
26
use Email::Sender::Failure;
26
27
Lines 958-960 subtest 'Test limit parameter for SendQueuedMessages' => sub { Link Here
958
    is( $messages_processed, 2,
959
    is( $messages_processed, 2,
959
        'Processed 2 message with limit of 3 and 2 unprocessed messages' );
960
        'Processed 2 message with limit of 3 and 2 unprocessed messages' );
960
};
961
};
961
- 
962
963
subtest 'Test message_id parameter for SendQueuedMessages' => sub {
964
965
    plan tests => 5;
966
967
    my $dbh = C4::Context->dbh;
968
969
    my $borrowernumber = Koha::Patron->new({
970
        firstname    => 'Jane',
971
        surname      => 'Smith',
972
        categorycode => $patron_category,
973
        branchcode   => $library->{branchcode},
974
        dateofbirth  => $date,
975
        smsalertnumber => undef,
976
    })->store->borrowernumber;
977
978
    $dbh->do(q|DELETE FROM message_queue|);
979
    $my_message = {
980
        'letter' => {
981
            'content'      => 'a message',
982
            'metadata'     => 'metadata',
983
            'code'         => 'TEST_MESSAGE',
984
            'content_type' => 'text/plain',
985
            'title'        => 'message title'
986
        },
987
        'borrowernumber'         => $borrowernumber,
988
        'to_address'             => 'to@example.org',
989
        'message_transport_type' => 'email',
990
        'from_address'           => 'root@localhost' # invalid KohaAdminEmailAddress
991
    };
992
    my $message_id = C4::Letters::EnqueueLetter($my_message);
993
    throws_ok {
994
        C4::Letters::SendQueuedMessages( { message_id => $message_id } );
995
    } 'Koha::Exceptions::BadParameter',
996
    'Exception thrown if invalid email is passed';
997
    my $message_1 = C4::Letters::GetMessage($message_id);
998
    # FIXME must be 'failed'
999
    is( $message_1->{status}, 'pending', 'Invalid KohaAdminEmailAddress => status pending' );
1000
1001
    $my_message->{from_address} = 'root@example.org'; # valid KohaAdminEmailAddress
1002
    $message_id = C4::Letters::EnqueueLetter($my_message);
1003
    C4::Letters::SendQueuedMessages( { message_id => $message_id } );
1004
    $message_1 = C4::Letters::GetMessage($message_1->{message_id});
1005
    my $message_2 = C4::Letters::GetMessage($message_id);
1006
    is( $message_1->{status}, 'pending', 'Message 1 status is unchanged' ); # Must be 'failed'
1007
    is( $message_2->{status}, 'sent', 'Valid KohaAdminEmailAddress => status sent' );
1008
};

Return to bug 27860