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

(-)a/t/db_dependent/Letters.t (-2 / +93 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use File::Basename qw(dirname);
21
use File::Basename qw(dirname);
22
use Test::More tests => 103;
22
use Test::More tests => 104;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Warn;
25
use Test::Warn;
Lines 75-80 $dbh->do(q|DELETE FROM letter|); Link Here
75
$dbh->do(q|DELETE FROM message_queue|);
75
$dbh->do(q|DELETE FROM message_queue|);
76
$dbh->do(q|DELETE FROM message_transport_types|);
76
$dbh->do(q|DELETE FROM message_transport_types|);
77
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
77
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
78
t::lib::Mocks::mock_preference( 'EmailRecipientField', 'to' );
78
79
79
my $library = $builder->build({
80
my $library = $builder->build({
80
    source => 'Branch',
81
    source => 'Branch',
Lines 1582-1584 subtest 'Quote user params in GetPreparedLetter' => sub { Link Here
1582
        $exec_time
1583
        $exec_time
1583
        );
1584
        );
1584
};
1585
};
1585
- 
1586
1587
subtest 'Tests for EmailRecipientField' => sub {
1588
    plan tests => 9;
1589
1590
    Koha::Notice::Messages->delete;
1591
1592
    t::lib::Mocks::mock_preference( 'EmailRecipientField', 'to' );
1593
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   'OFF' );
1594
1595
    my $library = $builder->build_object(
1596
        {
1597
            class => 'Koha::Libraries',
1598
            value => {
1599
                branchemail      => 'email@library.com', branchreplyto => 'reply@library.com',
1600
                branchreturnpath => 'return@library.com'
1601
            }
1602
        }
1603
    );
1604
    my $patron = $builder->build_object(
1605
        {
1606
            class => 'Koha::Patrons',
1607
            value => {
1608
                email      => 'primary@test.com', emailpro => 'secondary@test.com', B_email => 'alternate@test.com',
1609
                branchcode => $library->id
1610
            }
1611
        }
1612
    );
1613
1614
    my $my_message = {
1615
        'letter' => {
1616
            'content'      => '<p>a message</p>',
1617
            'metadata'     => 'metadata',
1618
            'code'         => 'TEST_MESSAGE',
1619
            'content_type' => 'text/html; charset="UTF-8"',
1620
            'title'        => 'message title'
1621
        },
1622
        'borrowernumber'         => $patron->id,
1623
        'to_address'             => undef,
1624
        'message_transport_type' => 'email',
1625
        'from_address'           => 'from@example.com'
1626
    };
1627
1628
    my $message_1_id = C4::Letters::EnqueueLetter($my_message);
1629
1630
    warning_like { C4::Letters::SendQueuedMessages({ message_id => $message_1_id }); }
1631
    qr|Fake send_or_die|,
1632
        "SendQueuedMessages is using the mocked send_or_die routine";
1633
1634
    my $message_1 = C4::Letters::GetMessage($message_1_id);
1635
    is( $message_1->{status}, 'sent', 'Message sent' );
1636
    is(
1637
        $message_1->{to_address}, $patron->notice_email_address,
1638
        'A to_address was generated in the sending of the message'
1639
    );
1640
1641
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   'MULTI' );
1642
    t::lib::Mocks::mock_preference( 'EmailFieldSelection', 'B_email,email,emailpro' );
1643
1644
    my $message_2_id = C4::Letters::EnqueueLetter($my_message);
1645
1646
    warning_like { C4::Letters::SendQueuedMessages({ message_id => $message_2_id }); }
1647
    qr|Fake send_or_die|,
1648
        "SendQueuedMessages is using the mocked send_or_die routine";
1649
1650
    my $message_2 = C4::Letters::GetMessage($message_2_id);
1651
    is( $message_2->{status}, 'sent', 'Message sent' );
1652
    is(
1653
        $message_2->{to_address}, $patron->notice_email_address,
1654
        'A to_address was generated in the sending of the message and uses the multiple selected addresses'
1655
    );
1656
1657
    t::lib::Mocks::mock_preference( 'EmailRecipientField',   'cc' );
1658
1659
    my $message_3_id = C4::Letters::EnqueueLetter($my_message);
1660
1661
    warning_like { C4::Letters::SendQueuedMessages({ message_id => $message_3_id }); }
1662
    qr|Fake send_or_die|,
1663
        "SendQueuedMessages is using the mocked send_or_die routine";
1664
1665
    my $message_3 = C4::Letters::GetMessage($message_3_id);
1666
    is( $message_3->{status}, 'sent', 'Message sent' );
1667
    is(
1668
        $message_3->{cc_address}, $patron->notice_email_address,
1669
        'A cc_address was generated in the sending of the message and uses the multiple selected addresses'
1670
    );
1671
1672
1673
#is( $email_object->email->header('To'), $guarantor1->email, "mailto correctly uses first guarantor" );
1674
#is( $email_object->email->header('Cc'), $guarantor2->email, "cc correctly uses second guarantor" );
1675
1676
};

Return to bug 37598