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 => 11; |
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 |
C4::Letters::SendQueuedMessages({ message_id => $message_1_id }); |
1631 |
|
1632 |
my $message_1 = Koha::Notice::Messages->find($message_1_id)->unblessed; |
1633 |
is( $message_1->{status}, 'sent', 'Message sent' ); |
1634 |
is( |
1635 |
$message_1->{to_address}, $patron->notice_email_address, |
1636 |
'A to_address was generated in the sending of the message' |
1637 |
); |
1638 |
|
1639 |
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'MULTI' ); |
1640 |
t::lib::Mocks::mock_preference( 'EmailFieldSelection', 'B_email,email,emailpro' ); |
1641 |
|
1642 |
my $message_2_id = C4::Letters::EnqueueLetter($my_message); |
1643 |
|
1644 |
C4::Letters::SendQueuedMessages({ message_id => $message_2_id }); |
1645 |
|
1646 |
my $message_2 = Koha::Notice::Messages->find($message_2_id)->unblessed; |
1647 |
is( $message_2->{status}, 'sent', 'Message sent' ); |
1648 |
my $message_2_to_address = $message_2->{to_address}; |
1649 |
$message_2_to_address =~ s/\s+//g; |
1650 |
is( |
1651 |
$message_2_to_address, $patron->notice_email_address, |
1652 |
'A to_address was generated in the sending of the message and uses the multiple selected addresses' |
1653 |
); |
1654 |
|
1655 |
t::lib::Mocks::mock_preference( 'EmailRecipientField', 'cc' ); |
1656 |
|
1657 |
my $message_3_id = C4::Letters::EnqueueLetter($my_message); |
1658 |
|
1659 |
C4::Letters::SendQueuedMessages({ message_id => $message_3_id }); |
1660 |
|
1661 |
my $message_3 = Koha::Notice::Messages->find($message_3_id)->unblessed; |
1662 |
is( $message_3->{status}, 'sent', 'Message sent' ); |
1663 |
my $message_3_cc_address = $message_3->{cc_address}; |
1664 |
$message_3_cc_address =~ s/\s+//g; |
1665 |
is( |
1666 |
$message_3_cc_address, $patron->notice_email_address, |
1667 |
'A cc_address was generated in the sending of the message and uses the multiple selected addresses' |
1668 |
); |
1669 |
|
1670 |
t::lib::Mocks::mock_preference( 'EmailRecipientField', 'bcc' ); |
1671 |
|
1672 |
my $message_4_id = C4::Letters::EnqueueLetter($my_message); |
1673 |
|
1674 |
C4::Letters::SendQueuedMessages({ message_id => $message_4_id }); |
1675 |
|
1676 |
my $message_4 = Koha::Notice::Messages->find($message_4_id)->unblessed; |
1677 |
is( $message_4->{status}, 'sent', 'Unable to specifically test BCC because this is only included in the email itself, so just confirm the message sent' ); |
1678 |
}; |