|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 71; |
20 |
use Test::More tests => 70; |
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
Lines 34-40
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
Link Here
|
| 34 |
use C4::HoldsQueue; |
34 |
use C4::HoldsQueue; |
| 35 |
use C4::Members; |
35 |
use C4::Members; |
| 36 |
use C4::Reserves |
36 |
use C4::Reserves |
| 37 |
qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); |
37 |
qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee CanItemBeReserved MergeHolds ); |
| 38 |
use Koha::ActionLogs; |
38 |
use Koha::ActionLogs; |
| 39 |
use Koha::Biblios; |
39 |
use Koha::Biblios; |
| 40 |
use Koha::Caches; |
40 |
use Koha::Caches; |
|
Lines 1029-1146
subtest 'ChargeReserveFee tests' => sub {
Link Here
|
| 1029 |
is( $line->branchcode, $library->id, "Library id is picked from userenv and stored correctly" ); |
1029 |
is( $line->branchcode, $library->id, "Library id is picked from userenv and stored correctly" ); |
| 1030 |
}; |
1030 |
}; |
| 1031 |
|
1031 |
|
| 1032 |
subtest 'reserves.item_level_hold' => sub { |
|
|
| 1033 |
plan tests => 2; |
| 1034 |
|
| 1035 |
my $item = $builder->build_sample_item; |
| 1036 |
my $patron = $builder->build_object( |
| 1037 |
{ |
| 1038 |
class => 'Koha::Patrons', |
| 1039 |
value => { branchcode => $item->homebranch } |
| 1040 |
} |
| 1041 |
); |
| 1042 |
|
| 1043 |
subtest 'item level hold' => sub { |
| 1044 |
plan tests => 5; |
| 1045 |
my $reserve_id = AddReserve( |
| 1046 |
{ |
| 1047 |
branchcode => $item->homebranch, |
| 1048 |
borrowernumber => $patron->borrowernumber, |
| 1049 |
biblionumber => $item->biblionumber, |
| 1050 |
priority => 1, |
| 1051 |
itemnumber => $item->itemnumber, |
| 1052 |
} |
| 1053 |
); |
| 1054 |
|
| 1055 |
my $hold = Koha::Holds->find($reserve_id); |
| 1056 |
is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' ); |
| 1057 |
|
| 1058 |
# Mark it waiting |
| 1059 |
ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 ); |
| 1060 |
|
| 1061 |
my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); |
| 1062 |
$mock->mock( |
| 1063 |
'enqueue', |
| 1064 |
sub { |
| 1065 |
my ( $self, $args ) = @_; |
| 1066 |
is_deeply( |
| 1067 |
$args->{biblio_ids}, |
| 1068 |
[ $hold->biblionumber ], |
| 1069 |
"AlterPriority triggers a holds queue update for the related biblio" |
| 1070 |
); |
| 1071 |
} |
| 1072 |
); |
| 1073 |
|
| 1074 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); |
| 1075 |
t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); |
| 1076 |
|
| 1077 |
# Revert the waiting status |
| 1078 |
C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); |
| 1079 |
|
| 1080 |
$hold = Koha::Holds->find($reserve_id); |
| 1081 |
|
| 1082 |
is( |
| 1083 |
$hold->itemnumber, $item->itemnumber, |
| 1084 |
'Itemnumber should not be removed when the waiting status is revert' |
| 1085 |
); |
| 1086 |
|
| 1087 |
my $log = |
| 1088 |
Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->next; |
| 1089 |
my $expected = sprintf q{'timestamp' => '%s'}, $hold->timestamp; |
| 1090 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
| 1091 |
my $log_count = |
| 1092 |
Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; |
| 1093 |
|
| 1094 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
| 1095 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 1096 |
|
| 1097 |
$hold->set_waiting; |
| 1098 |
|
| 1099 |
# Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test |
| 1100 |
C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); |
| 1101 |
|
| 1102 |
$hold->delete; # cleanup |
| 1103 |
|
| 1104 |
my $log_count_after = |
| 1105 |
Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; |
| 1106 |
is( $log_count, $log_count_after, "No logging is added for RevertWaitingStatus when HoldsLog is disabled" ); |
| 1107 |
|
| 1108 |
}; |
| 1109 |
|
| 1110 |
subtest 'biblio level hold' => sub { |
| 1111 |
plan tests => 3; |
| 1112 |
my $reserve_id = AddReserve( |
| 1113 |
{ |
| 1114 |
branchcode => $item->homebranch, |
| 1115 |
borrowernumber => $patron->borrowernumber, |
| 1116 |
biblionumber => $item->biblionumber, |
| 1117 |
priority => 1, |
| 1118 |
} |
| 1119 |
); |
| 1120 |
|
| 1121 |
my $hold = Koha::Holds->find($reserve_id); |
| 1122 |
is( |
| 1123 |
$hold->item_level_hold, 0, |
| 1124 |
'item_level_hold should not be set when AddReserve is called without a specific item' |
| 1125 |
); |
| 1126 |
|
| 1127 |
# Mark it waiting |
| 1128 |
ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 ); |
| 1129 |
|
| 1130 |
$hold = Koha::Holds->find($reserve_id); |
| 1131 |
is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should be set on hold confirmation' ); |
| 1132 |
|
| 1133 |
# Revert the waiting status |
| 1134 |
C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); |
| 1135 |
|
| 1136 |
$hold = Koha::Holds->find($reserve_id); |
| 1137 |
is( $hold->itemnumber, undef, 'Itemnumber should be removed when the waiting status is revert' ); |
| 1138 |
|
| 1139 |
$hold->delete; |
| 1140 |
}; |
| 1141 |
|
| 1142 |
}; |
| 1143 |
|
| 1144 |
subtest 'MoveReserve additional test' => sub { |
1032 |
subtest 'MoveReserve additional test' => sub { |
| 1145 |
|
1033 |
|
| 1146 |
plan tests => 8; |
1034 |
plan tests => 8; |
|
Lines 1216-1222
subtest 'MoveReserve additional test' => sub {
Link Here
|
| 1216 |
|
1104 |
|
| 1217 |
}; |
1105 |
}; |
| 1218 |
|
1106 |
|
| 1219 |
subtest 'RevertWaitingStatus' => sub { |
1107 |
# FIXME: Should be in Circulation.t |
|
|
1108 |
subtest 'AddIssue calls $hold->revert_waiting()' => sub { |
| 1220 |
|
1109 |
|
| 1221 |
plan tests => 2; |
1110 |
plan tests => 2; |
| 1222 |
|
1111 |
|