|
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 1582-1584
subtest 'Quote user params in GetPreparedLetter' => sub {
Link Here
|
| 1582 |
$exec_time |
1582 |
$exec_time |
| 1583 |
); |
1583 |
); |
| 1584 |
}; |
1584 |
}; |
| 1585 |
- |
1585 |
|
|
|
1586 |
subtest 'Virtual method ->strftime in notices' => sub { |
| 1587 |
plan tests => 2; |
| 1588 |
|
| 1589 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1590 |
$patron->update( { lastseen => dt_from_string('2024-12-19 12:00:00'), surname => 'Lener' } )->store; |
| 1591 |
my $hold = $builder->build_object( { class => 'Koha::Holds' } ); |
| 1592 |
$hold->waitingdate('2024-12-18')->store; |
| 1593 |
|
| 1594 |
# In the following tests we use waitingdate as date field and lastseen as datetime. |
| 1595 |
my $notice_content = |
| 1596 |
q|1=[% borrower.lastseen.strftime('%a') %],2=[% borrower.lastseen.strftime('test') %],3=[% borrower.lastseen.strftime('') %],4=[% borrower.surname.strftime('%a') %],5=[% borrower.lastseen.strftime('%A %B') %],6=[% borrower.lastseen.strftime('%A %B','nl_NL') %],7=[% blessed_hold.waitingdate.strftime('%d-%m') %],8=[% unblessed_hold.waitingdate.strftime('%d-%m') %],9=[% iso_date.strftime('%d-%m') %],10=[% metric_date.strftime('%m') %],11=[% us_date.strftime('%m') %],12=[% unrecognized.strftime('%d-%m') %]|; |
| 1597 |
|
| 1598 |
my $notice = Koha::Notice::Template->new( |
| 1599 |
{ |
| 1600 |
module => 'circulation', |
| 1601 |
code => 'TEST_strftime', |
| 1602 |
branchcode => '', |
| 1603 |
message_transport_type => 'email', |
| 1604 |
content => $notice_content, |
| 1605 |
} |
| 1606 |
)->store; |
| 1607 |
|
| 1608 |
# Trying metric first. Note that the us date then contains month 17, so will not be recognized and passed as-is. |
| 1609 |
t::lib::Mocks::mock_preference( 'dateformat', 'metric' ); # d/m/y |
| 1610 |
my $expected_output = |
| 1611 |
q|1=Thu,2=test,3=,4=Lener,5=Thursday December,6=donderdag december,7=18-12,8=18-12,9=17-12,10=12,11=12/17/2024,12=20241217|; |
| 1612 |
my $get_letter = sub { |
| 1613 |
return C4::Letters::GetPreparedLetter( |
| 1614 |
module => 'circulation', |
| 1615 |
letter_code => 'TEST_strftime', |
| 1616 |
tables => { |
| 1617 |
borrowers => $patron->borrowernumber, |
| 1618 |
}, |
| 1619 |
message_transport_type => 'email', |
| 1620 |
substitute => { |
| 1621 |
blessed_hold => $hold, |
| 1622 |
unblessed_hold => $hold->unblessed, |
| 1623 |
iso_date => '2024-12-17', |
| 1624 |
metric_date => '17/12/2024', |
| 1625 |
us_date => '12/17/2024', |
| 1626 |
unrecognized => '20241217', |
| 1627 |
}, |
| 1628 |
); |
| 1629 |
}; |
| 1630 |
is( $get_letter->()->{content}, $expected_output, 'Check generated content for metric dateformat' ); |
| 1631 |
|
| 1632 |
# Switch dateformat pref, only expect different results for 10=metric_date and 11=us_date. |
| 1633 |
# When using 'us', the metric date with month 17 will not be recognized and passed as-is. |
| 1634 |
t::lib::Mocks::mock_preference( 'dateformat', 'us' ); # m/d/y |
| 1635 |
$expected_output =~ s/10=12/10=17\/12\/2024/; |
| 1636 |
$expected_output =~ s/11=.{10}/11=12/; |
| 1637 |
is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' ); |
| 1638 |
}; |
| 1639 |
|
| 1640 |
$schema->storage->txn_rollback; |