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

(-)a/t/db_dependent/Letters.t (-3 / +99 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 => 104;
22
use Test::More tests => 105;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Warn;
25
use Test::Warn;
Lines 79-85 my $dbh = C4::Context->dbh; Link Here
79
$dbh->do(q|DELETE FROM letter|);
79
$dbh->do(q|DELETE FROM letter|);
80
$dbh->do(q|DELETE FROM message_queue|);
80
$dbh->do(q|DELETE FROM message_queue|);
81
$dbh->do(q|DELETE FROM message_transport_types|);
81
$dbh->do(q|DELETE FROM message_transport_types|);
82
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', '' );
82
t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   '' );
83
t::lib::Mocks::mock_preference( 'EmailRecipientField', 'to' );
83
84
84
my $library = $builder->build(
85
my $library = $builder->build(
85
    {
86
    {
Lines 1824-1827 subtest 'Virtual method ->strftime in notices' => sub { Link Here
1824
    is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' );
1825
    is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' );
1825
};
1826
};
1826
1827
1828
subtest 'Tests for EmailRecipientField' => sub {
1829
    plan tests => 11;
1830
1831
    Koha::Notice::Messages->delete;
1832
1833
    t::lib::Mocks::mock_preference( 'EmailRecipientField', 'to' );
1834
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   'OFF' );
1835
1836
    my $library = $builder->build_object(
1837
        {
1838
            class => 'Koha::Libraries',
1839
            value => {
1840
                branchemail      => 'email@library.com', branchreplyto => 'reply@library.com',
1841
                branchreturnpath => 'return@library.com'
1842
            }
1843
        }
1844
    );
1845
    my $patron = $builder->build_object(
1846
        {
1847
            class => 'Koha::Patrons',
1848
            value => {
1849
                email      => 'primary@test.com', emailpro => 'secondary@test.com', B_email => 'alternate@test.com',
1850
                branchcode => $library->id
1851
            }
1852
        }
1853
    );
1854
1855
    my $my_message = {
1856
        'letter' => {
1857
            'content'      => '<p>a message</p>',
1858
            'metadata'     => 'metadata',
1859
            'code'         => 'TEST_MESSAGE',
1860
            'content_type' => 'text/html; charset="UTF-8"',
1861
            'title'        => 'message title'
1862
        },
1863
        'borrowernumber'         => $patron->id,
1864
        'to_address'             => undef,
1865
        'message_transport_type' => 'email',
1866
        'from_address'           => 'from@example.com'
1867
    };
1868
1869
    my $message_1_id = C4::Letters::EnqueueLetter($my_message);
1870
1871
    C4::Letters::SendQueuedMessages( { message_id => $message_1_id } );
1872
1873
    my $message_1 = Koha::Notice::Messages->find($message_1_id)->unblessed;
1874
    is( $message_1->{status}, 'sent', 'Message sent' );
1875
    is(
1876
        $message_1->{to_address}, $patron->notice_email_address,
1877
        'A to_address was generated in the sending of the message'
1878
    );
1879
1880
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   'MULTI' );
1881
    t::lib::Mocks::mock_preference( 'EmailFieldSelection', 'B_email,email,emailpro' );
1882
1883
    my $message_2_id = C4::Letters::EnqueueLetter($my_message);
1884
1885
    C4::Letters::SendQueuedMessages( { message_id => $message_2_id } );
1886
1887
    my $message_2 = Koha::Notice::Messages->find($message_2_id)->unblessed;
1888
    is( $message_2->{status}, 'sent', 'Message sent' );
1889
    my $message_2_to_address = $message_2->{to_address};
1890
    $message_2_to_address =~ s/\s+//g;
1891
    is(
1892
        $message_2_to_address, $patron->notice_email_address,
1893
        'A to_address was generated in the sending of the message and uses the multiple selected addresses'
1894
    );
1895
1896
    t::lib::Mocks::mock_preference( 'EmailRecipientField', 'cc' );
1897
1898
    my $message_3_id = C4::Letters::EnqueueLetter($my_message);
1899
1900
    C4::Letters::SendQueuedMessages( { message_id => $message_3_id } );
1901
1902
    my $message_3 = Koha::Notice::Messages->find($message_3_id)->unblessed;
1903
    is( $message_3->{status}, 'sent', 'Message sent' );
1904
    my $message_3_cc_address = $message_3->{cc_address};
1905
    $message_3_cc_address =~ s/\s+//g;
1906
    is(
1907
        $message_3_cc_address, $patron->notice_email_address,
1908
        'A cc_address was generated in the sending of the message and uses the multiple selected addresses'
1909
    );
1910
1911
    t::lib::Mocks::mock_preference( 'EmailRecipientField', 'bcc' );
1912
1913
    my $message_4_id = C4::Letters::EnqueueLetter($my_message);
1914
1915
    C4::Letters::SendQueuedMessages( { message_id => $message_4_id } );
1916
1917
    my $message_4 = Koha::Notice::Messages->find($message_4_id)->unblessed;
1918
    is(
1919
        $message_4->{status}, 'sent',
1920
        'Unable to specifically test BCC because this is only included in the email itself, so just confirm the message sent'
1921
    );
1922
};
1923
1827
$schema->storage->txn_rollback;
1924
$schema->storage->txn_rollback;
1828
- 

Return to bug 37598