Lines 2-15
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
|
4 |
|
5 |
use Test::More tests => 4; |
5 |
use Test::More tests => 14; |
|
|
6 |
use Test::MockModule; |
7 |
|
6 |
use MARC::Record; |
8 |
use MARC::Record; |
|
|
9 |
use DateTime::Duration; |
7 |
|
10 |
|
8 |
use C4::Branch; |
11 |
use C4::Branch; |
9 |
use C4::Biblio; |
12 |
use C4::Biblio; |
10 |
use C4::Items; |
13 |
use C4::Items; |
11 |
use C4::Members; |
14 |
use C4::Members; |
12 |
|
15 |
|
|
|
16 |
use Koha::DateUtils; |
17 |
|
13 |
BEGIN { |
18 |
BEGIN { |
14 |
use_ok('C4::Reserves'); |
19 |
use_ok('C4::Reserves'); |
15 |
} |
20 |
} |
Lines 76-78
is($status, "Reserved", "CheckReserves Test 2");
Link Here
|
76 |
|
81 |
|
77 |
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode); |
82 |
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode); |
78 |
is($status, "Reserved", "CheckReserves Test 3"); |
83 |
is($status, "Reserved", "CheckReserves Test 3"); |
79 |
- |
84 |
|
|
|
85 |
|
86 |
# GetMaxPickupDate |
87 |
my $item = GetItem( $itemnumber ); |
88 |
is( C4::Reserves::GetMaxPickupDate(), undef, "GetMaxPickupDate returns undef if no parameter is given" ); |
89 |
|
90 |
# There is no issuingrule defined |
91 |
my $module = new Test::MockModule('C4::Circulation'); |
92 |
$module->mock( |
93 |
'GetIssuingRule', |
94 |
sub { |
95 |
return; |
96 |
} |
97 |
); |
98 |
# GetMaxPickupDate returns the same values for the 3 next calls (only reserve, only item and reserve + item) |
99 |
is( C4::Reserves::GetMaxPickupDate($reserve), undef, "GetMaxPickupDate returns undef if only reserve is given and waitingdate is not defined" ); |
100 |
is( C4::Reserves::GetMaxPickupDate(undef, $item), undef, "GetMaxPickupDate returns undef if only item is given and waitingdate is not defined" ); |
101 |
is( C4::Reserves::GetMaxPickupDate($reserve, $item), undef, "GetMaxPickupDate returns undef if reserve and item are given and waitingdate is not defined" ); |
102 |
|
103 |
# Set a maxpickupdate value |
104 |
C4::Reserves::ModReserveAffect( $item->{itemnumber}, $borrowernumber ); |
105 |
my $reserve_id = C4::Reserves::GetReserveId( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } ); |
106 |
$reserve = C4::Reserves::GetReserveInfo( $reserve_id ); |
107 |
is( C4::Reserves::GetMaxPickupDate($reserve), $reserve->{waitingdate} . 'T00:00:00', "GetMaxPickupDate returns undef if only reserve is given and waitingdate is defined" ); |
108 |
is( C4::Reserves::GetMaxPickupDate(undef, $item), $reserve->{waitingdate} . 'T00:00:00', "GetMaxPickupDate returns undef if only item is given and waitingdate is defined" ); |
109 |
is( C4::Reserves::GetMaxPickupDate($reserve, $item), $reserve->{waitingdate} . 'T00:00:00', "GetMaxPickupDate returns undef if reserve and item are given and waitingdate is not defined" ); |
110 |
|
111 |
my $delay = 5; |
112 |
$module->mock( |
113 |
'GetIssuingRule', |
114 |
sub { |
115 |
return {holdspickupdelay => $delay}; |
116 |
} |
117 |
); |
118 |
|
119 |
my $waitingdate_plus_5days = dt_from_string( $reserve->{waitingdate} )->add_duration(DateTime::Duration->new( days => $delay )); |
120 |
is( C4::Reserves::GetMaxPickupDate($reserve), $waitingdate_plus_5days, "GetMaxPickupDate returns undef if only reserve is given and waitingdate is defined" ); |
121 |
is( C4::Reserves::GetMaxPickupDate(undef, $item), $waitingdate_plus_5days, "GetMaxPickupDate returns undef if only item is given and waitingdate is defined" ); |
122 |
is( C4::Reserves::GetMaxPickupDate($reserve, $item), $waitingdate_plus_5days, "GetMaxPickupDate returns undef if reserve and item are given and waitingdate is not defined" ); |
123 |
|
124 |
# Helper method to set up a Biblio. |
125 |
sub create_helper_biblio { |
126 |
my $bib = MARC::Record->new(); |
127 |
my $title = 'Silence in the library'; |
128 |
$bib->append_fields( |
129 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
130 |
MARC::Field->new('245', ' ', ' ', a => $title), |
131 |
); |
132 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
133 |
} |