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

(-)a/C4/Letters.pm (-74 / +126 lines)
Lines 20-32 package C4::Letters; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use MIME::Lite;
22
use MIME::Lite;
23
use Mail::Sendmail;
24
use Date::Calc qw( Add_Delta_Days );
23
use Date::Calc qw( Add_Delta_Days );
25
use Encode;
24
use Encode;
26
use Carp;
25
use Carp;
27
use Template;
26
use Template;
28
use Module::Load::Conditional qw(can_load);
27
use Module::Load::Conditional qw(can_load);
29
28
29
use Try::Tiny;
30
30
use C4::Members;
31
use C4::Members;
31
use C4::Log;
32
use C4::Log;
32
use C4::SMS;
33
use C4::SMS;
Lines 39-44 use Koha::Notice::Messages; Link Here
39
use Koha::Notice::Templates;
40
use Koha::Notice::Templates;
40
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::Patrons;
42
use Koha::Patrons;
43
use Koha::SMTP::Servers;
42
use Koha::Subscriptions;
44
use Koha::Subscriptions;
43
45
44
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
46
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Lines 337-364 sub SendAlerts { Link Here
337
                want_librarian => 1,
339
                want_librarian => 1,
338
            ) or return;
340
            ) or return;
339
341
340
            # ... then send mail
342
            # FIXME: This 'default' behaviour should be moved to Koha::Email
341
            my $message = Koha::Email->new();
343
            my $mail = Koha::Email->create(
342
            my %mail = $message->create_message_headers(
343
                {
344
                {
344
                    to      => $email,
345
                    to       => $email,
345
                    from    => $library->branchemail,
346
                    from     => $library->branchemail,
346
                    replyto => $library->branchreplyto,
347
                    reply_to => $library->branchreplyto,
347
                    sender  => $library->branchreturnpath,
348
                    sender   => $library->branchreturnpath,
348
                    subject => Encode::encode( "UTF-8", "" . $letter->{title} ),
349
                    subject  => "" . $letter->{title},
349
                    message => $letter->{'is_html'}
350
                                ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
351
                                              Encode::encode( "UTF-8", "" . $letter->{'title'} ))
352
                                : Encode::encode( "UTF-8", "" . $letter->{'content'} ),
353
                    contenttype => $letter->{'is_html'}
354
                                    ? 'text/html; charset="utf-8"'
355
                                    : 'text/plain; charset="utf-8"',
356
                }
350
                }
357
            );
351
            );
358
            unless( Mail::Sendmail::sendmail(%mail) ) {
352
359
                carp $Mail::Sendmail::error;
353
            if ( $letter->{is_html} ) {
360
                return { error => $Mail::Sendmail::error };
354
                $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
355
            }
356
            else {
357
                $mail->text_body( $letter->{content} );
361
            }
358
            }
359
360
            try {
361
                $mail->send_or_die({ transport => $library->smtp_server->transport });
362
            }
363
            catch {
364
                carp "$_";
365
                return { error => "$_" };
366
            };
362
        }
367
        }
363
    }
368
    }
364
    elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' or $type eq 'orderacquisition' ) {
369
    elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' or $type eq 'orderacquisition' ) {
Lines 477-484 sub SendAlerts { Link Here
477
482
478
        # ... then send mail
483
        # ... then send mail
479
        my $library = Koha::Libraries->find( $userenv->{branch} );
484
        my $library = Koha::Libraries->find( $userenv->{branch} );
480
        my $email = Koha::Email->new();
485
        my $mail = Koha::Email->create(
481
        my %mail = $email->create_message_headers(
482
            {
486
            {
483
                to => join( ',', @email ),
487
                to => join( ',', @email ),
484
                cc => join( ',', @cc ),
488
                cc => join( ',', @cc ),
Lines 487-513 sub SendAlerts { Link Here
487
                        C4::Context->preference("ClaimsBccCopy")
491
                        C4::Context->preference("ClaimsBccCopy")
488
                          && ( $type eq 'claimacquisition'
492
                          && ( $type eq 'claimacquisition'
489
                            || $type eq 'claimissues' )
493
                            || $type eq 'claimissues' )
490
                    ) ? ( bcc => $userenv->{emailaddress} )
494
                    )
495
                    ? ( bcc => $userenv->{emailaddress} )
491
                    : ()
496
                    : ()
492
                ),
497
                ),
493
                from => $library->branchemail
498
                from => $library->branchemail
494
                  || C4::Context->preference('KohaAdminEmailAddress'),
499
                  || C4::Context->preference('KohaAdminEmailAddress'),
495
                subject => Encode::encode( "UTF-8", "" . $letter->{title} ),
500
                subject => "" . $letter->{title},
496
                message => $letter->{'is_html'} ? _wrap_html(
497
                    Encode::encode( "UTF-8", $letter->{'content'} ),
498
                    Encode::encode( "UTF-8", "" . $letter->{'title'} )
499
                  )
500
                : Encode::encode( "UTF-8", "" . $letter->{'content'} ),
501
                contenttype => $letter->{'is_html'}
502
                ? 'text/html; charset="utf-8"'
503
                : 'text/plain; charset="utf-8"',
504
            }
501
            }
505
        );
502
        );
506
503
507
        unless ( Mail::Sendmail::sendmail(%mail) ) {
504
        if ( $letter->{is_html} ) {
508
            carp $Mail::Sendmail::error;
505
            $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
509
            return { error => $Mail::Sendmail::error };
510
        }
506
        }
507
        else {
508
            $mail->text_body( "" . $letter->{content} );
509
        }
510
511
        try {
512
            $mail->send_or_die({ transport => $library->smtp_server->transport });
513
        }
514
        catch {
515
            carp "$_";
516
            return { error => "$_" };
517
        };
511
518
512
        logaction(
519
        logaction(
513
            "ACQUISITION",
520
            "ACQUISITION",
Lines 523-563 sub SendAlerts { Link Here
523
    }
530
    }
524
   # send an "account details" notice to a newly created user
531
   # send an "account details" notice to a newly created user
525
    elsif ( $type eq 'members' ) {
532
    elsif ( $type eq 'members' ) {
526
        my $library = Koha::Libraries->find( $externalid->{branchcode} )->unblessed;
533
        my $library = Koha::Libraries->find( $externalid->{branchcode} );
527
        my $letter = GetPreparedLetter (
534
        my $letter = GetPreparedLetter (
528
            module => 'members',
535
            module => 'members',
529
            letter_code => $letter_code,
536
            letter_code => $letter_code,
530
            branchcode => $externalid->{'branchcode'},
537
            branchcode => $externalid->{'branchcode'},
531
            lang       => $externalid->{lang} || 'default',
538
            lang       => $externalid->{lang} || 'default',
532
            tables => {
539
            tables => {
533
                'branches'    => $library,
540
                'branches'    => $library->unblessed,
534
                'borrowers' => $externalid->{'borrowernumber'},
541
                'borrowers' => $externalid->{'borrowernumber'},
535
            },
542
            },
536
            substitute => { 'borrowers.password' => $externalid->{'password'} },
543
            substitute => { 'borrowers.password' => $externalid->{'password'} },
537
            want_librarian => 1,
544
            want_librarian => 1,
538
        ) or return;
545
        ) or return;
539
        return { error => "no_email" } unless $externalid->{'emailaddr'};
546
        return { error => "no_email" } unless $externalid->{'emailaddr'};
540
        my $email = Koha::Email->new();
547
        try {
541
        my %mail  = $email->create_message_headers(
548
542
            {
549
            # FIXME: This 'default' behaviour should be moved to Koha::Email
543
                to      => $externalid->{'emailaddr'},
550
            my $mail = Koha::Email->create(
544
                from    => $library->{branchemail},
551
                {
545
                replyto => $library->{branchreplyto},
552
                    to       => $externalid->{'emailaddr'},
546
                sender  => $library->{branchreturnpath},
553
                    from     => $library->branchemail,
547
                subject => Encode::encode( "UTF-8", "" . $letter->{'title'} ),
554
                    reply_to => $library->branchreplyto,
548
                message => $letter->{'is_html'}
555
                    sender   => $library->branchreturnpath,
549
                            ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
556
                    subject  => "" . $letter->{'title'},
550
                                          Encode::encode( "UTF-8", "" . $letter->{'title'}  ) )
557
                }
551
                            : Encode::encode( "UTF-8", "" . $letter->{'content'} ),
558
            );
552
                contenttype => $letter->{'is_html'}
559
553
                                ? 'text/html; charset="utf-8"'
560
            if ( $letter->{is_html} ) {
554
                                : 'text/plain; charset="utf-8"',
561
                $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
555
            }
562
            }
556
        );
563
            else {
557
        unless( Mail::Sendmail::sendmail(%mail) ) {
564
                $mail->text_body( $letter->{content} );
558
            carp $Mail::Sendmail::error;
565
            }
559
            return { error => $Mail::Sendmail::error };
566
567
            $mail->send_or_die({ transport => $library->smtp_server->transport });
560
        }
568
        }
569
        catch {
570
            carp "$_";
571
            return { error => "$_" };
572
        };
561
    }
573
    }
562
574
563
    # If we come here, return an OK status
575
    # If we come here, return an OK status
Lines 1296-1312 sub _send_message_by_email { Link Here
1296
    my $content = encode('UTF-8', $message->{'content'});
1308
    my $content = encode('UTF-8', $message->{'content'});
1297
    my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"';
1309
    my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"';
1298
    my $is_html = $content_type =~ m/html/io;
1310
    my $is_html = $content_type =~ m/html/io;
1311
1299
    my $branch_email = undef;
1312
    my $branch_email = undef;
1300
    my $branch_replyto = undef;
1313
    my $branch_replyto = undef;
1301
    my $branch_returnpath = undef;
1314
    my $branch_returnpath = undef;
1315
    my $library;
1316
1302
    if ($patron) {
1317
    if ($patron) {
1303
        my $library = $patron->library;
1318
        $library           = $patron->library;
1304
        $branch_email      = $library->branchemail;
1319
        $branch_email      = $library->branchemail;
1305
        $branch_replyto    = $library->branchreplyto;
1320
        $branch_replyto    = $library->branchreplyto;
1306
        $branch_returnpath = $library->branchreturnpath;
1321
        $branch_returnpath = $library->branchreturnpath;
1307
    }
1322
    }
1308
    my $email = Koha::Email->new();
1323
1309
    my %sendmail_params = $email->create_message_headers(
1324
    my $email = Koha::Email->create(
1310
        {
1325
        {
1311
            to => $to_address,
1326
            to => $to_address,
1312
            (
1327
            (
Lines 1314-1342 sub _send_message_by_email { Link Here
1314
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1329
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1315
                : ()
1330
                : ()
1316
            ),
1331
            ),
1317
            from    => $message->{'from_address'} || $branch_email,
1332
            from     => $message->{'from_address'}  || $branch_email,
1318
            replyto => $message->{'reply_address'} || $branch_replyto,
1333
            reply_to => $message->{'reply_address'} || $branch_replyto,
1319
            sender  => $branch_returnpath,
1334
            sender   => $branch_returnpath,
1320
            subject => $subject,
1335
            subject  => "" . $message->{subject}
1321
            message => $is_html ? _wrap_html( $content, $subject ) : $content,
1322
            contenttype => $content_type
1323
        }
1336
        }
1324
    );
1337
    );
1325
1338
1326
    $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
1339
    if ( $is_html ) {
1340
        $email->html_body(
1341
            _wrap_html( $content, $subject )
1342
        );
1343
    }
1344
    else {
1345
        $email->text_body( $content );
1346
    }
1327
1347
1328
    _update_message_to_address($message->{'message_id'},$sendmail_params{To}) if !$message->{to_address} || $message->{to_address} ne $sendmail_params{To}; #if initial message address was empty, coming here means that a to address was found and queue should be updated; same if to address was overriden by create_message_headers
1348
    my $smtp_server;
1349
    if ( $library ) {
1350
        $smtp_server = $library->smtp_server;
1351
    }
1352
    else {
1353
        $smtp_server = Koha::SMTP::Servers->get_default;
1354
    }
1329
1355
1330
    if ( Mail::Sendmail::sendmail( %sendmail_params ) ) {
1356
    if ( $username ) {
1331
        _set_message_status( { message_id => $message->{'message_id'},
1357
        $smtp_server->set(
1332
                status     => 'sent' } );
1358
            {
1359
                sasl_username => $username,
1360
                sasl_password => $password,
1361
            }
1362
        );
1363
    }
1364
1365
# if initial message address was empty, coming here means that a to address was found and
1366
# queue should be updated; same if to address was overriden by create_message_headers
1367
    _update_message_to_address( $message->{'message_id'}, $email->email->header('To') )
1368
      if !$message->{to_address}
1369
      || $message->{to_address} ne $email->email->header('To');
1370
1371
    try {
1372
        $email->send_or_die({ transport => $smtp_server->transport });
1373
1374
        _set_message_status(
1375
            {
1376
                message_id => $message->{'message_id'},
1377
                status     => 'sent'
1378
            }
1379
        );
1333
        return 1;
1380
        return 1;
1334
    } else {
1335
        _set_message_status( { message_id => $message->{'message_id'},
1336
                status     => 'failed' } );
1337
        carp $Mail::Sendmail::error;
1338
        return;
1339
    }
1381
    }
1382
    catch {
1383
        _set_message_status(
1384
            {
1385
                message_id => $message->{'message_id'},
1386
                status     => 'failed'
1387
            }
1388
        );
1389
        carp "$_";
1390
        return;
1391
    };
1340
}
1392
}
1341
1393
1342
sub _wrap_html {
1394
sub _wrap_html {
(-)a/t/db_dependent/Letters.t (-35 / +73 lines)
Lines 24-36 use Test::Warn; Link Here
24
24
25
use MARC::Record;
25
use MARC::Record;
26
26
27
my %mail;
27
my ( $email_object, $sendmail_params );
28
my $module = new Test::MockModule('Mail::Sendmail');
28
29
$module->mock(
29
my $email_sender_module = Test::MockModule->new('Email::Stuffer');
30
    'sendmail',
30
$email_sender_module->mock(
31
    'send_or_die',
31
    sub {
32
    sub {
32
        warn "Fake sendmail";
33
        ( $email_object, $sendmail_params ) = @_;
33
        %mail = @_;
34
        warn "Fake send_or_die";
34
    }
35
    }
35
);
36
);
36
37
Lines 62-67 $dbh->do(q|DELETE FROM message_transport_types|); Link Here
62
63
63
my $library = $builder->build({
64
my $library = $builder->build({
64
    source => 'Branch',
65
    source => 'Branch',
66
    value  => {
67
        branchemail      => 'branchemail@address.com',
68
        branchreplyto    => 'branchreplyto@address.com',
69
        branchreturnpath => 'branchreturnpath@address.com',
70
    }
65
});
71
});
66
my $patron_category = $builder->build({ source => 'Category' })->{categorycode};
72
my $patron_category = $builder->build({ source => 'Category' })->{categorycode};
67
my $date = dt_from_string;
73
my $date = dt_from_string;
Lines 407-413 if (C4::Context->preference('marcflavour') eq 'UNIMARC') { Link Here
407
    );
413
    );
408
}
414
}
409
415
410
my $logged_in_user = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }});
416
my $logged_in_user = $builder->build_object(
417
    {
418
        class => 'Koha::Patrons',
419
        value => {
420
            branchcode => $library->{branchcode},
421
            email      => 'some@email.com'
422
        }
423
    }
424
);
425
411
t::lib::Mocks::mock_userenv({ patron => $logged_in_user });
426
t::lib::Mocks::mock_userenv({ patron => $logged_in_user });
412
427
413
($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
428
($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
Lines 439-451 t::lib::Mocks::mock_preference( 'LetterLog', 'on' ); Link Here
439
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
454
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
440
455
441
{
456
{
442
warning_is {
457
warning_like {
443
    $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) }
458
    $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) }
444
    "Fake sendmail",
459
    qr|Fake send_or_die|,
445
    "SendAlerts is using the mocked sendmail routine (orderacquisition)";
460
    "SendAlerts is using the mocked sendmail routine (orderacquisition)";
446
is($err, 1, "Successfully sent order.");
461
is($err, 1, "Successfully sent order.");
447
is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent order");
462
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order");
448
is($mail{'Message'}, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully');
463
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully');
449
464
450
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';});
465
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';});
451
warning_like {
466
warning_like {
Lines 456-469 is($err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined."); Link Here
456
}
471
}
457
472
458
{
473
{
459
warning_is {
474
warning_like {
460
    $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }
475
    $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }
461
    "Fake sendmail",
476
    qr|Fake send_or_die|,
462
    "SendAlerts is using the mocked sendmail routine";
477
    "SendAlerts is using the mocked sendmail routine";
463
478
464
is($err, 1, "Successfully sent claim");
479
is($err, 1, "Successfully sent claim");
465
is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim");
480
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent claim");
466
is($mail{'Message'}, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully');
481
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully');
467
}
482
}
468
483
469
{
484
{
Lines 496-523 my $borrowernumber = $patron->borrowernumber; Link Here
496
my $subscription = Koha::Subscriptions->find( $subscriptionid );
511
my $subscription = Koha::Subscriptions->find( $subscriptionid );
497
$subscription->add_subscriber( $patron );
512
$subscription->add_subscriber( $patron );
498
513
514
t::lib::Mocks::mock_userenv({ branch => $library->{branchcode} });
499
my $err2;
515
my $err2;
500
warning_is {
516
warning_like {
501
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
517
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
502
    "Fake sendmail",
518
    qr|Fake send_or_die|,
503
    "SendAlerts is using the mocked sendmail routine";
519
    "SendAlerts is using the mocked sendmail routine";
520
504
is($err2, 1, "Successfully sent serial notification");
521
is($err2, 1, "Successfully sent serial notification");
505
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
522
is($email_object->email->header('To'), 'john.smith@test.de', "mailto correct in sent serial notification");
506
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
523
is($email_object->email->body, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
507
524
508
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', 'robert.tables@mail.com' );
525
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', 'robert.tables@mail.com' );
509
526
510
my $err3;
527
my $err3;
511
warning_is {
528
warning_like {
512
$err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
529
$err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
513
    "Fake sendmail",
530
    qr|Fake send_or_die|,
514
    "SendAlerts is using the mocked sendmail routine";
531
    "SendAlerts is using the mocked sendmail routine";
515
is($mail{'To'}, 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference");
532
is($email_object->email->header('To'), 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference");
516
}
533
}
517
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
534
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
518
535
519
subtest 'SendAlerts - claimissue' => sub {
536
subtest 'SendAlerts - claimissue' => sub {
520
    plan tests => 8;
537
    plan tests => 9;
521
538
522
    use C4::Serials;
539
    use C4::Serials;
523
540
Lines 581-593 subtest 'SendAlerts - claimissue' => sub { Link Here
581
    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
598
    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
582
599
583
    {
600
    {
584
    warning_is {
601
    warning_like {
585
        $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) }
602
        $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) }
586
        "Fake sendmail",
603
        qr|Fake send_or_die|,
587
        "SendAlerts is using the mocked sendmail routine (claimissues)";
604
        "SendAlerts is using the mocked sendmail routine (claimissues)";
588
    is($err, 1, "Successfully sent claim");
605
    is( $err, 1, "Successfully sent claim" );
589
    is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim");
606
    is( $email_object->email->header('To'),
590
    is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", 'Serial claim letter for 1 issue constructed successfully');
607
        'testemail@mydomain.com', "mailto correct in sent claim" );
608
    is(
609
        $email_object->email->body,
610
        "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy",
611
        'Serial claim letter for 1 issue constructed successfully'
612
    );
591
    }
613
    }
592
614
593
    {
615
    {
Lines 597-604 subtest 'SendAlerts - claimissue' => sub { Link Here
597
    ($serials_count, @serials) = GetSerials($subscriptionid);
619
    ($serials_count, @serials) = GetSerials($subscriptionid);
598
    push @serialids, ($serials[1]->{serialid});
620
    push @serialids, ($serials[1]->{serialid});
599
621
600
    $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' );
622
    warning_like { $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ); }
601
    is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy\n$serialids[1]|2013-01-01|Silence in the library|xxxx-yyyy", "Serial claim letter for 2 issues constructed successfully");
623
        qr|Fake send_or_die|,
624
        "SendAlerts is using the mocked sendmail routine (claimissues)";
625
626
    is(
627
        $email_object->email->body,
628
        "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy"
629
          . $email_object->email->crlf
630
          . "$serialids[1]|2013-01-01|Silence in the library|xxxx-yyyy",
631
        "Serial claim letter for 2 issues constructed successfully"
632
    );
602
633
603
    $dbh->do(q{DELETE FROM letter WHERE code = 'TESTSERIALCLAIM';});
634
    $dbh->do(q{DELETE FROM letter WHERE code = 'TESTSERIALCLAIM';});
604
    warning_like {
635
    warning_like {
Lines 718-724 subtest 'TranslateNotices' => sub { Link Here
718
749
719
subtest 'SendQueuedMessages' => sub {
750
subtest 'SendQueuedMessages' => sub {
720
751
721
    plan tests => 6;
752
    plan tests => 9;
722
753
723
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
754
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
724
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
755
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
Lines 735-741 subtest 'SendQueuedMessages' => sub { Link Here
735
    my $sms_pro = $builder->build_object({ class => 'Koha::SMS::Providers', value => { domain => 'kidclamp.rocks' } });
766
    my $sms_pro = $builder->build_object({ class => 'Koha::SMS::Providers', value => { domain => 'kidclamp.rocks' } });
736
    $patron->set( { smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() } )->store;
767
    $patron->set( { smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() } )->store;
737
    $message_id = C4::Letters::EnqueueLetter($my_message); #using datas set around line 95 and forward
768
    $message_id = C4::Letters::EnqueueLetter($my_message); #using datas set around line 95 and forward
738
    C4::Letters::SendQueuedMessages();
769
770
    warning_like { C4::Letters::SendQueuedMessages(); }
771
        qr|Fake send_or_die|,
772
        "SendAlerts is using the mocked sendmail routine (claimissues)";
739
773
740
    my $message = $schema->resultset('MessageQueue')->search({
774
    my $message = $schema->resultset('MessageQueue')->search({
741
        borrowernumber => $borrowernumber,
775
        borrowernumber => $borrowernumber,
Lines 754-760 subtest 'SendQueuedMessages' => sub { Link Here
754
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', 'override@example.com');
788
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', 'override@example.com');
755
789
756
    $message_id = C4::Letters::EnqueueLetter($my_message);
790
    $message_id = C4::Letters::EnqueueLetter($my_message);
757
    C4::Letters::SendQueuedMessages();
791
    warning_like { C4::Letters::SendQueuedMessages(); }
792
        qr|Fake send_or_die|,
793
        "SendAlerts is using the mocked sendmail routine (claimissues)";
758
794
759
    $message = $schema->resultset('MessageQueue')->search({
795
    $message = $schema->resultset('MessageQueue')->search({
760
        borrowernumber => $borrowernumber,
796
        borrowernumber => $borrowernumber,
Lines 777-783 subtest 'SendQueuedMessages' => sub { Link Here
777
    });
813
    });
778
    is ( $number_attempted, 0, 'There were no password reset messages for SendQueuedMessages to attempt.' );
814
    is ( $number_attempted, 0, 'There were no password reset messages for SendQueuedMessages to attempt.' );
779
815
780
    C4::Letters::SendQueuedMessages();
816
    warning_like { C4::Letters::SendQueuedMessages(); }
817
        qr|Fake send_or_die|,
818
        "SendAlerts is using the mocked sendmail routine (claimissues)";
819
781
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
820
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
782
        borrowernumber => $borrowernumber,
821
        borrowernumber => $borrowernumber,
783
        status => 'sent'
822
        status => 'sent'
784
- 

Return to bug 22343