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

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

Return to bug 37598