Lines 7-15
use C4::Items;
Link Here
|
7 |
use C4::Circulation; |
7 |
use C4::Circulation; |
8 |
use Koha::IssuingRule; |
8 |
use Koha::IssuingRule; |
9 |
|
9 |
|
10 |
use Test::More tests => 4; |
10 |
use Test::More tests => 5; |
11 |
|
11 |
|
12 |
use t::lib::TestBuilder; |
12 |
use t::lib::TestBuilder; |
|
|
13 |
use t::lib::Mocks; |
13 |
|
14 |
|
14 |
BEGIN { |
15 |
BEGIN { |
15 |
use_ok('C4::Reserves'); |
16 |
use_ok('C4::Reserves'); |
Lines 24-29
my $builder = t::lib::TestBuilder->new;
Link Here
|
24 |
my $library1 = $builder->build({ |
25 |
my $library1 = $builder->build({ |
25 |
source => 'Branch', |
26 |
source => 'Branch', |
26 |
}); |
27 |
}); |
|
|
28 |
my $library2 = $builder->build({ |
29 |
source => 'Branch', |
30 |
}); |
31 |
|
27 |
|
32 |
|
28 |
# Now, set a userenv |
33 |
# Now, set a userenv |
29 |
C4::Context->_new_userenv('xxx'); |
34 |
C4::Context->_new_userenv('xxx'); |
Lines 52-57
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes L
Link Here
|
52 |
my $borrowernumber1 = $borrower1->{borrowernumber}; |
57 |
my $borrowernumber1 = $borrower1->{borrowernumber}; |
53 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
58 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
54 |
my $library_A = $library1->{branchcode}; |
59 |
my $library_A = $library1->{branchcode}; |
|
|
60 |
my $library_B = $library2->{branchcode}; |
55 |
|
61 |
|
56 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')"); |
62 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')"); |
57 |
|
63 |
|
Lines 104-110
$rule->store();
Link Here
|
104 |
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
110 |
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
105 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
111 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
106 |
|
112 |
|
107 |
AddIssue( $borrower2, $item1->{barcode} ); |
113 |
my $issue1 = AddIssue( $borrower2, $item1->{barcode} ); |
108 |
|
114 |
|
109 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
115 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
110 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
116 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
Lines 114-118
AddIssue( $borrower2, $item2->{barcode} );
Link Here
|
114 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
120 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
115 |
is( $is, 1, "Item can be held, no items available" ); |
121 |
is( $is, 1, "Item can be held, no items available" ); |
116 |
|
122 |
|
|
|
123 |
AddReturn( $item1->{barcode} ); |
124 |
|
125 |
{ # Remove the issue for the first patron, and modify the branch for item1 |
126 |
subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub { |
127 |
plan tests => 2; |
128 |
|
129 |
my $hold_allowed_from_home_library = 1; |
130 |
my $hold_allowed_from_any_libraries = 2; |
131 |
my $sth_delete_rules = $dbh->prepare(q|DELETE FROM default_circ_rules|); |
132 |
my $sth_insert_rule = $dbh->prepare(q|INSERT INTO default_circ_rules(singleton, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) VALUES ('singleton', NULL, NULL, ?, 'any', 'homebranch');|); |
133 |
|
134 |
subtest 'Item is checked out from the same library' => sub { |
135 |
plan tests => 4; |
136 |
|
137 |
Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_B, holdingbranch => $library_B })->store; |
138 |
$item1 = GetItem( $itemnumber1 ); |
139 |
|
140 |
{ |
141 |
$sth_delete_rules->execute; |
142 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
143 |
|
144 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
145 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
146 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library => the hold is allowed at item level" ); |
147 |
|
148 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
149 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
150 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library => the hold is allowed at item level" ); |
151 |
} |
152 |
|
153 |
{ |
154 |
$sth_delete_rules->execute; |
155 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
156 |
|
157 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
158 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
159 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library => the hold is allowed at item level" ); |
160 |
|
161 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
162 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
163 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library => the hold is allowed at item level" ); |
164 |
} |
165 |
}; |
166 |
|
167 |
subtest 'Item is checked out from the another library' => sub { |
168 |
plan tests => 4; |
169 |
|
170 |
Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_A, holdingbranch => $library_A })->store; |
171 |
$item1 = GetItem( $itemnumber1 ); |
172 |
|
173 |
{ |
174 |
$sth_delete_rules->execute; |
175 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
176 |
|
177 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
178 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
179 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library => the hold is allowed at item level" ); |
180 |
|
181 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
182 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
183 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library => the hold is allowed at item level" ); |
184 |
} |
185 |
|
186 |
{ |
187 |
$sth_delete_rules->execute; |
188 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
189 |
|
190 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
191 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
192 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library => the hold is allowed at item level" ); |
193 |
|
194 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
195 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
196 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library => the hold is allowed at item level" ); |
197 |
} |
198 |
}; |
199 |
}; |
200 |
} |
201 |
|
117 |
# Cleanup |
202 |
# Cleanup |
118 |
$schema->storage->txn_rollback; |
203 |
$schema->storage->txn_rollback; |
119 |
- |
|
|