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

(-)a/t/db_dependent/Letters.t (-1 / +126 lines)
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' );
1825
    is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' );
1826
};
1826
};
1827
1827
1828
subtest 'Test exclude_letter_code parameter for SendQueuedMessages' => sub {
1829
    plan tests => 10;
1830
1831
    my $dbh = C4::Context->dbh;
1832
1833
    my $borrowernumber = Koha::Patron->new(
1834
        {
1835
            firstname    => 'Jane',
1836
            surname      => 'Smith',
1837
            categorycode => $patron_category,
1838
            branchcode   => $library->{branchcode},
1839
            dateofbirth  => $date,
1840
            smsalertnumber => '5555555555',
1841
        }
1842
    )->store->borrowernumber;
1843
1844
    $dbh->do(q|DELETE FROM message_queue|);
1845
1846
    # Create messages with different letter codes
1847
    my $message_digest1 = {
1848
        'letter' => {
1849
            'content'      => 'digest message 1',
1850
            'metadata'     => 'metadata',
1851
            'code'         => 'DUEDGST',
1852
            'content_type' => 'text/plain',
1853
            'title'        => 'digest title'
1854
        },
1855
        'borrowernumber'         => $borrowernumber,
1856
        'to_address'             => undef,
1857
        'message_transport_type' => 'sms',
1858
        'from_address'           => 'from@example.com'
1859
    };
1860
    my $message_digest2 = {
1861
        'letter' => {
1862
            'content'      => 'digest message 2',
1863
            'metadata'     => 'metadata',
1864
            'code'         => 'PREDUEDGST',
1865
            'content_type' => 'text/plain',
1866
            'title'        => 'predigest title'
1867
        },
1868
        'borrowernumber'         => $borrowernumber,
1869
        'to_address'             => undef,
1870
        'message_transport_type' => 'sms',
1871
        'from_address'           => 'from@example.com'
1872
    };
1873
    my $message_regular = {
1874
        'letter' => {
1875
            'content'      => 'regular message',
1876
            'metadata'     => 'metadata',
1877
            'code'         => 'ACQ_NOTIF',
1878
            'content_type' => 'text/plain',
1879
            'title'        => 'regular title'
1880
        },
1881
        'borrowernumber'         => $borrowernumber,
1882
        'to_address'             => undef,
1883
        'message_transport_type' => 'sms',
1884
        'from_address'           => 'from@example.com'
1885
    };
1886
    my $message_regular2 = {
1887
        'letter' => {
1888
            'content'      => 'another regular message',
1889
            'metadata'     => 'metadata',
1890
            'code'         => 'TEST_MESSAGE',
1891
            'content_type' => 'text/plain',
1892
            'title'        => 'regular title 2'
1893
        },
1894
        'borrowernumber'         => $borrowernumber,
1895
        'to_address'             => undef,
1896
        'message_transport_type' => 'sms',
1897
        'from_address'           => 'from@example.com'
1898
    };
1899
1900
    my @id = (
1901
        C4::Letters::EnqueueLetter($message_digest1),
1902
        C4::Letters::EnqueueLetter($message_digest2),
1903
        C4::Letters::EnqueueLetter($message_regular),
1904
        C4::Letters::EnqueueLetter($message_regular2),
1905
    );
1906
1907
    # Test excluding single letter code (array)
1908
    C4::Letters::SendQueuedMessages(
1909
        {
1910
            exclude_letter_code => ['DUEDGST'],
1911
            type                => 'sms',
1912
        }
1913
    );
1914
1915
    is( Koha::Notice::Messages->find( $id[0] )->status, 'pending', 'DUEDGST message excluded, still pending' );
1916
    is( Koha::Notice::Messages->find( $id[1] )->status, 'failed',  'PREDUEDGST message processed' );
1917
    is( Koha::Notice::Messages->find( $id[2] )->status, 'failed',  'ACQ_NOTIF message processed' );
1918
    is( Koha::Notice::Messages->find( $id[3] )->status, 'failed',  'TEST_MESSAGE message processed' );
1919
1920
    # Reset messages to pending
1921
    Koha::Notice::Messages->find( $id[1] )->update( { status => 'pending' } );
1922
    Koha::Notice::Messages->find( $id[2] )->update( { status => 'pending' } );
1923
    Koha::Notice::Messages->find( $id[3] )->update( { status => 'pending' } );
1924
1925
    # Test excluding multiple letter codes
1926
    C4::Letters::SendQueuedMessages(
1927
        {
1928
            exclude_letter_code => [ 'DUEDGST', 'PREDUEDGST' ],
1929
            type                => 'sms',
1930
        }
1931
    );
1932
1933
    is( Koha::Notice::Messages->find( $id[0] )->status, 'pending', 'DUEDGST message excluded, still pending' );
1934
    is( Koha::Notice::Messages->find( $id[1] )->status, 'pending', 'PREDUEDGST message excluded, still pending' );
1935
    is( Koha::Notice::Messages->find( $id[2] )->status, 'failed',  'ACQ_NOTIF message processed' );
1936
    is( Koha::Notice::Messages->find( $id[3] )->status, 'failed',  'TEST_MESSAGE message processed' );
1937
1938
    # Reset messages to pending
1939
    Koha::Notice::Messages->find( $id[2] )->update( { status => 'pending' } );
1940
    Koha::Notice::Messages->find( $id[3] )->update( { status => 'pending' } );
1941
1942
    # Test with scalar exclude_letter_code
1943
    C4::Letters::SendQueuedMessages(
1944
        {
1945
            exclude_letter_code => 'TEST_MESSAGE',
1946
            type                => 'sms',
1947
        }
1948
    );
1949
1950
    is( Koha::Notice::Messages->find( $id[2] )->status, 'failed',  'ACQ_NOTIF message processed' );
1951
    is( Koha::Notice::Messages->find( $id[3] )->status, 'pending', 'TEST_MESSAGE message excluded, still pending' );
1952
};
1953
1828
$schema->storage->txn_rollback;
1954
$schema->storage->txn_rollback;
1829
- 

Return to bug 40934