|
Lines 6-12
use t::lib::Mocks;
Link Here
|
| 6 |
use C4::Context; |
6 |
use C4::Context; |
| 7 |
|
7 |
|
| 8 |
use Test::NoWarnings; |
8 |
use Test::NoWarnings; |
| 9 |
use Test::More tests => 8; |
9 |
use Test::More tests => 7; |
| 10 |
use MARC::Record; |
10 |
use MARC::Record; |
| 11 |
|
11 |
|
| 12 |
use Koha::Patrons; |
12 |
use Koha::Patrons; |
|
Lines 14-19
use Koha::Holds;
Link Here
|
| 14 |
use C4::Biblio; |
14 |
use C4::Biblio; |
| 15 |
use C4::Items; |
15 |
use C4::Items; |
| 16 |
use Koha::Database; |
16 |
use Koha::Database; |
|
|
17 |
use Koha::Library::Groups; |
| 17 |
|
18 |
|
| 18 |
use t::lib::TestBuilder; |
19 |
use t::lib::TestBuilder; |
| 19 |
|
20 |
|
|
Lines 32-37
my $library1 = $builder->build( { source => 'Branch', } );
Link Here
|
| 32 |
my $library2 = $builder->build( { source => 'Branch', } ); |
33 |
my $library2 = $builder->build( { source => 'Branch', } ); |
| 33 |
my $library3 = $builder->build( { source => 'Branch', } ); |
34 |
my $library3 = $builder->build( { source => 'Branch', } ); |
| 34 |
my $library4 = $builder->build( { source => 'Branch', } ); |
35 |
my $library4 = $builder->build( { source => 'Branch', } ); |
|
|
36 |
my $library5 = $builder->build( { source => 'Branch', } ); |
| 35 |
my $itemtype = $builder->build( |
37 |
my $itemtype = $builder->build( |
| 36 |
{ |
38 |
{ |
| 37 |
source => 'Itemtype', |
39 |
source => 'Itemtype', |
|
Lines 41-46
my $itemtype = $builder->build(
Link Here
|
| 41 |
|
43 |
|
| 42 |
my $borrowers_count = 5; |
44 |
my $borrowers_count = 5; |
| 43 |
|
45 |
|
|
|
46 |
# Create some groups |
| 47 |
my $group1 = |
| 48 |
Koha::Library::Group->new( { title => "Test hold group 1", ft_local_hold_group => '1' } )->store(); |
| 49 |
my $group2 = |
| 50 |
Koha::Library::Group->new( { title => "Test hold group 2", ft_local_hold_group => '1' } )->store(); |
| 51 |
|
| 52 |
#Add branches to the groups |
| 53 |
my $group1_library1 = |
| 54 |
Koha::Library::Group->new( { parent_id => $group1->id, branchcode => $library1->{branchcode} } )->store(); |
| 55 |
my $group1_library2 = |
| 56 |
Koha::Library::Group->new( { parent_id => $group1->id, branchcode => $library2->{branchcode} } )->store(); |
| 57 |
my $group2_library1 = |
| 58 |
Koha::Library::Group->new( { parent_id => $group2->id, branchcode => $library3->{branchcode} } )->store(); |
| 59 |
my $group2_library2 = |
| 60 |
Koha::Library::Group->new( { parent_id => $group2->id, branchcode => $library4->{branchcode} } )->store(); |
| 61 |
|
| 62 |
# group1 |
| 63 |
# group1_library1 |
| 64 |
# group1_library2 |
| 65 |
# group2 |
| 66 |
# group2_library1 |
| 67 |
# group2_library2 |
| 68 |
|
| 44 |
my $biblio = $builder->build_sample_biblio(); |
69 |
my $biblio = $builder->build_sample_biblio(); |
| 45 |
my $item = Koha::Item->new( |
70 |
my $item = Koha::Item->new( |
| 46 |
{ |
71 |
{ |
|
Lines 52-57
my $item = Koha::Item->new(
Link Here
|
| 52 |
}, |
77 |
}, |
| 53 |
)->store->get_from_storage; |
78 |
)->store->get_from_storage; |
| 54 |
|
79 |
|
|
|
80 |
my $item2 = Koha::Item->new( |
| 81 |
{ |
| 82 |
biblionumber => $biblio->biblionumber, |
| 83 |
homebranch => $library1->{branchcode}, |
| 84 |
holdingbranch => $library1->{branchcode}, |
| 85 |
itype => $itemtype, |
| 86 |
exclude_from_local_holds_priority => 0, |
| 87 |
}, |
| 88 |
)->store->get_from_storage; |
| 89 |
|
| 55 |
my @branchcodes = ( |
90 |
my @branchcodes = ( |
| 56 |
$library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, |
91 |
$library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, |
| 57 |
$library3->{branchcode}, $library4->{branchcode} |
92 |
$library3->{branchcode}, $library4->{branchcode} |
|
Lines 60-119
my $patron_category = $builder->build( { source => 'Category', value => { exclud
Link Here
|
| 60 |
|
95 |
|
| 61 |
# Create some borrowers |
96 |
# Create some borrowers |
| 62 |
my @borrowernumbers; |
97 |
my @borrowernumbers; |
|
|
98 |
my $r = 0; |
| 63 |
foreach ( 0 .. $borrowers_count - 1 ) { |
99 |
foreach ( 0 .. $borrowers_count - 1 ) { |
| 64 |
my $borrowernumber = Koha::Patron->new( |
100 |
my $borrowernumber = Koha::Patron->new( |
| 65 |
{ |
101 |
{ |
| 66 |
firstname => 'my firstname', |
102 |
firstname => 'my firstname', |
| 67 |
surname => 'my surname ' . $_, |
103 |
surname => 'my surname ' . $_, |
| 68 |
categorycode => $patron_category->{categorycode}, |
104 |
categorycode => $patron_category->{categorycode}, |
| 69 |
branchcode => $branchcodes[$_], |
105 |
branchcode => $branchcodes[$r], |
| 70 |
} |
106 |
} |
| 71 |
)->store->borrowernumber; |
107 |
)->store->borrowernumber; |
| 72 |
push @borrowernumbers, $borrowernumber; |
108 |
push @borrowernumbers, $borrowernumber; |
|
|
109 |
$r++; |
| 73 |
} |
110 |
} |
| 74 |
|
111 |
|
| 75 |
# Create five item level holds |
112 |
# Create five record level holds |
| 76 |
my $i = 1; |
113 |
AddReserve( |
| 77 |
foreach my $borrowernumber (@borrowernumbers) { |
114 |
{ |
| 78 |
AddReserve( |
115 |
branchcode => $library1, |
| 79 |
{ |
116 |
borrowernumber => $borrowernumbers[0], |
| 80 |
branchcode => $branchcodes[$i], |
117 |
biblionumber => $item->biblionumber, |
| 81 |
borrowernumber => $borrowernumber, |
118 |
priority => 1, |
| 82 |
biblionumber => $biblio->biblionumber, |
119 |
} |
| 83 |
priority => $i, |
120 |
); |
| 84 |
} |
121 |
AddReserve( |
|
|
122 |
{ |
| 123 |
branchcode => $library2, |
| 124 |
borrowernumber => $borrowernumbers[1], |
| 125 |
biblionumber => $item->biblionumber, |
| 126 |
priority => 1, |
| 127 |
} |
| 128 |
); |
| 129 |
AddReserve( |
| 130 |
{ |
| 131 |
branchcode => $library3, |
| 132 |
borrowernumber => $borrowernumbers[2], |
| 133 |
biblionumber => $item->biblionumber, |
| 134 |
priority => 1, |
| 135 |
} |
| 136 |
); |
| 137 |
AddReserve( |
| 138 |
{ |
| 139 |
branchcode => $library4, |
| 140 |
borrowernumber => $borrowernumbers[3], |
| 141 |
biblionumber => $item->biblionumber, |
| 142 |
priority => 1, |
| 143 |
} |
| 144 |
); |
| 145 |
my ( $status, $reserve, $all_reserves ); |
| 146 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 'None' ); |
| 147 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 148 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" ); |
| 149 |
|
| 150 |
subtest 'LocalHoldsPriority, GiveLibrary' => sub { #Test library only priority |
| 151 |
plan tests => 4; |
| 152 |
|
| 153 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 'GiveLibrary' ); |
| 154 |
|
| 155 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 156 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 157 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 158 |
ok( |
| 159 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 160 |
"Local patron is given priority when patron pickup and item home branch match" |
| 85 |
); |
161 |
); |
| 86 |
|
162 |
|
| 87 |
$i++; |
163 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 88 |
} |
164 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
|
|
165 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 166 |
ok( |
| 167 |
$reserve->{borrowernumber} eq $borrowernumbers[2], |
| 168 |
"Local patron is given priority when patron pickup location and item home branch match" |
| 169 |
); |
| 89 |
|
170 |
|
| 90 |
my ( $status, $reserve, $all_reserves ); |
171 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
|
|
172 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
| 173 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 174 |
ok( |
| 175 |
$reserve->{borrowernumber} eq $borrowernumbers[2], |
| 176 |
"Local patron is given priority when patron home library and item holding branch match" |
| 177 |
); |
| 91 |
|
178 |
|
| 92 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 ); |
179 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 93 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
180 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 94 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" ); |
181 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
|
|
182 |
ok( |
| 183 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 184 |
"Local patron is given priority when patron home location and item home branch match" |
| 185 |
); |
| 95 |
|
186 |
|
| 96 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
187 |
}; |
| 97 |
|
188 |
|
| 98 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
189 |
subtest 'LocalHoldsPriority, GiveLibraryAndGroup' => sub { #Test library then hold group priority |
| 99 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
190 |
plan tests => 4; |
| 100 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
191 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 'GiveLibraryAndGroup' ); |
| 101 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" ); |
|
|
| 102 |
|
192 |
|
| 103 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
193 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 104 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
194 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 105 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
195 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 106 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" ); |
196 |
ok( |
|
|
197 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 198 |
"Local patron is given priority when patron pickup and item home branch match" |
| 199 |
); |
| 107 |
|
200 |
|
| 108 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
201 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 109 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
202 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
| 110 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
203 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 111 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/holdingbranch" ); |
204 |
ok( |
|
|
205 |
$reserve->{borrowernumber} eq $borrowernumbers[2], |
| 206 |
"Local patron in group is given priority when patron pickup location and item home branch match" |
| 207 |
); |
| 112 |
|
208 |
|
| 113 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
209 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 114 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
210 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
| 115 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
211 |
( $status, $reserve, $all_reserves ) = CheckReserves($item2); |
| 116 |
ok( $reserve->{borrowernumber} eq $borrowernumbers[3], "Received expected results with HomeLibrary/homebranch" ); |
212 |
ok( |
|
|
213 |
$reserve->{borrowernumber} eq $borrowernumbers[0], |
| 214 |
"Local patron in group is given priority when patron home library and item holding branch match" |
| 215 |
); |
| 216 |
|
| 217 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 218 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 219 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 220 |
ok( |
| 221 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 222 |
"Local patron is given priority when patron home location and item home branch match" |
| 223 |
); |
| 224 |
|
| 225 |
}; |
| 226 |
|
| 227 |
subtest 'LocalHoldsPriority, GiveLibraryGroup' => sub { #Test hold group only priority |
| 228 |
plan tests => 4; |
| 229 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 'GiveLibraryGroup' ); |
| 230 |
|
| 231 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 232 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 233 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 234 |
ok( |
| 235 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 236 |
"Local patron in group is given priority when patron pickup location and item home branch match" |
| 237 |
); |
| 238 |
|
| 239 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 240 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
| 241 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 242 |
ok( |
| 243 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 244 |
"Local patron in group is given priority when patron pickup location and item holding branch match" |
| 245 |
); |
| 246 |
|
| 247 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 248 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' ); |
| 249 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 250 |
ok( |
| 251 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 252 |
"Local patron in group is given priority when patron home library and item holding branch match" |
| 253 |
); |
| 254 |
|
| 255 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 256 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 257 |
( $status, $reserve, $all_reserves ) = CheckReserves($item); |
| 258 |
ok( |
| 259 |
$reserve->{borrowernumber} eq $borrowernumbers[3], |
| 260 |
"Local patron in group is given priority when patron home library and item home branch matchh" |
| 261 |
); |
| 262 |
}; |
| 117 |
|
263 |
|
| 118 |
$schema->storage->txn_rollback; |
264 |
$schema->storage->txn_rollback; |
| 119 |
|
265 |
|
|
Lines 122-128
subtest "exclude from local holds" => sub {
Link Here
|
| 122 |
|
268 |
|
| 123 |
$schema->storage->txn_begin; |
269 |
$schema->storage->txn_begin; |
| 124 |
|
270 |
|
| 125 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
271 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 'GiveLibrary' ); |
| 126 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
272 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' ); |
| 127 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
273 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 128 |
|
274 |
|
| 129 |
- |
|
|