|
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 => 105; |
22 |
use Test::More tests => 106; |
| 23 |
use Test::NoWarnings; |
23 |
use Test::NoWarnings; |
| 24 |
|
24 |
|
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
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, 'sent', 'PREDUEDGST message processed' ); |
| 1917 |
is( Koha::Notice::Messages->find( $id[2] )->status, 'sent', 'ACQ_NOTIF message processed' ); |
| 1918 |
is( Koha::Notice::Messages->find( $id[3] )->status, 'sent', '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, 'sent', 'ACQ_NOTIF message processed' ); |
| 1936 |
is( Koha::Notice::Messages->find( $id[3] )->status, 'sent', '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, 'sent', '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 |
- |
|
|