Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Data::Dumper; |
6 |
use Test::More; |
7 |
|
8 |
use MARC::Record; |
9 |
|
10 |
use C4::Biblio; |
11 |
use C4::Circulation; |
12 |
use C4::Context; |
13 |
use C4::Items; |
14 |
use C4::Members; |
15 |
use C4::Reserves; |
16 |
|
17 |
my $dbh = C4::Context->dbh; |
18 |
|
19 |
# Start transaction |
20 |
$dbh->{AutoCommit} = 0; |
21 |
$dbh->{RaiseError} = 1; |
22 |
|
23 |
C4::Context->_new_userenv('xxx'); |
24 |
C4::Context::set_userenv(0,0,0,'firstname','surname', 'CPL', 'CPL', '', '', ''); |
25 |
|
26 |
my $record = MARC::Record->new; |
27 |
my ( $biblionumber ) = AddBiblio( $record, '' ); |
28 |
my ( $barcode1, $barcode2 ) = ( 'UT_prio_barcode_1', 'UT_prio_barcode_2' ); |
29 |
my ( undef, undef, $itemnumber1) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode1 }, $biblionumber); |
30 |
my ( undef, undef, $itemnumber2) = AddItem({ homebranch => 'MPL', holdingbranch => 'MPL', barcode => $barcode2 }, $biblionumber); |
31 |
|
32 |
my $borrowernumber1 = AddMember ( |
33 |
firstname => 'ill borrow', |
34 |
surname => 'foo', |
35 |
categorycode => 'PT', |
36 |
branchcode => 'CPL', |
37 |
); |
38 |
my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); |
39 |
my $borrowernumber2 = AddMember ( |
40 |
firstname => 'ill place the first hold', |
41 |
surname => 'foo', |
42 |
categorycode => 'PT', |
43 |
branchcode => 'CPL', |
44 |
); |
45 |
my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); |
46 |
my $borrowernumber3 = AddMember ( |
47 |
firstname => 'ill place the second hold', |
48 |
surname => 'foo', |
49 |
categorycode => 'PT', |
50 |
branchcode => 'CPL', |
51 |
); |
52 |
my $borrower3 = GetMember( borrowernumber => $borrowernumber3 ); |
53 |
|
54 |
|
55 |
my ( $reserve2, $reserve3 ); |
56 |
AddIssue( $borrower1, $barcode1 ); |
57 |
AddReserve( 'CPL', $borrowernumber2, $biblionumber, 'a', undef, 1, undef, undef, undef, undef, $itemnumber1 ); |
58 |
AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, undef, undef, $itemnumber1 ); |
59 |
|
60 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
61 |
AddReturn( $barcode1 ); |
62 |
ModReserveAffect( $itemnumber1, $borrowernumber2 ); |
63 |
|
64 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
65 |
is( $reserve2->{borrowernumber}, $borrowernumber2 ); |
66 |
is( $reserve2->{priority}, 0 ); |
67 |
is( $reserve2->{itemnumber}, $itemnumber1 ); |
68 |
is( $reserve2->{found}, 'W' ); |
69 |
|
70 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
71 |
is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
72 |
is( $reserve3->{priority}, 2 ); |
73 |
is( $reserve3->{itemnumber}, $itemnumber1 ); |
74 |
is( $reserve3->{found}, undef ); |
75 |
|
76 |
CancelReserve({ reserve_id => $reserve2->{reserve_id} }); |
77 |
|
78 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
79 |
is( $reserve2, undef ); |
80 |
|
81 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
82 |
is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
83 |
is( $reserve3->{priority}, 0 ); |
84 |
is( $reserve3->{itemnumber}, $itemnumber1 ); |
85 |
is( $reserve3->{found}, 'W' ); |
86 |
|
87 |
CancelReserve({ reserve_id => $reserve3->{reserve_id} }); |
88 |
|
89 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
90 |
is( $reserve3, undef ); |
91 |
|
92 |
|
93 |
|
94 |
AddIssue( $borrower1, $barcode1 ); |
95 |
AddReserve( 'CPL', $borrowernumber2, $biblionumber, 'a', undef, 1); |
96 |
AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2 ); |
97 |
C4::Context->set_preference('ConfirmFutureHolds', 2); |
98 |
my ( undef, $message ) = AddReturn( $barcode1 ); |
99 |
ModReserveAffect( $itemnumber1, $borrowernumber2 ); |
100 |
|
101 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
102 |
is( $reserve2->{borrowernumber}, $borrowernumber2 ); |
103 |
is( $reserve2->{priority}, 0 ); |
104 |
is( $reserve2->{itemnumber}, $itemnumber1 ); |
105 |
is( $reserve2->{found}, 'W' ); |
106 |
|
107 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
108 |
is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
109 |
is( $reserve3->{priority}, 2 ); |
110 |
is( $reserve3->{itemnumber}, undef ); |
111 |
is( $reserve3->{found}, undef ); |
112 |
|
113 |
CancelReserve({ reserve_id => $reserve2->{reserve_id} }); |
114 |
|
115 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
116 |
is( $reserve2, undef ); |
117 |
|
118 |
# FIXME |
119 |
#( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
120 |
#is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
121 |
#is( $reserve3->{priority}, 0 ); |
122 |
#is( $reserve3->{itemnumber}, $itemnumber1 ); |
123 |
#is( $reserve3->{found}, 'W' ); |
124 |
|
125 |
CancelReserve({ reserve_id => $reserve3->{reserve_id} }); |
126 |
|
127 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
128 |
is( $reserve3, undef ); |
129 |
|
130 |
|
131 |
|
132 |
AddIssue( $borrower1, $barcode1 ); |
133 |
AddReserve( 'MPL', $borrowernumber2, $biblionumber, 'a', undef, 1, undef, undef, undef, undef, $itemnumber2 ); |
134 |
AddReserve( 'MPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, undef, undef, $itemnumber2 ); |
135 |
|
136 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
137 |
AddReturn( $barcode1 ); |
138 |
ModReserveAffect( $itemnumber2, $borrowernumber2, 1 ); |
139 |
|
140 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
141 |
is( $reserve2->{borrowernumber}, $borrowernumber2 ); |
142 |
is( $reserve2->{priority}, 0 ); |
143 |
is( $reserve2->{itemnumber}, $itemnumber2 ); |
144 |
is( $reserve2->{found}, 'T' ); |
145 |
|
146 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
147 |
is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
148 |
is( $reserve3->{priority}, 2 ); |
149 |
is( $reserve3->{itemnumber}, $itemnumber2 ); |
150 |
is( $reserve3->{found}, undef ); |
151 |
|
152 |
CancelReserve({ reserve_id => $reserve2->{reserve_id} }); |
153 |
|
154 |
( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); |
155 |
is( $reserve2, undef ); |
156 |
|
157 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
158 |
is( $reserve3->{borrowernumber}, $borrowernumber3 ); |
159 |
is( $reserve3->{priority}, 0 ); |
160 |
is( $reserve3->{itemnumber}, $itemnumber2 ); |
161 |
is( $reserve3->{found}, 'T' ); |
162 |
|
163 |
CancelReserve({ reserve_id => $reserve3->{reserve_id} }); |
164 |
|
165 |
( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); |
166 |
is( $reserve3, undef ); |
167 |
|
168 |
|
169 |
done_testing; |