Browse Source

Bug 21798: Unify the creation of bibliographic record in tests

Using the newly created subroutine

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
19.05.x
Jonathan Druart 4 years ago
committed by Nick Clemens
parent
commit
9ba6125f72
  1. 138
      t/db_dependent/Circulation.t
  2. 113
      t/db_dependent/Holds.t
  3. 23
      t/db_dependent/Holds/LocalHoldsPriority.t
  4. 24
      t/db_dependent/Holds/RevertWaitingStatus.t
  5. 99
      t/db_dependent/Items.t
  6. 23
      t/db_dependent/Items/DelItem.t
  7. 20
      t/db_dependent/Items/GetItemsForInventory.t
  8. 19
      t/db_dependent/Koha/BiblioUtils/Iterator.t
  9. 19
      t/db_dependent/Koha/Biblios.t
  10. 47
      t/db_dependent/OAI/Sets.t
  11. 13
      t/db_dependent/Serials.t
  12. 27
      t/lib/TestBuilder.pm

138
t/db_dependent/Circulation.t

@ -213,8 +213,7 @@ $dbh->do(
# CanBookBeRenewed tests
C4::Context->set_preference('ItemsDeniedRenewal','');
# Generate test biblio
my $title = 'Silence in the library';
my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
my $biblio = $builder->gimme_a_biblio();
my $barcode = 'R00000342';
my $branch = $library2->{branchcode};
@ -227,7 +226,7 @@ $dbh->do(
replacementprice => 12.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $barcode2 = 'R00000343';
@ -239,7 +238,7 @@ $dbh->do(
replacementprice => 23.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $barcode3 = 'R00000346';
@ -251,7 +250,7 @@ $dbh->do(
replacementprice => 23.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
# Create borrowers
@ -328,9 +327,9 @@ $dbh->do(
# Biblio-level hold, renewal test
AddReserve(
$branch, $reserving_borrowernumber, $biblionumber,
$branch, $reserving_borrowernumber, $biblio->biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
$title, $checkitem, $found
'a title', $checkitem, $found
);
# Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
@ -345,7 +344,7 @@ $dbh->do(
my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
{
borrowernumber => $hold_waiting_borrowernumber,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
itemnumber => $itemnumber,
branchcode => $branch,
priority => 3,
@ -360,7 +359,7 @@ $dbh->do(
$hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
{
borrowernumber => $hold_waiting_borrowernumber,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
itemnumber => $itemnumber3,
branchcode => $branch,
priority => 0,
@ -381,7 +380,7 @@ $dbh->do(
is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
my $reserveid = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
AddIssue($reserving_borrower, $barcode3);
my $reserve = $dbh->selectrow_hashref(
@ -393,9 +392,9 @@ $dbh->do(
# Item-level hold, renewal test
AddReserve(
$branch, $reserving_borrowernumber, $biblionumber,
$branch, $reserving_borrowernumber, $biblio->biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
$title, $itemnumber, $found
'a title', $itemnumber, $found
);
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
@ -406,10 +405,10 @@ $dbh->do(
is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
# Items can't fill hold for reasons
ModItem({ notforloan => 1 }, $biblionumber, $itemnumber);
ModItem({ notforloan => 1 }, $biblio->biblionumber, $itemnumber);
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
ModItem({ notforloan => 0, itype => $itemtype }, $biblionumber, $itemnumber);
ModItem({ notforloan => 0, itype => $itemtype }, $biblio->biblionumber, $itemnumber);
# FIXME: Add more for itemtype not for loan etc.
@ -423,7 +422,7 @@ $dbh->do(
replacementprice => 23.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $datedue5 = AddIssue($restricted_borrower, $barcode5);
is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
@ -444,7 +443,7 @@ $dbh->do(
replacementprice => 23.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $barcode7 = 'R00000349';
@ -456,7 +455,7 @@ $dbh->do(
replacementprice => 23.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
@ -519,7 +518,7 @@ $dbh->do(
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
$hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next;
$hold = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next;
$hold->cancel;
# Bug 14101
@ -534,7 +533,7 @@ $dbh->do(
replacementprice => 16.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
$issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
@ -604,7 +603,7 @@ $dbh->do(
my $item_to_auto_renew = $builder->build(
{ source => 'Item',
value => {
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
homebranch => $branch,
holdingbranch => $branch,
}
@ -663,7 +662,7 @@ $dbh->do(
my $item_to_auto_renew = $builder->build({
source => 'Item',
value => {
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
homebranch => $branch,
holdingbranch => $branch,
}
@ -703,7 +702,7 @@ $dbh->do(
my $item_to_auto_renew = $builder->build({
source => 'Item',
value => {
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
homebranch => $branch,
holdingbranch => $branch,
}
@ -755,7 +754,7 @@ $dbh->do(
my $item_to_auto_renew = $builder->build(
{ source => 'Item',
value => {
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
homebranch => $branch,
holdingbranch => $branch,
}
@ -907,8 +906,7 @@ $dbh->do(
my $branch = $library2->{branchcode};
#Create another record
my $title2 = 'Something is worng here';
my ($biblionumber2, $biblioitemnumber2) = add_biblio($title2, 'Anonymous');
my $biblio2 = $builder->gimme_a_biblio();
#Create third item
AddItem(
@ -918,7 +916,7 @@ $dbh->do(
barcode => $barcode3,
itype => $itemtype
},
$biblionumber2
$biblio2->biblionumber
);
# Create a borrower
@ -987,7 +985,7 @@ $dbh->do(
my $barcode = '1234567890';
my $branch = $library2->{branchcode};
my ($biblionumber, $biblioitemnumber) = add_biblio();
my $biblio = $builder->gimme_a_biblio();
#Create third item
my ( undef, undef, $itemnumber ) = AddItem(
@ -997,7 +995,7 @@ $dbh->do(
barcode => $barcode,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
# Create a borrower
@ -1044,7 +1042,7 @@ $dbh->do(
undef, 0,
.10, 1
);
my ( $biblionumber, $biblioitemnumber ) = add_biblio();
my $biblio = $builder->gimme_a_biblio();
my $barcode1 = '1234';
my ( undef, undef, $itemnumber1 ) = AddItem(
@ -1054,7 +1052,7 @@ $dbh->do(
barcode => $barcode1,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $barcode2 = '4321';
my ( undef, undef, $itemnumber2 ) = AddItem(
@ -1064,7 +1062,7 @@ $dbh->do(
barcode => $barcode2,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $borrowernumber1 = Koha::Patron->new({
@ -1089,7 +1087,7 @@ $dbh->do(
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
AddReserve(
$library2->{branchcode}, $borrowernumber2, $biblionumber,
$library2->{branchcode}, $borrowernumber2, $biblio->biblionumber,
'', 1, undef, undef, '',
undef, undef, undef
);
@ -1115,7 +1113,7 @@ $dbh->do(
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
# Setting item not checked out to be not for loan but holdable
ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2);
ModItem({ notforloan => -1 }, $biblio->biblionumber, $itemnumber2);
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
@ -1127,7 +1125,7 @@ $dbh->do(
my $branch = $library->{branchcode};
#Create another record
my ($biblionumber, $biblioitemnumber) = add_biblio('A title', 'Anonymous');
my $biblio = $builder->gimme_a_biblio();
my (undef, undef, $itemnumber) = AddItem(
{
@ -1136,7 +1134,7 @@ $dbh->do(
barcode => $barcode,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $borrowernumber = Koha::Patron->new({
@ -1157,7 +1155,7 @@ $dbh->do(
{
my $library = $builder->build({ source => 'Branch' });
my ($biblionumber, $biblioitemnumber) = add_biblio();
my $biblio = $builder->gimme_a_biblio();
my $barcode = 'just a barcode';
my ( undef, undef, $itemnumber ) = AddItem(
@ -1167,7 +1165,7 @@ $dbh->do(
barcode => $barcode,
itype => $itemtype
},
$biblionumber,
$biblio->biblionumber,
);
my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
@ -1457,8 +1455,7 @@ subtest 'CanBookBeIssued + Statistic patrons "X"' => sub {
subtest 'MultipleReserves' => sub {
plan tests => 3;
my $title = 'Silence in the library';
my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
my $biblio = $builder->gimme_a_biblio();
my $branch = $library2->{branchcode};
@ -1471,7 +1468,7 @@ subtest 'MultipleReserves' => sub {
replacementprice => 12.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $barcode2 = 'R00110002';
@ -1483,7 +1480,7 @@ subtest 'MultipleReserves' => sub {
replacementprice => 12.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $bibitems = '';
@ -1515,9 +1512,9 @@ subtest 'MultipleReserves' => sub {
);
my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
AddReserve(
$branch, $reserving_borrowernumber1, $biblionumber,
$branch, $reserving_borrowernumber1, $biblio->biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
$title, $checkitem, $found
'a title', $checkitem, $found
);
my %reserving_borrower_data2 = (
@ -1528,9 +1525,9 @@ subtest 'MultipleReserves' => sub {
);
my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
AddReserve(
$branch, $reserving_borrowernumber2, $biblionumber,
$branch, $reserving_borrowernumber2, $biblio->biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
$title, $checkitem, $found
'a title', $checkitem, $found
);
{
@ -1547,7 +1544,7 @@ subtest 'MultipleReserves' => sub {
replacementprice => 12.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
{
@ -1995,9 +1992,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
);
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
# Generate test biblio
my $title = 'Koha for Dummies';
my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, 'Hall, Daria' );
my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Daria' });
subtest 'Full write-off tests' => sub {
@ -2013,13 +2008,13 @@ subtest '_FixAccountForLostAndReturned' => sub {
replacementprice => $replacement_amount,
itype => $item_type->itemtype
},
$biblionumber
$biblio->biblionumber
);
AddIssue( $patron->unblessed, $barcode );
# Simulate item marked as lost
ModItem( { itemlost => 3 }, $biblionumber, $item_id );
ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
LostItem( $item_id, 1 );
my $processing_fee_lines = Koha::Account::Lines->search(
@ -2075,13 +2070,13 @@ subtest '_FixAccountForLostAndReturned' => sub {
replacementprice => $replacement_amount,
itype => $item_type->itemtype
},
$biblionumber
$biblio->biblionumber
);
AddIssue( $patron->unblessed, $barcode );
# Simulate item marked as lost
ModItem( { itemlost => 1 }, $biblionumber, $item_id );
ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
LostItem( $item_id, 1 );
my $processing_fee_lines = Koha::Account::Lines->search(
@ -2144,13 +2139,13 @@ subtest '_FixAccountForLostAndReturned' => sub {
replacementprice => $replacement_amount,
itype => $item_type->itemtype
},
$biblionumber
$biblio->biblionumber
);
AddIssue( $patron->unblessed, $barcode );
# Simulate item marked as lost
ModItem( { itemlost => 3 }, $biblionumber, $item_id );
ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
LostItem( $item_id, 1 );
my $processing_fee_lines = Koha::Account::Lines->search(
@ -2198,13 +2193,13 @@ subtest '_FixAccountForLostAndReturned' => sub {
replacementprice => $replacement_amount,
itype => $item_type->itemtype
},
$biblionumber
$biblio->biblionumber
);
AddIssue( $patron->unblessed, $barcode );
# Simulate item marked as lost
ModItem( { itemlost => 1 }, $biblionumber, $item_id );
ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
LostItem( $item_id, 1 );
my $processing_fee_lines = Koha::Account::Lines->search(
@ -2362,9 +2357,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
subtest '_FixOverduesOnReturn' => sub {
plan tests => 10;
# Generate test biblio
my $title = 'Koha for Dummies';
my ( $biblionumber, $biblioitemnumber ) = add_biblio($title, 'Hall, Kylie');
my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Kylie' });
my $barcode = 'KD987654321';
my $branchcode = $library2->{branchcode};
@ -2377,7 +2370,7 @@ subtest '_FixOverduesOnReturn' => sub {
replacementprice => 99.00,
itype => $itemtype
},
$biblionumber
$biblio->biblionumber
);
my $patron = $builder->build( { source => 'Borrower' } );
@ -3009,29 +3002,6 @@ sub str {
return $s;
}
sub add_biblio {
my ($title, $author) = @_;
my $marcflavour = C4::Context->preference('marcflavour');
my $biblio = MARC::Record->new();
if ($title) {
my $tag = $marcflavour eq 'UNIMARC' ? '200' : '245';
$biblio->append_fields(
MARC::Field->new($tag, ' ', ' ', a => $title),
);
}
if ($author) {
my ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a');
$biblio->append_fields(
MARC::Field->new($tag, ' ', ' ', $code => $author),
);
}
return AddBiblio($biblio, '');
}
sub test_debarment_on_checkout {
my ($params) = @_;
my $item = $params->{item};

113
t/db_dependent/Holds.t

@ -54,12 +54,11 @@ $insert_sth->execute('DUMMY');
$insert_sth->execute('ONLY1');
# Setup Test------------------------
# Create a biblio instance for testing
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
my $biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
# Create item instance for testing.
my ($item_bibnum, $item_bibitemnum, $itemnumber)
= AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
= AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
# Create some borrowers
my @borrowernumbers;
@ -73,26 +72,23 @@ foreach (1..$borrowers_count) {
push @borrowernumbers, $borrowernumber;
}
my $biblionumber = $bibnum;
# Create five item level holds
foreach my $borrowernumber ( @borrowernumbers ) {
AddReserve(
$branch_1,
$borrowernumber,
$biblionumber,
$biblio->biblionumber,
my $bibitems = q{},
my $priority = C4::Reserves::CalculatePriority( $biblionumber ),
my $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ),
my $resdate,
my $expdate,
my $notes = q{},
$title,
'a title',
my $checkitem = $itemnumber,
my $found,
);
}
my $biblio = Koha::Biblios->find( $biblionumber );
my $holds = $biblio->holds;
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
@ -176,7 +172,7 @@ ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" );
SuspendAll(
borrowernumber => $borrowernumber,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
suspend => 1,
suspend_until => '2012-01-01',
);
@ -186,7 +182,7 @@ is( $hold->suspend_until, '2012-01-01 00:00:00', "Test SuspendAll(), with date"
SuspendAll(
borrowernumber => $borrowernumber,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
suspend => 0,
);
$hold = Koha::Holds->find( $reserve_id );
@ -197,19 +193,19 @@ is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have n
AddReserve(
$branch_1,
$borrowernumbers[0],
$biblionumber,
$biblio->biblionumber,
my $bibitems = q{},
my $priority,
my $resdate,
my $expdate,
my $notes = q{},
$title,
'a title',
my $checkitem,
my $found,
);
$patron = Koha::Patrons->find( $borrowernumber );
$holds = $patron->holds;
my $reserveid = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
ModReserveMinusPriority( $itemnumber, $reserveid );
$holds = $patron->holds;
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
@ -243,9 +239,9 @@ is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
# Note that canreservefromotherbranches has no effect if
# IndependentBranches is OFF.
my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
my $foreign_biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_bibnum);
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
$dbh->do('DELETE FROM issuingrules');
$dbh->do(
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
@ -288,14 +284,14 @@ ok(
{
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $bibnum, '', 1);
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $bibnum, '', 2);
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $bibnum, '', 3);
my $hhh = Koha::Holds->search({ biblionumber => $bibnum });
$biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
my $hold3 = Koha::Holds->find( $reserveid3 );
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
ModReserve({ reserve_id => $reserveid1, rank => 'del' });
@ -325,12 +321,12 @@ ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged',
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
# Regression test for bug 9532
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
AddReserve(
$branch_1,
$borrowernumbers[0],
$bibnum,
$biblio->biblionumber,
'',
1,
);
@ -373,20 +369,20 @@ $dbh->do(q{
INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
VALUES (?, ?, ?, ?)
}, {}, $branch_1, 'CAN', 1, 'homebranch');
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
"CanItemBeReserved should return 'notReservable'");
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
{ homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
{ homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
'cannotReserveFromOtherBranches',
"CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
"CanItemBeReserved should return 'OK'");
@ -399,9 +395,9 @@ $dbh->do('DELETE FROM issues');
$dbh->do('DELETE FROM items');
$dbh->do('DELETE FROM biblio');
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
$biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
( $item_bibnum, $item_bibitemnum, $itemnumber )
= AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
= AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
$dbh->do(
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
@ -412,7 +408,7 @@ $dbh->do(
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
@ -424,10 +420,10 @@ subtest 'Test max_holds per library/patron category' => sub {
$dbh->do('DELETE FROM issuingrules');
$dbh->do('DELETE FROM circulation_rules');
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
$biblio = $builder->gimme_a_biblio({ itemtype => 'TEST' });
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
$bibnum );
$biblio->biblionumber );
$dbh->do(
q{
INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
@ -436,9 +432,9 @@ subtest 'Test max_holds per library/patron category' => sub {
{},
'*', '*', 'TEST', 99, 99
);
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
my $count =
Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
@ -494,9 +490,9 @@ subtest 'Test max_holds per library/patron category' => sub {
subtest 'Pickup location availability tests' => sub {
plan tests => 4;
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
$biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
my ( $item_bibnum, $item_bibitemnum, $itemnumber )
= AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
= AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
#Add a default rule to allow some holds
$dbh->do(
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
@ -551,26 +547,26 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
# Create 3 biblios with items
my ($bibnum_1) = create_helper_biblio( $itemtype->itemtype );
my $biblio_1 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
my ( undef, undef, $itemnumber_1 ) = AddItem(
{ homebranch => $library->branchcode,
holdingbranch => $library->branchcode
},
$bibnum
$biblio_1->biblionumber
);
my ($bibnum_2) = create_helper_biblio( $itemtype->itemtype );
my $biblio_2 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
my ( undef, undef, $itemnumber_2 ) = AddItem(
{ homebranch => $library->branchcode,
holdingbranch => $library->branchcode
},
$bibnum_2
$biblio_2->biblionumber
);
my ($bibnum_3) = create_helper_biblio( $itemtype->itemtype );
my $biblio_3 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
my ( undef, undef, $itemnumber_3 ) = AddItem(
{ homebranch => $library->branchcode,
holdingbranch => $library->branchcode
},
$bibnum_3
$biblio_3->biblionumber
);
Koha::IssuingRules->search->delete;
@ -590,7 +586,7 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
'Patron can reserve item with hold limit of 1, no holds placed'
);
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
@ -608,7 +604,7 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
);
# Add a second reserve
my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
{ status => 'tooManyReservesToday', limit => 2 },
@ -644,14 +640,14 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
{ status => 'OK' },
'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
);
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
{ status => 'OK' },
'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
);
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_3, '', 1, );
AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_3->biblionumber, '', 1, );
is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
{ status => 'tooManyReserves', limit => 3 },
@ -660,16 +656,3 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
$schema->storage->txn_rollback;
};
# Helper method to set up a Biblio.
sub create_helper_biblio {
my $itemtype = shift;
my $bib = MARC::Record->new();
my $title = 'Silence in the library';
$bib->append_fields(
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
MARC::Field->new('245', ' ', ' ', a => $title),
MARC::Field->new('942', ' ', ' ', c => $itemtype),
);
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
}

23
t/db_dependent/Holds/LocalHoldsPriority.t

@ -40,15 +40,13 @@ my $itemtype = $builder->build(
my $borrowers_count = 5;
# Create a helper biblio
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
# Create a helper item for the biblio.
my $biblio = $builder->gimme_a_biblio();
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
{ homebranch => $library4->{branchcode},
holdingbranch => $library3->{branchcode},
itype => $itemtype
},
$bibnum
$biblio->biblionumber,
);
@ -67,21 +65,19 @@ foreach ( 1 .. $borrowers_count ) {
push @borrowernumbers, $borrowernumber;
}
my $biblionumber = $bibnum;
# Create five item level holds
my $i = 1;
foreach my $borrowernumber (@borrowernumbers) {
AddReserve(
$branchcodes[$i],
$borrowernumber,
$biblionumber,
$biblio->biblionumber,
my $bibitems = q{},
my $priority = $i,
my $resdate,
my $expdate,
my $notes = q{},
$title,
'a title',
my $checkitem,
my $found,
);
@ -116,14 +112,3 @@ t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary'
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
# Helper method to set up a Biblio.
sub create_helper_biblio {
my $bib = MARC::Record->new();
my $title = 'Silence in the library';
$bib->append_fields(
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
MARC::Field->new( '245', ' ', ' ', a => $title ),
);
return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
}

24
t/db_dependent/Holds/RevertWaitingStatus.t

@ -46,10 +46,7 @@ t::lib::Mocks::mock_userenv({ flags => 1, userid => '1', branchcode => $branchco
my $borrowers_count = 3;
# Create a biblio instance
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
# Create an item
my $biblio = $builder->gimme_a_biblio();
my $item_barcode = 'my_barcode';
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
{ homebranch => $branchcode,
@ -57,7 +54,7 @@ my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
barcode => $item_barcode,
itype => $itemtype
},
$bibnum
$biblio->biblionumber,
);
# Create some borrowers
@ -73,20 +70,18 @@ foreach my $i ( 1 .. $borrowers_count ) {
push @borrowernumbers, $borrowernumber;
}
my $biblionumber = $bibnum;
# Create five item level holds
foreach my $borrowernumber (@borrowernumbers) {
AddReserve(
$branchcode,
$borrowernumber,
$biblionumber,
$biblio->biblionumber,
my $bibitems = q{},
my $priority,
my $resdate,
my $expdate,
my $notes = q{},
$title,
'a title',
my $checkitem,
my $found,
);
@ -104,14 +99,3 @@ ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
$schema->storage->txn_rollback;
# Helper method to set up a Biblio.
sub create_helper_biblio {
my $bib = MARC::Record->new();
my $title = 'Silence in the library';
$bib->append_fields(
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
MARC::Field->new( '245', ' ', ' ', a => $title ),
);
return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
}

99
t/db_dependent/Items.t

@ -56,12 +56,12 @@ subtest 'General Add, Get and Del tests' => sub {
# Create a biblio instance for testing
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
my ($bibnum, $bibitemnum) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
# Add an item.
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
# Get item.
my $getitem = GetItem($itemnumber);
@ -74,29 +74,29 @@ subtest 'General Add, Get and Del tests' => sub {
# Do not modify anything, and do not explode!
my $dbh = C4::Context->dbh;
local $dbh->{RaiseError} = 1;
ModItem({}, $bibnum, $itemnumber);
ModItem({}, $biblio->biblionumber, $itemnumber);
# Modify item; setting barcode.
ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
my $moditem = GetItem($itemnumber);
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
# Delete item.
DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber });
DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
my $getdeleted = GetItem($itemnumber);
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
$getitem = GetItem($itemnumber);
is( $getitem->{location}, $location, "The location should not have been modified" );
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
ModItem({ location => $location }, $bibnum, $itemnumber);
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
$getitem = GetItem($itemnumber);
is( $getitem->{location}, $location, "The location should have been set to correct location" );
is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
ModItem({ location => 'CART' }, $bibnum, $itemnumber);
ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
$getitem = GetItem($itemnumber);
is( $getitem->{location}, 'CART', "The location should have been set to CART" );
is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
@ -168,7 +168,7 @@ subtest 'GetHiddenItemnumbers tests' => sub {
# Create a new biblio
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
my ($biblionumber, $biblioitemnumber) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
# Add two items
my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
@ -178,7 +178,7 @@ subtest 'GetHiddenItemnumbers tests' => sub {
withdrawn => 1,
itype => $itemtype->{itemtype},
},
$biblionumber
$biblio->biblionumber
);
my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
{
@ -187,7 +187,7 @@ subtest 'GetHiddenItemnumbers tests' => sub {
withdrawn => 0,
itype => $itemtype->{itemtype},
},
$biblionumber
$biblio->biblionumber
);
my $opachiddenitems;
@ -266,7 +266,7 @@ subtest 'GetItemsInfo tests' => sub {
});
# Add a biblio
my ($biblionumber, $biblioitemnumber) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
# Add an item
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
{
@ -274,7 +274,7 @@ subtest 'GetItemsInfo tests' => sub {
holdingbranch => $library2->{branchcode},
itype => $itemtype->{itemtype},
},
$biblionumber
$biblio->biblionumber
);
my $library = Koha::Libraries->find( $library1->{branchcode} );
@ -285,7 +285,7 @@ subtest 'GetItemsInfo tests' => sub {
$library->opac_info("holdingbranch OPAC info");
$library->store;
my @results = GetItemsInfo( $biblionumber );
my @results = GetItemsInfo( $biblio->biblionumber );
ok( @results, 'GetItemsInfo returns results');
is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
'GetItemsInfo returns the correct home branch OPAC info notice' );
@ -357,7 +357,7 @@ subtest 'SearchItems test' => sub {
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
my ($biblionumber) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
@ -366,12 +366,12 @@ subtest 'SearchItems test' => sub {
homebranch => $library1->{branchcode},
holdingbranch => $library1->{branchcode},
itype => $itemtype->{itemtype},
}, $biblionumber);
}, $biblio->biblionumber);
my (undef, undef, $item2_itemnumber) = AddItem({
homebranch => $library2->{branchcode},
holdingbranch => $library2->{branchcode},
itype => $itemtype->{itemtype},
}, $biblionumber);
}, $biblio->biblionumber);
my ($items, $total_results);
@ -476,7 +476,7 @@ subtest 'SearchItems test' => sub {
)
);
my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
$biblionumber);
$biblio->biblionumber);
# Search item where item subfield z is "foobar"
$filter = {
@ -498,7 +498,7 @@ subtest 'SearchItems test' => sub {
$cache->clear_from_cache("default_value_for_mod_marc-");
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
# Make sure the link is used
my $item3 = GetItem($item3_itemnumber);
@ -534,14 +534,14 @@ subtest 'Koha::Item(s) tests' => sub {
# Create a biblio and item for testing
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
my ($bibnum, $bibitemnum) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
{
homebranch => $library1->{branchcode},
holdingbranch => $library2->{branchcode},
itype => $itemtype->{itemtype},
},
$bibnum
$biblio->biblionumber
);
# Get item.
@ -575,7 +575,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
source => 'Itemtype',
});
my ( $biblionumber, $biblioitemnumber ) = get_biblio();
my $biblio = $builder->gimme_a_biblio();
my $item_infos = [
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
@ -598,7 +598,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
holdingbranch => $item_info->{holdingbanch},
itype => $itemtype->{itemtype},
},
$biblionumber
$biblio->biblionumber
);
push @itemnumbers, $itemnumber;
}
@ -608,32 +608,32 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
my ($itemfield) =
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
'Should carp is no record passed.';
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber });
biblionumber => $biblio->biblionumber });
my @items = $record->field($itemfield);
is( scalar @items, $number_of_items, 'Should return all items' );
my $marc_with_items = C4::Biblio::GetMarcBiblio({
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
embed_items => 1 });
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
@items = $record->field($itemfield);
is( scalar @items, 2, 'Should return all items present in the list' );
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
opac => 1 });
@items = $record->field($itemfield);
is( scalar @items, $number_of_items, 'Should return all items for opac' );
@ -644,7 +644,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber });
biblionumber => $biblio->biblionumber });
@items = $record->field($itemfield);
is( scalar @items,
$number_of_items,
@ -652,7 +652,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
opac => 1 });
@items = $record->field($itemfield);
is(
@ -666,7 +666,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
C4::Biblio::EmbedItemsInMarcBiblio({
marc_record => $record,
biblionumber => $biblionumber,
biblionumber => $biblio->biblionumber,
opac => 1 });
@items = $record->field($itemfield);
is(
@ -702,7 +702,7 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
# Create a record with a barcode
my ($biblionumber) = get_biblio( $framework->{frameworkcode} );
my $biblio = $builder->gimme_a_biblio({ frameworkcode => $framework->{frameworkcode} });
my $item_record = new MARC::Record;
my $a_barcode = 'a barcode';
my $barcode_field = MARC::Field->new(
@ -715,7 +715,7 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
y => $itemtype
);
$item_record->append_fields( $barcode_field );
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
# Make sure everything has been set up
my $item = GetItem($item_itemnumber);
@ -724,13 +724,13 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
# Delete the barcode field and save the record
$item_record->delete_fields( $barcode_field );
$item_record->append_fields( $itemtype_field ); # itemtype is mandatory
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
$item = GetItem($item_itemnumber);
is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
# Re-add the barcode field and save the record
$item_record->append_fields( $barcode_field );
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
$item = GetItem($item_itemnumber);
is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
@ -751,7 +751,7 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {