|
Lines 24-29
use C4::Branch;
Link Here
|
| 24 |
use Koha::Database; |
24 |
use Koha::Database; |
| 25 |
|
25 |
|
| 26 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
|
|
27 |
use t::lib::TestBuilder; |
| 27 |
|
28 |
|
| 28 |
use Test::More tests => 9; |
29 |
use Test::More tests => 9; |
| 29 |
|
30 |
|
|
Lines 35-58
BEGIN {
Link Here
|
| 35 |
} |
36 |
} |
| 36 |
|
37 |
|
| 37 |
my $dbh = C4::Context->dbh; |
38 |
my $dbh = C4::Context->dbh; |
| 38 |
my $branches = GetBranches; |
|
|
| 39 |
my ($branch1, $branch2) = keys %$branches; |
| 40 |
my $location = 'My Location'; |
39 |
my $location = 'My Location'; |
| 41 |
|
40 |
|
| 42 |
subtest 'General Add, Get and Del tests' => sub { |
41 |
subtest 'General Add, Get and Del tests' => sub { |
| 43 |
|
42 |
|
| 44 |
plan tests => 10; |
43 |
plan tests => 10; |
| 45 |
|
44 |
|
| 46 |
# Start transaction |
45 |
my $builder = t::lib::TestBuilder->new; |
| 47 |
$dbh->{AutoCommit} = 0; |
46 |
my $library = $builder->build({ |
| 48 |
$dbh->{RaiseError} = 1; |
47 |
source => 'Branch', |
|
|
48 |
}); |
| 49 |
|
49 |
|
| 50 |
# Create a biblio instance for testing |
50 |
# Create a biblio instance for testing |
| 51 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
51 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 52 |
my ($bibnum, $bibitemnum) = get_biblio(); |
52 |
my ($bibnum, $bibitemnum) = get_biblio(); |
| 53 |
|
53 |
|
| 54 |
# Add an item. |
54 |
# Add an item. |
| 55 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location } , $bibnum); |
55 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location } , $bibnum); |
| 56 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
56 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
| 57 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
57 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
| 58 |
|
58 |
|
|
Lines 73-84
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
| 73 |
my $getdeleted = GetItem($itemnumber); |
73 |
my $getdeleted = GetItem($itemnumber); |
| 74 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
74 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
| 75 |
|
75 |
|
| 76 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location, permanent_location => 'my permanent location' } , $bibnum); |
76 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location' } , $bibnum); |
| 77 |
$getitem = GetItem($itemnumber); |
77 |
$getitem = GetItem($itemnumber); |
| 78 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
78 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
| 79 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
79 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
| 80 |
|
|
|
| 81 |
$dbh->rollback; |
| 82 |
}; |
80 |
}; |
| 83 |
|
81 |
|
| 84 |
subtest 'GetHiddenItemnumbers tests' => sub { |
82 |
subtest 'GetHiddenItemnumbers tests' => sub { |
|
Lines 87-118
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
| 87 |
|
85 |
|
| 88 |
# This sub is controlled by the OpacHiddenItems system preference. |
86 |
# This sub is controlled by the OpacHiddenItems system preference. |
| 89 |
|
87 |
|
| 90 |
# Start transaction |
88 |
my $builder = t::lib::TestBuilder->new; |
| 91 |
$dbh->{AutoCommit} = 0; |
89 |
my $library1 = $builder->build({ |
| 92 |
$dbh->{RaiseError} = 1; |
90 |
source => 'Branch', |
|
|
91 |
}); |
| 92 |
|
| 93 |
my $library2 = $builder->build({ |
| 94 |
source => 'Branch', |
| 95 |
}); |
| 93 |
|
96 |
|
| 94 |
# Create a new biblio |
97 |
# Create a new biblio |
| 95 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
98 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 96 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
99 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
| 97 |
|
100 |
|
| 98 |
# Add branches if they don't exist |
|
|
| 99 |
if (not defined GetBranchDetail('CPL')) { |
| 100 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
| 101 |
} |
| 102 |
if (not defined GetBranchDetail('MPL')) { |
| 103 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
| 104 |
} |
| 105 |
|
| 106 |
# Add two items |
101 |
# Add two items |
| 107 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
102 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
| 108 |
{ homebranch => $branch1, |
103 |
{ homebranch => $library1->{branchcode}, |
| 109 |
holdingbranch => $branch1, |
104 |
holdingbranch => $library1->{branchcode}, |
| 110 |
withdrawn => 1 }, |
105 |
withdrawn => 1 }, |
| 111 |
$biblionumber |
106 |
$biblionumber |
| 112 |
); |
107 |
); |
| 113 |
my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem( |
108 |
my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem( |
| 114 |
{ homebranch => $branch2, |
109 |
{ homebranch => $library2->{branchcode}, |
| 115 |
holdingbranch => $branch2, |
110 |
holdingbranch => $library2->{branchcode}, |
| 116 |
withdrawn => 0 }, |
111 |
withdrawn => 0 }, |
| 117 |
$biblionumber |
112 |
$biblionumber |
| 118 |
); |
113 |
); |
|
Lines 153-195
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
| 153 |
# Two variables, a value each |
148 |
# Two variables, a value each |
| 154 |
$opachiddenitems = " |
149 |
$opachiddenitems = " |
| 155 |
withdrawn: [1] |
150 |
withdrawn: [1] |
| 156 |
homebranch: [$branch2] |
151 |
homebranch: [$library2->{branchcode}] |
| 157 |
"; |
152 |
"; |
| 158 |
C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); |
153 |
C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 159 |
@hidden = GetHiddenItemnumbers( @items ); |
154 |
@hidden = GetHiddenItemnumbers( @items ); |
| 160 |
ok( scalar @hidden == 2, "Two items hidden"); |
155 |
ok( scalar @hidden == 2, "Two items hidden"); |
| 161 |
is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch=MPL hidden"); |
156 |
is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden"); |
| 162 |
|
157 |
|
| 163 |
# Valid OpacHiddenItems, empty list |
158 |
# Valid OpacHiddenItems, empty list |
| 164 |
@items = (); |
159 |
@items = (); |
| 165 |
@hidden = GetHiddenItemnumbers( @items ); |
160 |
@hidden = GetHiddenItemnumbers( @items ); |
| 166 |
ok( scalar @hidden == 0, "Empty items list, no item hidden"); |
161 |
ok( scalar @hidden == 0, "Empty items list, no item hidden"); |
| 167 |
|
|
|
| 168 |
$dbh->rollback; |
| 169 |
}; |
162 |
}; |
| 170 |
|
163 |
|
| 171 |
subtest 'GetItemsInfo tests' => sub { |
164 |
subtest 'GetItemsInfo tests' => sub { |
| 172 |
|
165 |
|
| 173 |
plan tests => 4; |
166 |
plan tests => 4; |
| 174 |
|
167 |
|
| 175 |
# Start transaction |
168 |
my $builder = t::lib::TestBuilder->new; |
| 176 |
$dbh->{AutoCommit} = 0; |
169 |
my $library1 = $builder->build({ |
| 177 |
$dbh->{RaiseError} = 1; |
170 |
source => 'Branch', |
|
|
171 |
}); |
| 172 |
my $library2 = $builder->build({ |
| 173 |
source => 'Branch', |
| 174 |
}); |
| 178 |
|
175 |
|
| 179 |
# Add a biblio |
176 |
# Add a biblio |
| 180 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
177 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
| 181 |
# Add an item |
178 |
# Add an item |
| 182 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
179 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) |
| 183 |
= AddItem({ |
180 |
= AddItem({ |
| 184 |
homebranch => $branch1, |
181 |
homebranch => $library1->{branchcode}, |
| 185 |
holdingbranch => $branch2 |
182 |
holdingbranch => $library2->{branchcode}, |
| 186 |
}, $biblionumber ); |
183 |
}, $biblionumber ); |
| 187 |
|
184 |
|
| 188 |
my $branch = GetBranchDetail( $branch1 ); |
185 |
my $branch = GetBranchDetail( $library1->{branchcode} ); |
| 189 |
$branch->{ opac_info } = "homebranch OPAC info"; |
186 |
$branch->{ opac_info } = "homebranch OPAC info"; |
| 190 |
ModBranch($branch); |
187 |
ModBranch($branch); |
| 191 |
|
188 |
|
| 192 |
$branch = GetBranchDetail( $branch2 ); |
189 |
$branch = GetBranchDetail( $library2->{branchcode} ); |
| 193 |
$branch->{ opac_info } = "holdingbranch OPAC info"; |
190 |
$branch->{ opac_info } = "holdingbranch OPAC info"; |
| 194 |
ModBranch($branch); |
191 |
ModBranch($branch); |
| 195 |
|
192 |
|
|
Lines 201-217
subtest 'GetItemsInfo tests' => sub {
Link Here
|
| 201 |
'GetItemsInfo returns the correct holding branch OPAC info notice' ); |
198 |
'GetItemsInfo returns the correct holding branch OPAC info notice' ); |
| 202 |
is( exists( $results[0]->{ onsite_checkout } ), 1, |
199 |
is( exists( $results[0]->{ onsite_checkout } ), 1, |
| 203 |
'GetItemsInfo returns a onsite_checkout key' ); |
200 |
'GetItemsInfo returns a onsite_checkout key' ); |
| 204 |
|
|
|
| 205 |
$dbh->rollback; |
| 206 |
}; |
201 |
}; |
| 207 |
|
202 |
|
| 208 |
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { |
203 |
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { |
| 209 |
|
204 |
|
| 210 |
plan tests => 4; |
205 |
plan tests => 4; |
| 211 |
|
206 |
|
| 212 |
# Start transaction |
207 |
my $builder = t::lib::TestBuilder->new; |
| 213 |
$dbh->{AutoCommit} = 0; |
|
|
| 214 |
$dbh->{RaiseError} = 1; |
| 215 |
|
208 |
|
| 216 |
my $schema = Koha::Database->new()->schema(); |
209 |
my $schema = Koha::Database->new()->schema(); |
| 217 |
|
210 |
|
|
Lines 249-288
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
Link Here
|
| 249 |
ok( defined $effective_itemtype && |
242 |
ok( defined $effective_itemtype && |
| 250 |
$effective_itemtype eq 'BIB_LEVEL', |
243 |
$effective_itemtype eq 'BIB_LEVEL', |
| 251 |
'$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' ); |
244 |
'$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' ); |
| 252 |
|
|
|
| 253 |
$dbh->rollback; |
| 254 |
}; |
245 |
}; |
| 255 |
|
246 |
|
| 256 |
subtest 'SearchItems test' => sub { |
247 |
subtest 'SearchItems test' => sub { |
| 257 |
plan tests => 14; |
248 |
plan tests => 14; |
| 258 |
|
249 |
|
| 259 |
# Start transaction |
250 |
my $builder = t::lib::TestBuilder->new; |
| 260 |
$dbh->{AutoCommit} = 0; |
251 |
my $dbh = C4::Context->dbh; |
| 261 |
$dbh->{RaiseError} = 1; |
252 |
|
|
|
253 |
my $library1 = $builder->build({ |
| 254 |
source => 'Branch', |
| 255 |
}); |
| 256 |
my $library2 = $builder->build({ |
| 257 |
source => 'Branch', |
| 258 |
}); |
| 262 |
|
259 |
|
| 263 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
260 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 264 |
my $cpl_items_before = SearchItemsByField( 'homebranch', 'CPL'); |
261 |
my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode}); |
| 265 |
|
262 |
|
| 266 |
my ($biblionumber) = get_biblio(); |
263 |
my ($biblionumber) = get_biblio(); |
| 267 |
|
264 |
|
| 268 |
# Add branches if they don't exist |
|
|
| 269 |
if (not defined GetBranchDetail('CPL')) { |
| 270 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
| 271 |
} |
| 272 |
if (not defined GetBranchDetail('MPL')) { |
| 273 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
| 274 |
} |
| 275 |
|
| 276 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
265 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
| 277 |
|
266 |
|
| 278 |
# Add two items |
267 |
# Add two items |
| 279 |
my (undef, undef, $item1_itemnumber) = AddItem({ |
268 |
my (undef, undef, $item1_itemnumber) = AddItem({ |
| 280 |
homebranch => 'CPL', |
269 |
homebranch => $library1->{branchcode}, |
| 281 |
holdingbranch => 'CPL', |
270 |
holdingbranch => $library1->{branchcode}, |
| 282 |
}, $biblionumber); |
271 |
}, $biblionumber); |
| 283 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
272 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
| 284 |
homebranch => 'MPL', |
273 |
homebranch => $library2->{branchcode}, |
| 285 |
holdingbranch => 'MPL', |
274 |
holdingbranch => $library2->{branchcode}, |
| 286 |
}, $biblionumber); |
275 |
}, $biblionumber); |
| 287 |
|
276 |
|
| 288 |
my ($items, $total_results); |
277 |
my ($items, $total_results); |
|
Lines 298-311
subtest 'SearchItems test' => sub {
Link Here
|
| 298 |
# Search all items where homebranch = 'CPL' |
287 |
# Search all items where homebranch = 'CPL' |
| 299 |
my $filter = { |
288 |
my $filter = { |
| 300 |
field => 'homebranch', |
289 |
field => 'homebranch', |
| 301 |
query => 'CPL', |
290 |
query => $library1->{branchcode}, |
| 302 |
operator => '=', |
291 |
operator => '=', |
| 303 |
}; |
292 |
}; |
| 304 |
($items, $total_results) = SearchItems($filter); |
293 |
($items, $total_results) = SearchItems($filter); |
| 305 |
ok($total_results > 0, "There is at least one CPL item"); |
294 |
ok($total_results > 0, "There is at least one CPL item"); |
| 306 |
my $all_items_are_CPL = 1; |
295 |
my $all_items_are_CPL = 1; |
| 307 |
foreach my $item (@$items) { |
296 |
foreach my $item (@$items) { |
| 308 |
if ($item->{homebranch} ne 'CPL') { |
297 |
if ($item->{homebranch} ne $library1->{branchcode}) { |
| 309 |
$all_items_are_CPL = 0; |
298 |
$all_items_are_CPL = 0; |
| 310 |
last; |
299 |
last; |
| 311 |
} |
300 |
} |
|
Lines 315-328
subtest 'SearchItems test' => sub {
Link Here
|
| 315 |
# Search all items where homebranch != 'CPL' |
304 |
# Search all items where homebranch != 'CPL' |
| 316 |
$filter = { |
305 |
$filter = { |
| 317 |
field => 'homebranch', |
306 |
field => 'homebranch', |
| 318 |
query => 'CPL', |
307 |
query => $library1->{branchcode}, |
| 319 |
operator => '!=', |
308 |
operator => '!=', |
| 320 |
}; |
309 |
}; |
| 321 |
($items, $total_results) = SearchItems($filter); |
310 |
($items, $total_results) = SearchItems($filter); |
| 322 |
ok($total_results > 0, "There is at least one non-CPL item"); |
311 |
ok($total_results > 0, "There is at least one non-CPL item"); |
| 323 |
my $all_items_are_not_CPL = 1; |
312 |
my $all_items_are_not_CPL = 1; |
| 324 |
foreach my $item (@$items) { |
313 |
foreach my $item (@$items) { |
| 325 |
if ($item->{homebranch} eq 'CPL') { |
314 |
if ($item->{homebranch} eq $library1->{branchcode}) { |
| 326 |
$all_items_are_not_CPL = 0; |
315 |
$all_items_are_not_CPL = 0; |
| 327 |
last; |
316 |
last; |
| 328 |
} |
317 |
} |
|
Lines 350-356
subtest 'SearchItems test' => sub {
Link Here
|
| 350 |
}, |
339 |
}, |
| 351 |
{ |
340 |
{ |
| 352 |
field => 'homebranch', |
341 |
field => 'homebranch', |
| 353 |
query => 'CPL', |
342 |
query => $library1->{branchcode}, |
| 354 |
operator => '=', |
343 |
operator => '=', |
| 355 |
}, |
344 |
}, |
| 356 |
], |
345 |
], |
|
Lines 411-435
subtest 'SearchItems test' => sub {
Link Here
|
| 411 |
($items, $total_results) = SearchItems($filter); |
400 |
($items, $total_results) = SearchItems($filter); |
| 412 |
ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"'); |
401 |
ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"'); |
| 413 |
|
402 |
|
| 414 |
my $cpl_items_after = SearchItemsByField( 'homebranch', 'CPL'); |
403 |
my $cpl_items_after = SearchItemsByField( 'homebranch', $library1->{branchcode}); |
| 415 |
is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' ); |
404 |
is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' ); |
| 416 |
|
|
|
| 417 |
$dbh->rollback; |
| 418 |
}; |
405 |
}; |
| 419 |
|
406 |
|
| 420 |
subtest 'Koha::Item(s) tests' => sub { |
407 |
subtest 'Koha::Item(s) tests' => sub { |
| 421 |
|
408 |
|
| 422 |
plan tests => 5; |
409 |
plan tests => 5; |
| 423 |
|
410 |
|
| 424 |
# Start transaction |
411 |
my $builder = t::lib::TestBuilder->new; |
| 425 |
my $schema = Koha::Database->new()->schema(); |
412 |
my $library1 = $builder->build({ |
| 426 |
$schema->storage->txn_begin(); |
413 |
source => 'Branch', |
| 427 |
$dbh->{RaiseError} = 1; |
414 |
}); |
|
|
415 |
my $library2 = $builder->build({ |
| 416 |
source => 'Branch', |
| 417 |
}); |
| 428 |
|
418 |
|
| 429 |
# Create a biblio and item for testing |
419 |
# Create a biblio and item for testing |
| 430 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
420 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 431 |
my ($bibnum, $bibitemnum) = get_biblio(); |
421 |
my ($bibnum, $bibitemnum) = get_biblio(); |
| 432 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch2 } , $bibnum); |
422 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} } , $bibnum); |
| 433 |
|
423 |
|
| 434 |
# Get item. |
424 |
# Get item. |
| 435 |
my $item = Koha::Items->find( $itemnumber ); |
425 |
my $item = Koha::Items->find( $itemnumber ); |
|
Lines 437-469
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
| 437 |
|
427 |
|
| 438 |
my $homebranch = $item->home_branch(); |
428 |
my $homebranch = $item->home_branch(); |
| 439 |
is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" ); |
429 |
is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" ); |
| 440 |
is( $homebranch->branchcode(), $branch1, "Home branch code matches homebranch" ); |
430 |
is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" ); |
| 441 |
|
431 |
|
| 442 |
my $holdingbranch = $item->holding_branch(); |
432 |
my $holdingbranch = $item->holding_branch(); |
| 443 |
is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" ); |
433 |
is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" ); |
| 444 |
is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" ); |
434 |
is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" ); |
| 445 |
}; |
435 |
}; |
| 446 |
|
436 |
|
| 447 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
437 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
| 448 |
plan tests => 7; |
438 |
plan tests => 7; |
| 449 |
|
439 |
|
| 450 |
$dbh->{AutoCommit} = 0; |
440 |
my $builder = t::lib::TestBuilder->new; |
| 451 |
$dbh->{RaiseError} = 1; |
441 |
my $library1 = $builder->build({ |
|
|
442 |
source => 'Branch', |
| 443 |
}); |
| 444 |
my $library2 = $builder->build({ |
| 445 |
source => 'Branch', |
| 446 |
}); |
| 452 |
|
447 |
|
| 453 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
448 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
| 454 |
my $item_infos = [ |
449 |
my $item_infos = [ |
| 455 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
450 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 456 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
451 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 457 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
452 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 458 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
453 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 459 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
454 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 460 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
455 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 461 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
456 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 462 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
457 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 463 |
]; |
458 |
]; |
| 464 |
my $number_of_items = scalar @$item_infos; |
459 |
my $number_of_items = scalar @$item_infos; |
| 465 |
my $number_of_items_with_homebranch_is_CPL = |
460 |
my $number_of_items_with_homebranch_is_CPL = |
| 466 |
grep { $_->{homebranch} eq 'CPL' } @$item_infos; |
461 |
grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; |
| 467 |
|
462 |
|
| 468 |
my @itemnumbers; |
463 |
my @itemnumbers; |
| 469 |
for my $item_info (@$item_infos) { |
464 |
for my $item_info (@$item_infos) { |
|
Lines 501-507
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
| 501 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
496 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
| 502 |
|
497 |
|
| 503 |
my $opachiddenitems = " |
498 |
my $opachiddenitems = " |
| 504 |
homebranch: ['CPL']"; |
499 |
homebranch: ['$library1->{branchcode}']"; |
| 505 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
500 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 506 |
|
501 |
|
| 507 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
502 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
|
Lines 519-525
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
| 519 |
); |
514 |
); |
| 520 |
|
515 |
|
| 521 |
$opachiddenitems = " |
516 |
$opachiddenitems = " |
| 522 |
homebranch: ['CPL', 'MPL']"; |
517 |
homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; |
| 523 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
518 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 524 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
519 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 525 |
@items = $record->field($itemfield); |
520 |
@items = $record->field($itemfield); |