Bugzilla – Attachment 95902 Details for
Bug 23463
Move C4::Items CRUD subroutines to Koha::Item
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23463: Replace AddItem calls with Koha::Item->store
Bug-23463-Replace-AddItem-calls-with-KohaItem-stor.patch (text/plain), 79.13 KB, created by
Jonathan Druart
on 2019-12-02 12:04:24 UTC
(
hide
)
Description:
Bug 23463: Replace AddItem calls with Koha::Item->store
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-12-02 12:04:24 UTC
Size:
79.13 KB
patch
obsolete
>From 1304239220d8acb32900a2f676b52c742af914f9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Sun, 17 Mar 2019 23:12:46 -0300 >Subject: [PATCH] Bug 23463: Replace AddItem calls with Koha::Item->store > >--- > 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 ++-- > t/db_dependent/Circulation/CheckIfIssuedToPatron.t | 4 +- > t/db_dependent/Circulation/CheckValidBarcode.t | 6 +- > .../Circulation/GetPendingOnSiteCheckouts.t | 8 +- > t/db_dependent/Circulation/GetTopIssues.t | 10 +- > .../Circulation/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 | 65 ++++------- > t/db_dependent/Holds/LocalHoldsPriority.t | 9 +- > t/db_dependent/Holds/RevertWaitingStatus.t | 9 +- > t/db_dependent/Items.t | 129 ++++++++++++--------- > .../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 | 23 ++++ > t/db_dependent/Labels/t_Label.t | 13 +-- > 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 | 118 +++++++++---------- > 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, 414 insertions(+), 362 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index f63e3e1763..d51a721ac7 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -28,7 +28,6 @@ BEGIN { > > @EXPORT = qw( > AddItemFromMarc >- AddItem > AddItemBatchFromMarc > ModItemFromMarc > Item2Marc >@@ -160,9 +159,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 >@@ -191,29 +198,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..36e6c8831c 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 a9cca3f727..333fbb8a36 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -48,6 +48,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 781a235ada..3188b84372 100755 >--- a/t/db_dependent/Acquisition.t >+++ b/t/db_dependent/Acquisition.t >@@ -536,7 +536,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 2cf83118b6..3471435548 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -2426,15 +2426,16 @@ subtest '_FixAccountForLostAndReturned' => 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 ); > >@@ -3011,16 +3012,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 dfd65d33d2..91ad173769 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 d2602263f3..fcacd4b702 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; >@@ -61,12 +60,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 81d98bdd5f..d3fe947277 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({ >@@ -346,9 +341,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, >@@ -356,8 +351,7 @@ my $itemnumber; > notforloan => 1, > itype => $itemtype > }, >- $biblionumber >-); >+)->store->itemnumber; > > t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); > AddReturn( 'barcode_3', $branchcode_1 ); >@@ -373,18 +367,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 f7919b3827..7d0ffd65ed 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; >@@ -152,7 +151,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, > }); >@@ -241,8 +240,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; > $dbh->do('DELETE FROM issuingrules'); > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) >@@ -284,13 +282,14 @@ ok( > ); > > { >+ my $item_bibnum;my $item_bibitemnum; > # 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($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); >- ($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($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); >- ($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($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); > my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); > my $hold3 = Koha::Holds->find( $reserveid3 ); >@@ -300,7 +299,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" ); >@@ -309,7 +308,7 @@ $hold = Koha::Hold->new( > { > borrowernumber => $borrowernumbers[0], > itemnumber => $itemnumber, >- biblionumber => $item_bibnum, >+ biblionumber => $biblio->biblionumber, > } > )->store(); > is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, >@@ -323,7 +322,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( > $branch_1, > $borrowernumbers[0], >@@ -335,14 +334,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)" >@@ -382,14 +381,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'"); >@@ -398,8 +395,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'"); > >@@ -413,8 +409,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; > > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) >@@ -445,9 +440,7 @@ subtest 'Test max_holds per library/patron category' => sub { > $dbh->do('DELETE FROM circulation_rules'); > > $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' }); >- ( $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; > $dbh->do( > q{ > INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) >@@ -515,8 +508,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 > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) >@@ -572,26 +564,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::IssuingRules->search->delete; > my $issuingrule = Koha::IssuingRule->new( >diff --git a/t/db_dependent/Holds/LocalHoldsPriority.t b/t/db_dependent/Holds/LocalHoldsPriority.t >index 0ecb9d124c..a41515bc1e 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 30228dfcef..266fb066d9 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 3f466b24aa..0a318f7d71 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -60,14 +60,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" ); > >@@ -87,7 +95,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" ); >@@ -172,25 +188,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; >@@ -279,15 +292,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"); >@@ -316,7 +329,7 @@ subtest 'GetItemsInfo tests' => sub { > t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 ); > #place item into holds queue > my $dbh = C4::Context->dbh; >- $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 not AllowItemsOnHoldCheckout' ); >@@ -395,16 +408,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}, >- }, $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); > >@@ -567,15 +584,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 ); >@@ -590,8 +607,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; > }; >@@ -629,14 +646,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; > } > >@@ -908,7 +926,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 2f62524505..6bc7069d07 100644 >--- a/t/db_dependent/Koha/Biblios.t >+++ b/t/db_dependent/Koha/Biblios.t >@@ -145,9 +145,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, >@@ -175,9 +178,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 5f97d46c06..b40244f2b6 100644 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -27,9 +27,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; >@@ -58,6 +60,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 069512c011..1a25eb4b7c 100644 >--- a/t/db_dependent/Labels/t_Label.t >+++ b/t/db_dependent/Labels/t_Label.t >@@ -62,14 +62,13 @@ 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( >+my $itemnumber = $builder->build_sample_item( > { >- homebranch => $branch_1, >- holdingbranch => $branch_1, >- itype => $itemtype >- }, >- $bibnum >-); >+ biblionumber => $bibnum, >+ library => $branch_1, >+ itype => $itemtype, >+ } >+)->itemnumber; > > # Modify item; setting barcode. > my $testbarcode = '97531'; >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 618f0598c9..5f39ad17f7 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' >@@ -130,13 +124,13 @@ AddReserve($branchcode, $borrowernumber, $biblionumber, > $bibitems, $priority, $resdate, $expdate, $notes, > 'a title', $checkitem, $found); > >-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) >@@ -320,9 +313,9 @@ $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); > AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, > 'a title', $checkitem, $found); >-($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 >@@ -335,13 +328,13 @@ $expdate= undef; #no expdate > AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, > 'a title', $checkitem, $found); >-($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 >@@ -361,12 +354,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)'); > >@@ -392,7 +385,6 @@ $resdate=output_pref($resdate); > AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, > 'a title', $checkitem, $found); >-my $item = Koha::Items->find( $itemnumber ); > $holds = $item->current_holds; > my $dtf = Koha::Database->new->schema->storage->datetime_parser; > my $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); >@@ -401,11 +393,11 @@ is( $future_holds->count, 0, 'current_holds does not return a future next availa > $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); > AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, >- 'a title', $itemnumber, $found); #item level hold >+ 'a title', $item->itemnumber, $found); #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 >@@ -427,10 +419,10 @@ is($p, 1, 'CalculatePriority should now return priority 1'); > #add a new reserve and confirm it to waiting > AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, $p, $resdate, $expdate, $notes, >- 'a title', $itemnumber, $found); >+ 'a title', $item->itemnumber, $found); > $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 >@@ -455,10 +447,10 @@ is($p, 3, 'CalculatePriority should now return priority 3'); > > # Tests for cancel reserves by users from OPAC. > $dbh->do('DELETE FROM reserves', undef, ($bibnum)); >-AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum, >+AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, undef, $expdate, $notes, > 'a title', $checkitem, ''); >-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' >@@ -480,17 +472,17 @@ 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'); > > $dbh->do('DELETE FROM reserves', undef, ($bibnum)); >-AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum, >+AddReserve($branch_1, $requesters{$branch_1}, $bibnum, > $bibitems, 1, undef, $expdate, $notes, > 'a title', $checkitem, ''); >-(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'); > >@@ -529,8 +521,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 }; >@@ -551,48 +541,48 @@ t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); > $dbh->do('DELETE FROM reserves', undef, ($bibnum)); > t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0); > t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); >-AddReserve($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, undef, $expdate, $notes, 'a title', $checkitem, ''); >-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($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, undef, $expdate, $notes, 'a title', $checkitem, '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(); > $resdate->add_duration(DateTime::Duration->new(days => 1)); > $resdate=output_pref($resdate); >-AddReserve($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, ''); >-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 > t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2); >-AddReserve($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, ''); >-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($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, 'W'); >-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(); > $resdate->add_duration(DateTime::Duration->new(days => 3)); > $resdate=output_pref($resdate); >-AddReserve($branch_1, $borrowernumber, $item_bibnum, >+AddReserve($branch_1, $borrowernumber, $bibnum, > $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, ''); >-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 a83adba99f..e5fe05bf8f 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); >@@ -219,26 +223,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 387947251f..d312720d9e 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 f4ebe0a2ec..6034d0d8b0 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -176,8 +176,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 } } ); >@@ -187,7 +186,6 @@ sub build_sample_item { > homebranch => $library, > holdingbranch => $library, > barcode => $barcode, >- itype => $itype, > %$args, > }, > $biblionumber >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23463
:
95899
|
95900
|
95901
|
95902
|
95903
|
95904
|
95905
|
95906
|
95907
|
95908
|
95909
|
95910
|
95911
|
95912
|
95913
|
95914
|
95915
|
95916
|
95917
|
95918
|
95919
|
95920
|
95921
|
95922
|
95923
|
95925
|
96145
|
97895
|
97896
|
97897
|
97898
|
97899
|
97900
|
97901
|
97902
|
97903
|
97904
|
97905
|
97906
|
97907
|
97908
|
97909
|
97910
|
97911
|
97912
|
97913
|
97914
|
97915
|
97916
|
97917
|
97918
|
97919
|
97920
|
97921
|
101151
|
101152
|
101153
|
101154
|
101156
|
101157
|
101158
|
101161
|
101163
|
101165
|
101167
|
101169
|
101170
|
101171
|
101172
|
101173
|
101174
|
101175
|
101176
|
101177
|
101178
|
101179
|
101180
|
101181
|
101182
|
101183
|
101184
|
101185
|
101186
|
101188
|
101189
|
101190
|
101191
|
101192
|
101193
|
101194
|
101195
|
101196
|
101197
|
101246
|
101247
|
101248
|
101249
|
101250
|
101251
|
101252
|
101253
|
101254
|
101255
|
101256
|
101257
|
101258
|
101259
|
101260
|
101261
|
101262
|
101263
|
101264
|
101265
|
101266
|
101267
|
101268
|
101269
|
101270
|
101271
|
101272
|
101273
|
101274
|
101275
|
101276
|
101277
|
101278
|
101279
|
101280
|
101281
|
101282
|
101283
|
101284
|
101413
|
101414
|
101415
|
101416
|
101432
|
101476
|
102071
|
103129
|
113581