From 2075a22ed3c71196002dd8da28a061f791baf393 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 17 Mar 2019 23:12:46 -0300 Subject: [PATCH] Bug 23463: Replace AddItem calls with Koha::Item->store Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Items.pm | 23 ++-- Koha/EDI.pm | 19 ++- Koha/Item.pm | 35 +++++ acqui/addorderiso2709.pl | 35 ++--- t/db_dependent/Acquisition.t | 2 +- t/db_dependent/Acquisition/CancelReceipt.t | 6 +- t/db_dependent/Acquisition/TransferOrder.t | 10 +- t/db_dependent/Circulation.t | 15 +- t/db_dependent/Circulation/Branch.t | 25 ++-- .../Circulation/CheckIfIssuedToPatron.t | 4 +- .../Circulation/CheckValidBarcode.t | 6 +- .../Circulation/GetPendingOnSiteCheckouts.t | 8 +- t/db_dependent/Circulation/GetTopIssues.t | 10 +- .../IssuingRules/maxsuspensiondays.t | 6 +- t/db_dependent/Circulation/issue.t | 35 ++--- t/db_dependent/Circulation/transfers.t | 20 +-- t/db_dependent/CourseReserves.t | 12 +- t/db_dependent/Holds.t | 64 +++------ t/db_dependent/Holds/LocalHoldsPriority.t | 9 +- t/db_dependent/Holds/RevertWaitingStatus.t | 9 +- t/db_dependent/Items.t | 130 +++++++++++------- .../Items/AutomaticItemModificationByAge.t | 16 +-- t/db_dependent/Items/DelItem.t | 17 ++- t/db_dependent/Koha/BiblioUtils/Iterator.t | 2 +- t/db_dependent/Koha/Biblios.t | 20 ++- t/db_dependent/Koha/Items.t | 25 +++- t/db_dependent/Labels/t_Label.t | 10 +- t/db_dependent/Members/GetAllIssues.t | 11 +- t/db_dependent/Members/IssueSlip.t | 8 +- t/db_dependent/Patron/Borrower_Discharge.t | 15 +- t/db_dependent/Reserves.t | 117 ++++++++-------- t/db_dependent/RotatingCollections.t | 33 ++--- t/db_dependent/ShelfBrowser.t | 12 +- t/db_dependent/Template/Plugin/Branches.t | 1 - t/lib/TestBuilder.pm | 4 +- 35 files changed, 417 insertions(+), 357 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 9de9600ce9..e67b6a043e 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -27,7 +27,6 @@ BEGIN { @EXPORT = qw( AddItemFromMarc - AddItem AddItemBatchFromMarc ModItemFromMarc Item2Marc @@ -159,9 +158,17 @@ sub AddItemFromMarc { my $localitemmarc = MARC::Record->new; $localitemmarc->append_fields( $source_item_marc->field($itemtag) ); + +#RMME my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields ); + + my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); + $item_values->{biblionumber} = $biblionumber; + # FIXME RM my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); + my $item = Koha::Item->new( $item_values ); # FIXME Handle $unlinked_item_subfields + return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber ); } =head2 AddItem @@ -190,29 +197,15 @@ sub AddItem { my $biblionumber = shift; my $dbh = @_ ? shift : C4::Context->dbh; - my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode($biblionumber); my $unlinked_item_subfields; if (@_) { $unlinked_item_subfields = shift; } - # needs old biblionumber and biblioitemnumber - $item->{'biblionumber'} = $biblionumber; - my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); - $sth->execute( $item->{'biblionumber'} ); - ( $item->{'biblioitemnumber'} ) = $sth->fetchrow; - _set_defaults_for_add($item); _set_derived_columns_for_add($item); $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields); - # FIXME - checks here - unless ( $item->{itype} ) { # default to biblioitem.itemtype if no itype - my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); - $itype_sth->execute( $item->{'biblionumber'} ); - ( $item->{'itype'} ) = $itype_sth->fetchrow_array; - } - my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} ); return if $error; diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 0ab4658689..5bf0197184 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -29,7 +29,6 @@ use C4::Context; use Koha::Database; use C4::Acquisition qw( NewBasket CloseBasket ModOrder); use C4::Suggestions qw( ModSuggestion ); -use C4::Items qw(AddItem); use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField ); use Koha::Edifact::Order; use Koha::Edifact; @@ -718,9 +717,9 @@ sub quote_item { my $created = 0; while ( $created < $order_quantity ) { - my $itemnumber; - ( $bib->{biblionumber}, $bib->{biblioitemnumber}, $itemnumber ) - = AddItem( $item_hash, $bib->{biblionumber} ); + $item_hash->{biblionumber} = $bib->{biblionumber}; + my $item = Koha::Item->new( $item_hash ); + my $itemnumber = $item->itemnumber; $logger->trace("Added item:$itemnumber"); $schema->resultset('AqordersItem')->create( { @@ -809,9 +808,9 @@ sub quote_item { $item_hash->{homebranch} = $new_item->{homebranch}; } - my $itemnumber; - ( undef, undef, $itemnumber ) = - AddItem( $item_hash, $bib->{biblionumber} ); + $item_hash->{biblionumber} = $bib->{biblionumber}; + my $item = Koha::Item->new( $item_hash ); + my $itemnumber = $item->itemnumber; $logger->trace("New item $itemnumber added"); $schema->resultset('AqordersItem')->create( { @@ -878,9 +877,9 @@ sub quote_item { $item->girfield( 'branch', $occurrence ), homebranch => $item->girfield( 'branch', $occurrence ), }; - my $itemnumber; - ( undef, undef, $itemnumber ) = - AddItem( $new_item, $bib->{biblionumber} ); + $new_item->{biblionumber} = $bib->{biblionumber}; + my $item = Koha::Item->new( $new_item ); + my $itemnumber = $item->itemnumber; $logger->trace("New item $itemnumber added"); $schema->resultset('AqordersItem')->create( { diff --git a/Koha/Item.pm b/Koha/Item.pm index d2b1b9d154..1b3e555488 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -49,6 +49,41 @@ Koha::Item - Koha Item object class =cut +=head3 store + +=cut + +sub store { + my ($self) = @_; + + # We do not want to oblige callers to pass this value + # Dev conveniences vs performance? + unless ( $self->biblioitemnumber ) { + $self->biblioitemnumber( $self->biblio->biblioitem->biblioitemnumber ); + } + + # See related changes from C4::Items::AddItem + unless ( $self->itype ) { + $self->itype($self->biblio->biblioitem->itemtype); + } + + unless ( $self->in_storage ) { #AddItem + my $today = dt_from_string; + unless ( $self->permanent_location ) { + $self->permanent_location($self->location); + } + unless ( $self->replacementpricedate ) { + $self->replacementpricedate($today); + } + unless ( $self->datelastseen ) { + $self->datelastseen($today); + } + + } + + return $self->SUPER::store; +} + =head3 effective_itemtype Returns the itemtype for the item based on whether item level itemtypes are set or not. diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 224f38a0ab..1caee77950 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -220,22 +220,25 @@ if ($op eq ""){ my @itemnumbers; for (my $i = 0; $i < $count; $i++) { $itemcreation = 1; - my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ - homebranch => $homebranches[$i], - holdingbranch => $holdingbranches[$i], - itemnotes_nonpublic => $nonpublic_notes[$i], - itemnotes => $public_notes[$i], - location => $locs[$i], - ccode => $ccodes[$i], - itype => $itypes[$i], - notforloan => $notforloans[$i], - uri => $uris[$i], - copynumber => $copynos[$i], - price => $itemprices[$i], - replacementprice => $replacementprices[$i], - itemcallnumber => $itemcallnumbers[$i], - }, $biblionumber); - push( @itemnumbers, $itemnumber ); + my $item = Koha::Item->new( + { + biblionumber => $biblionumber, + homebranch => $homebranches[$i], + holdingbranch => $holdingbranches[$i], + itemnotes_nonpublic => $nonpublic_notes[$i], + itemnotes => $public_notes[$i], + location => $locs[$i], + ccode => $ccodes[$i], + itype => $itypes[$i], + notforloan => $notforloans[$i], + uri => $uris[$i], + copynumber => $copynos[$i], + price => $itemprices[$i], + replacementprice => $replacementprices[$i], + itemcallnumber => $itemcallnumbers[$i], + } + ); + push( @itemnumbers, $item->itemnumber ); } if ($itemcreation == 1) { # Group orderlines from MarcItemFieldsToOrder diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index a367aa8987..6fc9da3ca4 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -557,7 +557,7 @@ ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \ ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore"); my $order5 = GetOrder($ordernumbers[4]); -C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} ); +Koha::Item->new({ barcode => '0102030405', biblionumber => $order5->{biblionumber} })->store; $error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1); $order5 = GetOrder($order5->{ordernumber}); ok((defined $order5->{datecancellationprinted}), "order is cancelled"); diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index f659e9ef3a..fa2509678b 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -66,7 +66,7 @@ my $budgetid = C4::Budgets::AddBudget( my $budget = C4::Budgets::GetBudget( $budgetid ); my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); -my $itemnumber = AddItem( { itype => $itemtype }, $biblionumber ); +my $itemnumber = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber; my $order = Koha::Acquisition::Order->new( { @@ -92,8 +92,8 @@ CancelReceipt($ordernumber); is($order->items->count, 0, "Create items on receiving: 0 item exist after cancelling a receipt"); -my $itemnumber1 = AddItem( { itype => $itemtype }, $biblionumber ); -my $itemnumber2 = AddItem( { itype => $itemtype }, $biblionumber ); +my $itemnumber1 = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber; +my $itemnumber2 = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber; t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering'); t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7 diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index 7a5dcf71f9..2b0c107e8b 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -12,6 +12,7 @@ use Koha::Database; use Koha::DateUtils; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; +use t::lib::TestBuilder; use MARC::Record; my $schema = Koha::Database->new()->schema(); @@ -20,6 +21,8 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; +my $builder = t::lib::TestBuilder->new; + my $bookseller1 = Koha::Acquisition::Bookseller->new( { name => "my vendor 1", @@ -55,8 +58,9 @@ my $budgetid = C4::Budgets::AddBudget( my $budget = C4::Budgets::GetBudget( $budgetid ); -my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); -my $itemnumber = AddItem({}, $biblionumber); +my $biblio = $builder->build_sample_biblio(); +my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); +my $biblionumber = $biblio->biblionumber; my $order = Koha::Acquisition::Order->new( { @@ -67,7 +71,7 @@ my $order = Koha::Acquisition::Order->new( } )->store; my $ordernumber = $order->ordernumber; -$order->add_item( $itemnumber ); +$order->add_item( $item_1->itemnumber ); # Begin tests is(scalar GetOrders($basketno1), 1, "1 order in basket1"); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 9ee0ac27ac..e579e78b8e 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2742,15 +2742,16 @@ subtest '_FixAccountForLostAndFound' => sub { } } ); - my ( undef, undef, $item_id ) = AddItem( - { homebranch => $library->branchcode, + my $item_id = Koha::Item->new( + { + biblionumber => $biblio->biblionumber, + homebranch => $library->branchcode, holdingbranch => $library->branchcode, barcode => $barcode, replacementprice => $replacement_amount, itype => $item_type->itemtype }, - $biblio->biblionumber - ); + )->store->itemnumber; AddIssue( $patron->unblessed, $barcode ); @@ -3355,16 +3356,16 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { }); my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author }); - my ( undef, undef, $item_id ) = AddItem( + my $item_id = Koha::Item->new( { + biblionumber => $biblio->biblionumber, homebranch => $library->id, holdingbranch => $library->id, barcode => $barcode, replacementprice => 23.00, itype => $itemtype->id }, - $biblio->biblionumber - ); + )->store->itemnumber; my $item = Koha::Items->find( $item_id ); my $context = Test::MockModule->new('C4::Context'); diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t index 4da6d09c05..16e590fcc3 100644 --- a/t/db_dependent/Circulation/Branch.t +++ b/t/db_dependent/Circulation/Branch.t @@ -98,43 +98,40 @@ $record->append_fields( my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); # item 1 has home branch and holding branch samplebranch1 -my @sampleitem1 = C4::Items::AddItem( +my $item_id1 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => 'barcode_1', itemcallnumber => 'callnumber1', homebranch => $samplebranch1->{branchcode}, holdingbranch => $samplebranch1->{branchcode}, itype => $no_circ_itemtype->{ itemtype } - }, - $biblionumber -); -my $item_id1 = $sampleitem1[2]; + } +)->store->itemnumber; # item 2 has holding branch samplebranch2 -my @sampleitem2 = C4::Items::AddItem( +my $item_id2 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => 'barcode_2', itemcallnumber => 'callnumber2', homebranch => $samplebranch2->{branchcode}, holdingbranch => $samplebranch1->{branchcode}, itype => $no_circ_itemtype->{ itemtype } }, - $biblionumber -); -my $item_id2 = $sampleitem2[2]; +)->store->itemnumber; # item 3 has item type sampleitemtype2 with noreturn policy -my @sampleitem3 = C4::Items::AddItem( +my $item_id3 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => 'barcode_3', itemcallnumber => 'callnumber3', homebranch => $samplebranch2->{branchcode}, holdingbranch => $samplebranch2->{branchcode}, itype => $sampleitemtype2->{itemtype} - }, - $biblionumber -); -my $item_id3 = $sampleitem3[2]; + } +)->store->itemnumber; #Add borrower my $borrower_id1 = Koha::Patron->new({ diff --git a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t index bd398958a6..bc0d093855 100644 --- a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t +++ b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t @@ -61,10 +61,10 @@ my %item_info = ( my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); my $barcode1 = '0101'; -AddItem({ barcode => $barcode1, %item_info }, $biblionumber1); +Koha::Item->new({ barcode => $barcode1, %item_info, biblionumber => $biblionumber1 })->store; my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); my $barcode2 = '0202'; -AddItem({ barcode => $barcode2, %item_info }, $biblionumber2); +Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store; my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber; my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber; diff --git a/t/db_dependent/Circulation/CheckValidBarcode.t b/t/db_dependent/Circulation/CheckValidBarcode.t index 527a13332a..41305a84d3 100644 --- a/t/db_dependent/Circulation/CheckValidBarcode.t +++ b/t/db_dependent/Circulation/CheckValidBarcode.t @@ -67,10 +67,10 @@ $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode3); is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' ); my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); -AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1); -AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber1); +Koha::Item->new({ barcode => $barcode1, %item_branch_infos, biblionumber => $biblionumber1})->store; +Koha::Item->new({ barcode => $barcode2, %item_branch_infos, biblionumber => $biblionumber1})->store; my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); -AddItem({ barcode => $barcode3, %item_branch_infos }, $biblionumber2); +Koha::Item->new({ barcode => $barcode3, %item_branch_infos, biblionumber =>$biblionumber2})->store; $check_valid_barcode = C4::Circulation::CheckValidBarcode(); is( $check_valid_barcode, 0, 'CheckValidBarcode without barcode returns false' ); diff --git a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t b/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t index 236626cb70..33d186ceb4 100644 --- a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t +++ b/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t @@ -50,11 +50,11 @@ my %item_infos = ( ); my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); -my $itemnumber1 = AddItem({ barcode => '0101', %item_infos }, $biblionumber1); -my $itemnumber2 = AddItem({ barcode => '0102', %item_infos }, $biblionumber1); +my $itemnumber1 = Koha::Item->new({ barcode => '0101', %item_infos, biblionumber => $biblionumber1})->store->itemnumber; +my $itemnumber2 = Koha::Item->new({ barcode => '0102', %item_infos, biblionumber => $biblionumber1})->store->itemnumber; my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); -my $itemnumber3 = AddItem({ barcode => '0203', %item_infos }, $biblionumber2); +my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber; my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; my $borrowernumber = $builder->build( @@ -75,7 +75,7 @@ AddIssue($borrower, '0203'); my $onsite_checkouts = GetPendingOnSiteCheckouts; is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" ); -my $itemnumber4 = AddItem({ barcode => '0104', %item_infos }, $biblionumber1); +my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber; AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } ); $onsite_checkouts = GetPendingOnSiteCheckouts; is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" ); diff --git a/t/db_dependent/Circulation/GetTopIssues.t b/t/db_dependent/Circulation/GetTopIssues.t index 71a8cb319d..3ddeb43277 100644 --- a/t/db_dependent/Circulation/GetTopIssues.t +++ b/t/db_dependent/Circulation/GetTopIssues.t @@ -50,17 +50,19 @@ $c4_context->mock('userenv', sub { t::lib::Mocks::mock_preference('item-level_itypes', '0'); my $biblionumber = create_biblio('Test 1', $itemtype); -AddItem({ +Koha::Item->new({ + biblionumber => $biblionumber, barcode => 'GTI_BARCODE_001', homebranch => $branch_1->{ branchcode }, ccode => 'GTI_CCODE', -}, $biblionumber); +})->store; $biblionumber = create_biblio('Test 2', $itemtype); -AddItem({ +Koha::Item->new({ + biblionumber => $biblionumber, barcode => 'GTI_BARCODE_002', homebranch => $branch_2->{ branchcode }, -}, $biblionumber); +})->store; my $borrowernumber = Koha::Patron->new({ userid => 'gti.test', diff --git a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t index f29df5f94c..51d089d05d 100644 --- a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t +++ b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t @@ -6,7 +6,6 @@ use MARC::Field; use C4::Context; use C4::Circulation qw( AddIssue AddReturn ); -use C4::Items qw( AddItem ); use C4::Biblio qw( AddBiblio ); use Koha::Database; use Koha::DateUtils; @@ -60,12 +59,13 @@ $record->append_fields( my $barcode = 'bc_maxsuspensiondays'; my ($biblionumber, $biblioitemnumber) = AddBiblio($record, ''); -my (undef, undef, $itemnumber) = AddItem({ +my $itemnumber = Koha::Item->new({ + biblionumber => $biblionumber, homebranch => $branchcode, holdingbranch => $branchcode, barcode => $barcode, itype => $itemtype - } , $biblionumber); + })->store->itemnumber; # clear any holidays to avoid throwing off the suspension day # calculations diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index c2fcbaaf1a..6f312e4773 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -131,32 +131,27 @@ my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); my $barcode_1 = 'barcode_1'; my $barcode_2 = 'barcode_2'; -my @sampleitem1 = C4::Items::AddItem( +my $item_id1 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => $barcode_1, itemcallnumber => 'callnumber1', homebranch => $branchcode_1, holdingbranch => $branchcode_1, - issue => 1, - reserve => 1, itype => $itemtype }, - $biblionumber -); -my $item_id1 = $sampleitem1[2]; -my @sampleitem2 = C4::Items::AddItem( +)->store->itemnumber; +my $item_id2 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => $barcode_2, itemcallnumber => 'callnumber2', homebranch => $branchcode_2, holdingbranch => $branchcode_2, notforloan => 1, - issue => 1, itype => $itemtype }, - $biblionumber -); -my $item_id2 = $sampleitem2[2]; +)->store->itemnumber; #Add borrower my $borrower_id1 = Koha::Patron->new({ @@ -353,9 +348,9 @@ AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42')); $return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" ); ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" ); -my $itemnumber; -($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem( +my $itemnumber = Koha::Item->new( { + biblionumber => $biblionumber, barcode => 'barcode_3', itemcallnumber => 'callnumber3', homebranch => $branchcode_1, @@ -363,8 +358,7 @@ my $itemnumber; notforloan => 1, itype => $itemtype }, - $biblionumber -); +)->store->itemnumber; t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); AddReturn( 'barcode_3', $branchcode_1 ); @@ -380,18 +374,17 @@ AddReturn( 'barcode_3', $branchcode_1 ); $item = Koha::Items->find( $itemnumber ); ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} ); -my $itemnumber2; -($biblionumber, $biblioitemnumber, $itemnumber2) = C4::Items::AddItem( +my $itemnumber2 = Koha::Item->new( { + biblionumber => $biblionumber, barcode => 'barcode_4', itemcallnumber => 'callnumber4', homebranch => $branchcode_1, holdingbranch => $branchcode_1, - location => 'FIC', + location => 'FIC', itype => $itemtype - }, - $biblionumber -); + } +)->store->itemnumber; t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} ); AddReturn( 'barcode_4', $branchcode_1 ); diff --git a/t/db_dependent/Circulation/transfers.t b/t/db_dependent/Circulation/transfers.t index 28fce32581..3c53882df3 100644 --- a/t/db_dependent/Circulation/transfers.t +++ b/t/db_dependent/Circulation/transfers.t @@ -69,26 +69,26 @@ $record->append_fields( MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) ); my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); -my @sampleitem1 = C4::Items::AddItem( - { barcode => 1, +my $item_id1 = Koha::Item->new( + { + biblionumber => $biblionumber, + barcode => 1, itemcallnumber => 'callnumber1', homebranch => $branchcode_1, holdingbranch => $branchcode_1, itype => $itemtype }, - $biblionumber -); -my $item_id1 = $sampleitem1[2]; -my @sampleitem2 = C4::Items::AddItem( - { barcode => 2, +)->store->itemnumber; +my $item_id2 = Koha::Item->new( + { + biblionumber => $biblionumber, + barcode => 2, itemcallnumber => 'callnumber2', homebranch => $branchcode_1, holdingbranch => $branchcode_1, itype => $itemtype }, - $biblionumber -); -my $item_id2 = $sampleitem2[2]; +)->store->itemnumber; #Add transfers ModItemTransfer( diff --git a/t/db_dependent/CourseReserves.t b/t/db_dependent/CourseReserves.t index 42d8d1f670..a82cb48b89 100755 --- a/t/db_dependent/CourseReserves.t +++ b/t/db_dependent/CourseReserves.t @@ -17,13 +17,12 @@ use Modern::Perl; -use Test::More tests => 27; +use Test::More tests => 26; use Koha::Database; use t::lib::TestBuilder; BEGIN { - use_ok('C4::Items', qw(AddItem)); use_ok('C4::Biblio'); use_ok('C4::CourseReserves', qw/:all/); use_ok('C4::Context'); @@ -50,13 +49,14 @@ foreach (1..10) { # Create the a record with an item my $record = MARC::Record->new; my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, ''); -my ( undef, undef, $itemnumber ) = C4::Items::AddItem( - { homebranch => $branchcode, +my $itemnumber = Koha::Item->new( + { + biblionumber => $biblionumber, + homebranch => $branchcode, holdingbranch => $branchcode, itype => $itemtype }, - $biblionumber -); +)->store->itemnumber; my $course_id = ModCourse( course_name => "Test Course", diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index b648db8f4a..7b0e31cd93 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -58,8 +58,7 @@ $insert_sth->execute('ONLY1'); my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); # Create item instance for testing. -my ($item_bibnum, $item_bibitemnum, $itemnumber) - = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); +my $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber; # Create some borrowers my @borrowernumbers; @@ -148,7 +147,7 @@ is( $hold->suspend_until, '2013-01-01 00:00:00', "Test ModReserve, suspend until ModReserve({ # call without reserve_id rank => '3', - biblionumber => $item_bibnum, + biblionumber => $biblio->biblionumber, itemnumber => $itemnumber, borrowernumber => $borrowernumber, }); @@ -232,8 +231,7 @@ is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); # IndependentBranches is OFF. my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); -my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) - = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); +my $foreign_itemnumber = $builder->build_sample_item({ library => $branch_2, biblionumber => $foreign_biblio->biblionumber })->itemnumber; Koha::CirculationRules->set_rules( { categorycode => undef, @@ -287,7 +285,7 @@ ok( { # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); + $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber; my $reserveid1 = AddReserve( { branchcode => $branch_1, @@ -297,7 +295,7 @@ ok( } ); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); + $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber; my $reserveid2 = AddReserve( { branchcode => $branch_1, @@ -307,7 +305,7 @@ ok( } ); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); + $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber; my $reserveid3 = AddReserve( { branchcode => $branch_1, @@ -325,7 +323,7 @@ ok( is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); } -ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); +ModItem({ damaged => 1 }, $biblio->biblionumber, $itemnumber); t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); @@ -334,7 +332,7 @@ $hold = Koha::Hold->new( { borrowernumber => $borrowernumbers[0], itemnumber => $itemnumber, - biblionumber => $item_bibnum, + biblionumber => $biblio->biblionumber, } )->store(); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, @@ -348,7 +346,7 @@ ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d # Regression test for bug 9532 $biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); -($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber); +$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber; AddReserve( { branchcode => $branch_1, @@ -361,14 +359,14 @@ is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', "cannot request item if policy that matches on item-level item type forbids it" ); -ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); +ModItem({ itype => 'CAN' }, $biblio->biblionumber, $itemnumber); ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', "can request item if policy that matches on item type allows it" ); t::lib::Mocks::mock_preference('item-level_itypes', 0); -ModItem({ itype => undef }, $item_bibnum, $itemnumber); +ModItem({ itype => undef }, $biblio->biblionumber, $itemnumber); ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" @@ -410,14 +408,12 @@ Koha::CirculationRules->set_rules( } ); $biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); -($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( - { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber); +$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber; is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable', "CanItemBeReserved should return 'notReservable'"); t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); -($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( - { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber); +$itemnumber = $builder->build_sample_item({ library => $branch_2, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber; is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'cannotReserveFromOtherBranches', "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'"); @@ -426,8 +422,7 @@ is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'"); -($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( - { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber); +$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber; is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', "CanItemBeReserved should return 'OK'"); @@ -441,8 +436,7 @@ $dbh->do('DELETE FROM items'); $dbh->do('DELETE FROM biblio'); $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' }); -( $item_bibnum, $item_bibitemnum, $itemnumber ) - = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber ); +$itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber; Koha::CirculationRules->set_rules( { @@ -483,9 +477,7 @@ subtest 'Test max_holds per library/patron category' => sub { $dbh->do('DELETE FROM reserves'); $biblio = $builder->build_sample_biblio; - ( $item_bibnum, $item_bibitemnum, $itemnumber ) = - AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, - $biblio->biblionumber ); + $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber; Koha::CirculationRules->set_rules( { categorycode => undef, @@ -562,8 +554,7 @@ subtest 'Pickup location availability tests' => sub { plan tests => 4; $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' }); - my ( $item_bibnum, $item_bibitemnum, $itemnumber ) - = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber ); + $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber; #Add a default rule to allow some holds Koha::CirculationRules->set_rules( @@ -625,26 +616,11 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub { # Create 3 biblios with items my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype }); - my ( undef, undef, $itemnumber_1 ) = AddItem( - { homebranch => $library->branchcode, - holdingbranch => $library->branchcode - }, - $biblio_1->biblionumber - ); + my $itemnumber_1 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_1->biblionumber})->itemnumber; my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype }); - my ( undef, undef, $itemnumber_2 ) = AddItem( - { homebranch => $library->branchcode, - holdingbranch => $library->branchcode - }, - $biblio_2->biblionumber - ); + my $itemnumber_2 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_2->biblionumber})->itemnumber; my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype }); - my ( undef, undef, $itemnumber_3 ) = AddItem( - { homebranch => $library->branchcode, - holdingbranch => $library->branchcode - }, - $biblio_3->biblionumber - ); + my $itemnumber_3 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_3->biblionumber})->itemnumber; Koha::CirculationRules->search->delete; Koha::CirculationRules->set_rules( diff --git a/t/db_dependent/Holds/LocalHoldsPriority.t b/t/db_dependent/Holds/LocalHoldsPriority.t index 28849d2fb1..98ac219976 100755 --- a/t/db_dependent/Holds/LocalHoldsPriority.t +++ b/t/db_dependent/Holds/LocalHoldsPriority.t @@ -41,13 +41,14 @@ my $itemtype = $builder->build( my $borrowers_count = 5; my $biblio = $builder->build_sample_biblio(); -my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( - { homebranch => $library4->{branchcode}, +my $itemnumber = Koha::Item->new( + { + biblionumber => $biblio->biblionumber, + homebranch => $library4->{branchcode}, holdingbranch => $library3->{branchcode}, itype => $itemtype }, - $biblio->biblionumber, -); +)->store->itemnumber; my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} ); diff --git a/t/db_dependent/Holds/RevertWaitingStatus.t b/t/db_dependent/Holds/RevertWaitingStatus.t index 41a22e9e0a..feb4c83652 100755 --- a/t/db_dependent/Holds/RevertWaitingStatus.t +++ b/t/db_dependent/Holds/RevertWaitingStatus.t @@ -48,14 +48,15 @@ my $borrowers_count = 3; my $biblio = $builder->build_sample_biblio(); my $item_barcode = 'my_barcode'; -my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( - { homebranch => $branchcode, +my $itemnumber = Koha::Item->new( + { + biblionumber => $biblio->biblionumber, + homebranch => $branchcode, holdingbranch => $branchcode, barcode => $item_barcode, itype => $itemtype }, - $biblio->biblionumber, -); +)->store->itemnumber; # Create some borrowers my $patron_category = $builder->build({ source => 'Category' }); diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 981fa86e9e..c59cbf72f7 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -59,14 +59,22 @@ subtest 'General Add, Get and Del tests' => sub { my $biblio = $builder->build_sample_biblio(); # Add an item. - 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."); + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->{branchcode}, + location => $location, + itype => $itemtype->{itemtype} + } + ); + my $itemnumber = $item->itemnumber; + cmp_ok($item->biblionumber, '==', $biblio->biblionumber, "New item is linked to correct biblionumber."); + cmp_ok($item->biblioitemnumber, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber."); # Get item. my $getitem = Koha::Items->find($itemnumber); cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber."); - cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); + cmp_ok($getitem->biblioitemnumber, '==', $item->biblioitemnumber, "Retrieved item has correct biblioitemnumber."); # We are not testing anything useful here is( $getitem->location, $location, "The location should not have been modified" ); is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" ); @@ -86,7 +94,15 @@ subtest 'General Add, Get and Del tests' => sub { my $getdeleted = Koha::Items->find($itemnumber); is($getdeleted, 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} } , $biblio->biblionumber); + $itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->{branchcode}, + location => $location, + permanent_location => 'my permanent location', + itype => $itemtype->{itemtype} + } + )->itemnumber; $getitem = Koha::Items->find($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" ); @@ -226,25 +242,22 @@ subtest 'GetHiddenItemnumbers tests' => sub { my $biblio = $builder->build_sample_biblio(); # Add two items - my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem( + my $item1_itemnumber = $builder->build_sample_item( { - homebranch => $library1->{branchcode}, - holdingbranch => $library1->{branchcode}, - withdrawn => 1, - itype => $itemtype->{itemtype}, - }, - $biblio->biblionumber - ); - my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem( + biblionumber => $biblio->biblionumber, + library => $library1->{branchcode}, + withdrawn => 1, + itype => $itemtype->{itemtype} + } + )->itemnumber; + my $item2_itemnumber = $builder->build_sample_item( { - homebranch => $library2->{branchcode}, - holdingbranch => $library2->{branchcode}, - withdrawn => 0, - itype => $itemtype->{itemtype}, - }, - $biblio->biblionumber - ); - + biblionumber => $biblio->biblionumber, + library => $library2->{branchcode}, + withdrawn => 0, + itype => $itemtype->{itemtype} + } + )->itemnumber; my $opachiddenitems; my @itemnumbers = ($item1_itemnumber,$item2_itemnumber); my @hidden; @@ -333,15 +346,15 @@ subtest 'GetItemsInfo tests' => sub { # Add a biblio my $biblio = $builder->build_sample_biblio(); # Add an item - my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + my $itemnumber = $builder->build_sample_item( { + biblionumber => $biblio->biblionumber, homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode}, itype => $itemtype->{itemtype}, restricted => 1, - }, - $biblio->biblionumber - ); + } + )->itemnumber; my $library = Koha::Libraries->find( $library1->{branchcode} ); $library->opac_info("homebranch OPAC info"); @@ -373,7 +386,7 @@ subtest 'GetItemsInfo tests' => sub { is( $results[0]->{ has_pending_hold }, "0", 'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' ); - $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $item_bibnum, $itemnumber); + $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $biblio->biblionumber, $itemnumber); @results = GetItemsInfo( $biblio->biblionumber ); is( $results[0]->{ has_pending_hold }, "1", 'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' ); @@ -447,17 +460,20 @@ subtest 'SearchItems test' => sub { my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); # Add two items - my (undef, undef, $item1_itemnumber) = AddItem({ - homebranch => $library1->{branchcode}, - holdingbranch => $library1->{branchcode}, - itype => $itemtype->{itemtype}, - }, $biblio->biblionumber); - my (undef, undef, $item2_itemnumber) = AddItem({ - homebranch => $library2->{branchcode}, - holdingbranch => $library2->{branchcode}, - itype => $itemtype->{itemtype}, - issues => 3, - }, $biblio->biblionumber); + my $item1_itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library1->{branchcode}, + itype => $itemtype->{itemtype} + } + )->itemnumber; + my $item2_itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library2->{branchcode}, + itype => $itemtype->{itemtype} + } + )->itemnumber; my ($items, $total_results); @@ -639,15 +655,15 @@ subtest 'Koha::Item(s) tests' => sub { # Create a biblio and item for testing t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); - my $biblio = $builder->build_sample_biblio({title => 'Silence in the library'}); - my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + my $biblio = $builder->build_sample_biblio(); + my $itemnumber = $builder->build_sample_item( { + biblionumber => $biblio->biblionumber, homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode}, - itype => $itemtype->{itemtype}, - }, - $biblio->biblionumber - ); + itype => $itemtype->{itemtype} + } + )->itemnumber; # Get item. my $item = Koha::Items->find( $itemnumber ); @@ -662,8 +678,8 @@ subtest 'Koha::Item(s) tests' => sub { is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" ); $biblio = $item->biblio(); - is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" ); - is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' ); + is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" ); + is( $item->biblio->title(), $biblio->title, 'Title matches biblio title' ); $schema->storage->txn_rollback; }; @@ -701,14 +717,15 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { my @itemnumbers; for my $item_info (@$item_infos) { - my ( undef, undef, $itemnumber ) = AddItem( + my $itemnumber = $builder->build_sample_item( { + biblionumber => $biblio->biblionumber, homebranch => $item_info->{homebranch}, - holdingbranch => $item_info->{holdingbanch}, - itype => $itemtype->{itemtype}, - }, - $biblio->biblionumber - ); + holdingbranch => $item_info->{holdingbranch}, + itype => $itemtype->{itemtype} + } + )->itemnumber; + push @itemnumbers, $itemnumber; } @@ -980,7 +997,14 @@ subtest 'Test logging for ModItem' => sub { my $biblio = $builder->build_sample_biblio(); # Add an item. - my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber); + my $itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->{homebranch}, + location => $location, + itype => $itemtype->{itemtype} + } + )->itemnumber; # False means no logging $schema->resultset('ActionLog')->search()->delete(); diff --git a/t/db_dependent/Items/AutomaticItemModificationByAge.t b/t/db_dependent/Items/AutomaticItemModificationByAge.t index 33f85ecbbb..86f2eb32dd 100644 --- a/t/db_dependent/Items/AutomaticItemModificationByAge.t +++ b/t/db_dependent/Items/AutomaticItemModificationByAge.t @@ -53,17 +53,15 @@ $record->append_fields( ); my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, $frameworkcode); -my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( +my $item = $builder->build_sample_item( { - homebranch => $library, - holdingbranch => $library, - new_status => 'new_value', - ccode => 'FIC', - }, - $biblionumber + biblionumber => $biblionumber, + library => $library, + new_status => 'new_value', + ccode => 'FIC', + } ); - -my $item = Koha::Items->find( $itemnumber ); +my $itemnumber = $item->itemnumber; is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| ); my ( $tagfield, undef ) = GetMarcFromKohaField( 'items.itemnumber' ); diff --git a/t/db_dependent/Items/DelItem.t b/t/db_dependent/Items/DelItem.t index b8b61a538b..5f2355f1e3 100644 --- a/t/db_dependent/Items/DelItem.t +++ b/t/db_dependent/Items/DelItem.t @@ -20,17 +20,24 @@ my $library = $builder->build({ my $biblio = $builder->build_sample_biblio(); -my ( $item_bibnum, $item_bibitemnum, $itemnumber ); -( $item_bibnum, $item_bibitemnum, $itemnumber ) = - AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber ); +my $itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->{branchcode} + } +)->itemnumber; my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } ); is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); my $deleted_item = Koha::Items->find($itemnumber); is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." ); -( $item_bibnum, $item_bibitemnum, $itemnumber ) = - AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber ); +$itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->{branchcode} + } +)->itemnumber; $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } ); is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); $deleted_item = Koha::Items->find($itemnumber); diff --git a/t/db_dependent/Koha/BiblioUtils/Iterator.t b/t/db_dependent/Koha/BiblioUtils/Iterator.t index c2c5a39f28..ecc6db365c 100644 --- a/t/db_dependent/Koha/BiblioUtils/Iterator.t +++ b/t/db_dependent/Koha/BiblioUtils/Iterator.t @@ -50,7 +50,7 @@ t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); my $biblio = $builder->build_sample_biblio(); # Add an item. -my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber); +$builder->build_sample_item({ biblionumber => $biblio->biblionumber }); my $rs = $schema->resultset('Biblioitem')->search({}); my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 ); diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index 45ceb1a6c5..a6af46d288 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -144,9 +144,12 @@ subtest 'can_be_transferred' => sub { my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' }); - my ($item_bibnum, $item_bibitemnum, $itemnumber) - = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber); - my $item = Koha::Items->find($itemnumber); + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library1->branchcode + } + ); is(Koha::Item::Transfer::Limits->search({ fromBranch => $library1->branchcode, @@ -174,9 +177,14 @@ subtest 'can_be_transferred' => sub { is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' .'items is already located at to-library, then the transfer is possible.'); $item->holdingbranch($library1->branchcode)->store; - my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) - = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $biblio->biblionumber); - my $item2 = Koha::Items->find($itemnumber2); + + my $item2 = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + homebranch => $library1->branchcode, + holdingbranch => $library3->branchcode, + } + ); is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' .'another item that should have no transfer limits applying on, then ' .'the transfer is possible.'); diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 94d9a45714..d04559a16d 100644 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::Exception; use C4::Circulation; @@ -28,9 +28,11 @@ use Koha::Item; use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use t::lib::TestBuilder; use t::lib::Mocks; +use t::lib::Dates; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -61,6 +63,27 @@ is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber ); is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); +subtest 'store' => sub { + plan tests => 4; + my $biblio = $builder->build_sample_biblio; + my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); + my $item = Koha::Item->new( + { + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + biblionumber => $biblio->biblionumber, + location => 'my_loc', + } + )->store + ->get_from_storage; + + is( t::lib::Dates::compare($item->replacementpricedate, $today), 0, 'replacementpricedate must have been set to today if not given'); + is( t::lib::Dates::compare($item->datelastseen, $today), 0, 'datelastseen must have been set to today if not given'); + is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given'); + is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' ); + $item->delete; +}; + subtest 'get_transfer' => sub { plan tests => 3; diff --git a/t/db_dependent/Labels/t_Label.t b/t/db_dependent/Labels/t_Label.t index d553a0127b..93e3c92a69 100644 --- a/t/db_dependent/Labels/t_Label.t +++ b/t/db_dependent/Labels/t_Label.t @@ -62,8 +62,16 @@ t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); my $bibnum = $builder->build_sample_biblio({ frameworkcode => $frameworkcode })->biblionumber; +# Create a helper item instance for testing my $item = $builder->build_sample_item( - { library => $branch_1, itype => $itemtype, biblionumber => $bibnum, enumchron => "enum", copynumber => "copynum" } ); + { + library => $branch_1, + itype => $itemtype, + biblionumber => $bibnum, + enumchron => "enum", + copynumber => "copynum" + } +); my $itemnumber = $item->itemnumber; # Modify item; setting barcode. diff --git a/t/db_dependent/Members/GetAllIssues.t b/t/db_dependent/Members/GetAllIssues.t index bffd0cbcdc..54cc5cb203 100644 --- a/t/db_dependent/Members/GetAllIssues.t +++ b/t/db_dependent/Members/GetAllIssues.t @@ -54,14 +54,13 @@ my %item_infos = ( ); my ($biblionumber1) = AddBiblio( MARC::Record->new, '' ); -my $itemnumber1 = - AddItem( { barcode => '0101', %item_infos }, $biblionumber1 ); -my $itemnumber2 = - AddItem( { barcode => '0102', %item_infos }, $biblionumber1 ); + +# FIXME These tests will fail if the barcode exists in DB +my $itemnumber1 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => '0101', %item_infos })->itemnumber; +my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => '0102', %item_infos })->itemnumber; my ($biblionumber2) = AddBiblio( MARC::Record->new, '' ); -my $itemnumber3 = - AddItem( { barcode => '0203', %item_infos }, $biblionumber2 ); +my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, barcode => '0202', %item_infos })->itemnumber; my $borrowernumber1 = Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber; diff --git a/t/db_dependent/Members/IssueSlip.t b/t/db_dependent/Members/IssueSlip.t index 2280045f27..0ec870d18e 100644 --- a/t/db_dependent/Members/IssueSlip.t +++ b/t/db_dependent/Members/IssueSlip.t @@ -95,7 +95,7 @@ $dbh->do(q| |, {}, $quick_slip_content); my ( $title1, $title2 ) = ( 'My title 1', 'My title 2' ); -my ( $barcode1, $barcode2 ) = ('BC0101', 'BC0202' ); +my ( $barcode1, $barcode2 ) = ('BC0101', 'BC0202' ); # FIXME Must not be hardcoded, tests could fail my $record = MARC::Record->new; $record->append_fields( MARC::Field->new( @@ -104,8 +104,7 @@ $record->append_fields( ), ); my ($biblionumber1) = AddBiblio( $record, '' ); -my $itemnumber1 = - AddItem( { barcode => $barcode1, %item_infos }, $biblionumber1 ); +my $itemnumber1 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => $barcode1, %item_infos })->itemnumber; $record = MARC::Record->new; $record->append_fields( @@ -115,8 +114,7 @@ $record->append_fields( ), ); my ($biblionumber2) = AddBiblio( $record, '' ); -my $itemnumber2 = - AddItem( { barcode => $barcode2, %item_infos }, $biblionumber2 ); +my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, barcode => $barcode2, %item_infos })->itemnumber; my $borrowernumber = Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber; diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t index 3a5ddd9012..8c74219537 100644 --- a/t/db_dependent/Patron/Borrower_Discharge.t +++ b/t/db_dependent/Patron/Borrower_Discharge.t @@ -20,7 +20,6 @@ use Test::Warn; use MARC::Record; use C4::Circulation qw( AddIssue AddReturn ); -use C4::Items qw( AddItem ); use C4::Biblio qw( AddBiblio ); use C4::Context; @@ -72,13 +71,13 @@ my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} ); # Discharge not possible with issues my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); my $barcode = 'BARCODE42'; -my ( undef, undef, $itemnumber ) = AddItem( - { homebranch => $library->{branchcode}, - holdingbranch => $library->{branchcode}, - barcode => $barcode, - itype => $itemtype - }, - $biblionumber +$builder->build_sample_item( + { + biblionumber => $biblionumber, + library => $library->{branchcode}, + barcode => $barcode, + itype => $itemtype + } ); AddIssue( $patron, $barcode ); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index ef47e26473..ed3d09588f 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -85,13 +85,7 @@ t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber; # Create a helper item instance for testing -my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( - { homebranch => $branch_1, - holdingbranch => $branch_1, - itype => $itemtype - }, - $bibnum -); +my $itemnumber = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype })->itemnumber; my $biblio_with_no_item = $builder->build({ source => 'Biblio' @@ -127,13 +121,13 @@ AddReserve( } ); -my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode); +my ($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber, $barcode); is($status, "Reserved", "CheckReserves Test 1"); ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response'); -($status, $reserve, $all_reserves) = CheckReserves($itemnumber); +($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber); is($status, "Reserved", "CheckReserves Test 2"); ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode); @@ -227,23 +221,22 @@ Koha::CirculationRules->set_rules( my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber; my ($itemnum_cpl, $itemnum_fpl); -( undef, undef, $itemnum_cpl ) = AddItem( - { homebranch => $branch_1, - holdingbranch => $branch_1, - barcode => 'bug10272_CPL', - itype => $itemtype - }, - $bibnum2 -); -( undef, undef, $itemnum_fpl ) = AddItem( - { homebranch => $branch_2, - holdingbranch => $branch_2, - barcode => 'bug10272_FPL', - itype => $itemtype - }, - $bibnum2 -); - +$itemnum_cpl = $builder->build_sample_item( + { + biblionumber => $bibnum2, + library => $branch_1, + barcode => 'bug10272_CPL', + itype => $itemtype + } +)->itemnumber; +$itemnum_fpl = $builder->build_sample_item( + { + biblionumber => $bibnum2, + library => $branch_2, + barcode => 'bug10272_FPL', + itype => $itemtype + } +)->itemnumber; # Ensure that priorities are numbered correcly when a hold is moved to waiting # (bug 11947) @@ -354,9 +347,9 @@ AddReserve( priority => 1, } ); -($status)=CheckReserves($itemnumber,undef,undef); +($status)=CheckReserves($item->itemnumber,undef,undef); is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead'); -($status)=CheckReserves($itemnumber,undef,7); +($status)=CheckReserves($item->itemnumber,undef,7); is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead'); # Test 9761b: Add a reserve with future date, CheckReserve should not return it @@ -374,13 +367,13 @@ AddReserve( reservation_date => $resdate, } ); -($status)=CheckReserves($itemnumber,undef,undef); +($status)=CheckReserves($item->itemnumber,undef,undef); is( $status, '', 'CheckReserves returns no future reserve without lookahead'); # Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough -($status)=CheckReserves($itemnumber,undef,3); +($status)=CheckReserves($item->itemnumber,undef,3); is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead'); -($status)=CheckReserves($itemnumber,undef,4); +($status)=CheckReserves($item->itemnumber,undef,4); is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead'); # Test 9761d: Check ResFound message of AddReturn for future hold @@ -400,12 +393,12 @@ is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve with # test marking a hold as captured my $hold_notice_count = count_hold_print_messages(); -ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); +ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); my $new_count = count_hold_print_messages(); is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); # test that duplicate notices aren't generated -ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); +ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); $new_count = count_hold_print_messages(); is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); @@ -452,13 +445,13 @@ AddReserve( biblionumber => $bibnum, priority => 1, reservation_date => $resdate, - itemnumber => $itemnumber, + itemnumber => $item->itemnumber, } ); #item level hold $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); is( $future_holds->count, 0, 'current_holds does not return a future item level hold' ); # 9788c: current_holds returns future wait (confirmed future hold) -ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0); #confirm hold +ModReserveAffect( $item->itemnumber, $requesters{$branch_1} , 0); #confirm hold $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' ); # End of tests for bug 9788 @@ -488,12 +481,12 @@ AddReserve( borrowernumber => $requesters{$branch_1}, biblionumber => $bibnum, priority => $p, - itemnumber => $itemnumber, + itemnumber => $item->itemnumber, } ); $p = C4::Reserves::CalculatePriority($bibnum); is($p, 2, 'CalculatePriority should now return priority 2'); -ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0); +ModReserveAffect( $item->itemnumber, $requesters{$branch_1} , 0); $p = C4::Reserves::CalculatePriority($bibnum); is($p, 1, 'CalculatePriority should now return priority 1'); #add another biblio hold, no resdate @@ -533,11 +526,11 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $requesters{$branch_1}, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, } ); -my (undef, $canres, undef) = CheckReserves($itemnumber); +my (undef, $canres, undef) = CheckReserves($item->itemnumber); is( CanReserveBeCanceledFromOpac(), undef, 'CanReserveBeCanceledFromOpac should return undef if called without any parameter' @@ -559,7 +552,7 @@ is($cancancel, 1, 'Can user cancel its own reserve'); $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2}); is($cancancel, 0, 'Other user cant cancel reserve'); -ModReserveAffect($itemnumber, $requesters{$branch_1}, 1); +ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1); $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); is($cancancel, 0, 'Reserve in transfer status cant be canceled'); @@ -568,13 +561,13 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $requesters{$branch_1}, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, } ); -(undef, $canres, undef) = CheckReserves($itemnumber); +(undef, $canres, undef) = CheckReserves($item->itemnumber); -ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); +ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); is($cancancel, 0, 'Reserve in waiting status cant be canceled'); @@ -613,8 +606,6 @@ is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{bibl ####### EO Bug 13113 <<< #### -$item = Koha::Items->find($itemnumber); - ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" ); my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode }; @@ -653,25 +644,25 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber ); is( $status, '', 'MoveReserve filled hold'); # hold from A waiting, today, no fut holds: MoveReserve should fill it AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, found => 'W', } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber ); is( $status, '', 'MoveReserve filled waiting hold'); # hold from A pos 1, tomorrow, no fut holds: not filled $resdate= dt_from_string(); @@ -681,13 +672,13 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, reservation_date => $resdate, } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber, undef, 1 ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber, undef, 1 ); is( $status, 'Reserved', 'MoveReserve did not fill future hold'); $dbh->do('DELETE FROM reserves', undef, ($bibnum)); # hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it @@ -696,26 +687,26 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, reservation_date => $resdate, } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber, undef, 2 ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber, undef, 2 ); is( $status, '', 'MoveReserve filled future hold now'); # hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, reservation_date => $resdate, } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber, undef, 2 ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber, undef, 2 ); is( $status, '', 'MoveReserve filled future waiting hold now'); # hold from A pos 1, today+3, fut holds=2: MoveReserve should not fill it $resdate= dt_from_string(); @@ -725,13 +716,13 @@ AddReserve( { branchcode => $branch_1, borrowernumber => $borrowernumber, - biblionumber => $item_bibnum, + biblionumber => $bibnum, priority => 1, reservation_date => $resdate, } ); -MoveReserve( $itemnumber, $borrowernumber ); -($status)=CheckReserves( $itemnumber, undef, 3 ); +MoveReserve( $item->itemnumber, $borrowernumber ); +($status)=CheckReserves( $item->itemnumber, undef, 3 ); is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days'); $dbh->do('DELETE FROM reserves', undef, ($bibnum)); diff --git a/t/db_dependent/RotatingCollections.t b/t/db_dependent/RotatingCollections.t index cbe3dcf005..4bc5ffa932 100644 --- a/t/db_dependent/RotatingCollections.t +++ b/t/db_dependent/RotatingCollections.t @@ -24,6 +24,8 @@ use C4::Biblio; use Koha::Database; use Koha::Library; +use t::lib::TestBuilder; + BEGIN { } @@ -58,6 +60,8 @@ $dbh->do(q|DELETE FROM collections |); $dbh->do(q|DELETE FROM branches |); $dbh->do(q|DELETE FROM categories|); +my $builder = t::lib::TestBuilder->new; + #Test CreateCollection my $collections = GetCollections(); my $countcollection = scalar(@$collections); @@ -218,26 +222,23 @@ $record->append_fields( ) ); my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); -my @sampleitem1 = C4::Items::AddItem( +my $item_id1 = $builder->build_sample_item( { - barcode => 1, + biblionumber => $biblionumber, + library => $samplebranch->{branchcode}, + barcode => 1, # FIXME This must not be hardcoded! itemcallnumber => 'callnumber1', - homebranch => $samplebranch->{branchcode}, - holdingbranch => $samplebranch->{branchcode} - }, - $biblionumber -); -my $item_id1 = $sampleitem1[2]; -my @sampleitem2 = C4::Items::AddItem( + } +)->itemnumber; +my $item_id2 = $builder->build_sample_item( { - barcode => 2, + biblionumber => $biblionumber, + library => $samplebranch->{branchcode}, + barcode => 2, # FIXME This must not be hardcoded! itemcallnumber => 'callnumber2', - homebranch => $samplebranch->{branchcode}, - holdingbranch => $samplebranch->{branchcode} - }, - $biblionumber -); -my $item_id2 = $sampleitem2[2]; + } +)->itemnumber; + is( AddItemToCollection( $collection_id1, $item_id1 ), 1, "Sampleitem1 has been added to Collection1" ); is( AddItemToCollection( $collection_id1, $item_id2 ), diff --git a/t/db_dependent/ShelfBrowser.t b/t/db_dependent/ShelfBrowser.t index f4dd9b9d78..ada817806b 100644 --- a/t/db_dependent/ShelfBrowser.t +++ b/t/db_dependent/ShelfBrowser.t @@ -62,11 +62,13 @@ $record->append_fields( my ( $biblionumber ) = C4::Biblio::AddBiblio($record, ''); for my $callnumber ( shuffle @callnumbers ) { - my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({ - homebranch => $library->{branchcode}, - holdingbranch => $library->{branchcode}, - itemcallnumber => $callnumber, - }, $biblionumber); + my $itemnumber = $builder->build_sample_item( + { + biblionumber => $biblionumber, + library => $library->{branchcode}, + itemcallnumber => $callnumber, + } + )->itemnumber; $cn->{$callnumber} = { biblionumber => $biblionumber, itemnumber => $itemnumber, diff --git a/t/db_dependent/Template/Plugin/Branches.t b/t/db_dependent/Template/Plugin/Branches.t index be0d1134f9..103476b236 100644 --- a/t/db_dependent/Template/Plugin/Branches.t +++ b/t/db_dependent/Template/Plugin/Branches.t @@ -21,7 +21,6 @@ use Test::MockModule; use C4::Context; use C4::Biblio qw(AddBiblio); -use C4::Items qw(AddItem); use Koha::Database; use Clone qw(clone); diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 3329d451e9..f5226fd39e 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -182,8 +182,7 @@ sub build_sample_item { my $library = delete $args->{library} || $self->build_object( { class => 'Koha::Libraries' } )->branchcode; - my $itype = delete $args->{itype} - || $self->build_object( { class => 'Koha::ItemTypes' } )->itemtype; + # If itype is not passed it will be picked from the biblio (see Koha::Item->store) my $barcode = delete $args->{barcode} || $self->_gen_text( { info => { size => SIZE_BARCODE } } ); @@ -193,7 +192,6 @@ sub build_sample_item { homebranch => $library, holdingbranch => $library, barcode => $barcode, - itype => $itype, %$args, }, $biblionumber -- 2.39.5