|
Lines 19-25
use Modern::Perl;
Link Here
|
| 19 |
use utf8; |
19 |
use utf8; |
| 20 |
|
20 |
|
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::More tests => 78; |
22 |
use Test::More tests => 80; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Deep qw( cmp_deeply ); |
25 |
use Test::Deep qw( cmp_deeply ); |
|
Lines 28-33
use Test::Warn;
Link Here
|
| 28 |
use Data::Dumper; |
28 |
use Data::Dumper; |
| 29 |
use DateTime; |
29 |
use DateTime; |
| 30 |
use Time::Fake; |
30 |
use Time::Fake; |
|
|
31 |
use JSON qw( from_json ); |
| 31 |
use POSIX qw( floor ); |
32 |
use POSIX qw( floor ); |
| 32 |
use t::lib::Mocks; |
33 |
use t::lib::Mocks; |
| 33 |
use t::lib::TestBuilder; |
34 |
use t::lib::TestBuilder; |
|
Lines 7769-7774
subtest 'ChildNeedsGuarantor' => sub {
Link Here
|
| 7769 |
"AddReturn generates no warning when can_be_guarantee type patron has a guarantor and not ChildNeedsGuarantor"; |
7770 |
"AddReturn generates no warning when can_be_guarantee type patron has a guarantor and not ChildNeedsGuarantor"; |
| 7770 |
}; |
7771 |
}; |
| 7771 |
|
7772 |
|
|
|
7773 |
subtest 'Bug 9762: AddIssue override JSON logging' => sub { |
| 7774 |
plan tests => 8; |
| 7775 |
|
| 7776 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 7777 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 7778 |
my $item = $builder->build_sample_item( { library => $library->branchcode } ); |
| 7779 |
|
| 7780 |
t::lib::Mocks::mock_userenv( { patron => $patron, branchcode => $library->branchcode } ); |
| 7781 |
t::lib::Mocks::mock_preference( 'IssueLog', 1 ); |
| 7782 |
|
| 7783 |
# Clear any existing logs |
| 7784 |
Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'ISSUE' } )->delete; |
| 7785 |
|
| 7786 |
# Test 1: Normal checkout without overrides - should log item number only |
| 7787 |
my $issue = C4::Circulation::AddIssue( $patron, $item->barcode ); |
| 7788 |
ok( $issue, 'Item checked out successfully' ); |
| 7789 |
|
| 7790 |
my $logs = Koha::ActionLogs->search( |
| 7791 |
{ |
| 7792 |
module => 'CIRCULATION', |
| 7793 |
action => 'ISSUE', |
| 7794 |
object => $patron->borrowernumber |
| 7795 |
}, |
| 7796 |
{ order_by => { -desc => 'timestamp' } } |
| 7797 |
); |
| 7798 |
is( $logs->count, 1, 'One log entry created for normal checkout' ); |
| 7799 |
my $log = $logs->next; |
| 7800 |
is( $log->info, $item->itemnumber, 'Normal checkout logs item number only' ); |
| 7801 |
|
| 7802 |
# Return the item for next test |
| 7803 |
C4::Circulation::AddReturn( $item->barcode, $library->branchcode ); |
| 7804 |
|
| 7805 |
# Test 2: Checkout with confirmations - should log JSON with confirmations |
| 7806 |
my $item2 = $builder->build_sample_item( { library => $library->branchcode } ); |
| 7807 |
|
| 7808 |
my $issue2 = C4::Circulation::AddIssue( |
| 7809 |
$patron, |
| 7810 |
$item2->barcode, |
| 7811 |
undef, undef, undef, undef, |
| 7812 |
{ |
| 7813 |
confirmations => [ 'DEBT', 'AGE_RESTRICTION' ], |
| 7814 |
forced => [] |
| 7815 |
} |
| 7816 |
); |
| 7817 |
ok( $issue2, 'Item with confirmations checked out successfully' ); |
| 7818 |
|
| 7819 |
$logs = Koha::ActionLogs->search( |
| 7820 |
{ |
| 7821 |
module => 'CIRCULATION', |
| 7822 |
action => 'ISSUE', |
| 7823 |
object => $patron->borrowernumber, |
| 7824 |
info => { '!=', $item->itemnumber } # Exclude the first test log |
| 7825 |
}, |
| 7826 |
{ order_by => { -desc => 'timestamp' } } |
| 7827 |
); |
| 7828 |
is( $logs->count, 1, 'One log entry created for override checkout' ); |
| 7829 |
$log = $logs->next; |
| 7830 |
|
| 7831 |
my $log_data = eval { from_json( $log->info ) }; |
| 7832 |
ok( !$@, 'Log info is valid JSON' ); |
| 7833 |
ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' ); |
| 7834 |
is_deeply( $log_data->{confirmations}, [ 'DEBT', 'AGE_RESTRICTION' ], 'Confirmations logged correctly' ); |
| 7835 |
}; |
| 7836 |
|
| 7837 |
subtest 'Bug 9762: AddRenewal override JSON logging' => sub { |
| 7838 |
plan tests => 11; |
| 7839 |
|
| 7840 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 7841 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 7842 |
my $item = $builder->build_sample_item( { library => $library->branchcode } ); |
| 7843 |
|
| 7844 |
t::lib::Mocks::mock_userenv( { patron => $patron, branchcode => $library->branchcode } ); |
| 7845 |
t::lib::Mocks::mock_preference( 'RenewalLog', 1 ); |
| 7846 |
|
| 7847 |
# Issue the item first |
| 7848 |
my $issue = C4::Circulation::AddIssue( $patron, $item->barcode ); |
| 7849 |
|
| 7850 |
# Clear any existing renewal logs |
| 7851 |
Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'RENEWAL' } )->delete; |
| 7852 |
|
| 7853 |
# Test 1: Normal renewal without overrides - should log item number only |
| 7854 |
C4::Circulation::AddRenewal( |
| 7855 |
{ |
| 7856 |
borrowernumber => $patron->borrowernumber, |
| 7857 |
itemnumber => $item->itemnumber, |
| 7858 |
branch => $library->branchcode |
| 7859 |
} |
| 7860 |
); |
| 7861 |
|
| 7862 |
my $logs = Koha::ActionLogs->search( |
| 7863 |
{ |
| 7864 |
module => 'CIRCULATION', |
| 7865 |
action => 'RENEWAL', |
| 7866 |
object => $patron->borrowernumber |
| 7867 |
}, |
| 7868 |
{ order_by => { -desc => 'timestamp' } } |
| 7869 |
); |
| 7870 |
is( $logs->count, 1, 'One log entry created for normal renewal' ); |
| 7871 |
my $log = $logs->next; |
| 7872 |
|
| 7873 |
my $log_data = eval { from_json( $log->info ) }; |
| 7874 |
ok( !$@, 'Normal renewal log info is valid JSON' ); |
| 7875 |
is( $log_data->{itemnumber}, $item->itemnumber, 'Normal renewal JSON contains itemnumber' ); |
| 7876 |
is_deeply( $log_data->{confirmations}, [], 'Normal renewal has empty confirmations array' ); |
| 7877 |
is_deeply( $log_data->{forced}, [], 'Normal renewal has empty forced array' ); |
| 7878 |
|
| 7879 |
# Test 2: Renewal with overrides - should log JSON with confirmations |
| 7880 |
C4::Circulation::AddRenewal( |
| 7881 |
{ |
| 7882 |
borrowernumber => $patron->borrowernumber, |
| 7883 |
itemnumber => $item->itemnumber, |
| 7884 |
branch => $library->branchcode, |
| 7885 |
confirmations => [ 'ON_RESERVE', 'RENEWAL_LIMIT' ], |
| 7886 |
forced => ['TOO_MUCH'] |
| 7887 |
} |
| 7888 |
); |
| 7889 |
|
| 7890 |
# Get only the most recent renewal log (the one with overrides) |
| 7891 |
my $override_log = Koha::ActionLogs->search( |
| 7892 |
{ |
| 7893 |
module => 'CIRCULATION', |
| 7894 |
action => 'RENEWAL', |
| 7895 |
object => $patron->borrowernumber, |
| 7896 |
info => { 'like' => '%ON_RESERVE%' } # Only get the log with our test overrides |
| 7897 |
}, |
| 7898 |
{ order_by => { -desc => 'timestamp' }, rows => 1 } |
| 7899 |
)->next; |
| 7900 |
|
| 7901 |
ok( $override_log, 'Found override renewal log entry' ); |
| 7902 |
$log_data = eval { from_json( $override_log->info ) }; |
| 7903 |
ok( !$@, 'Override renewal log info is valid JSON' ); |
| 7904 |
ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' ); |
| 7905 |
ok( exists $log_data->{forced}, 'JSON contains forced array' ); |
| 7906 |
is_deeply( $log_data->{confirmations}, [ 'ON_RESERVE', 'RENEWAL_LIMIT' ], 'Confirmations logged correctly' ); |
| 7907 |
is_deeply( $log_data->{forced}, ['TOO_MUCH'], 'Forced overrides logged correctly' ); |
| 7908 |
}; |
| 7909 |
|
| 7772 |
$schema->storage->txn_rollback; |
7910 |
$schema->storage->txn_rollback; |
| 7773 |
C4::Context->clear_syspref_cache(); |
7911 |
C4::Context->clear_syspref_cache(); |
| 7774 |
$branches = Koha::Libraries->search(); |
7912 |
$branches = Koha::Libraries->search(); |
| 7775 |
- |
|
|