Bugzilla – Attachment 29748 Details for
Bug 12583
DelItem takes $dbh in parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12583: DelItem prototype - Add unit tests
Bug-12583-DelItem-prototype---Add-unit-tests.patch (text/plain), 4.06 KB, created by
Jonathan Druart
on 2014-07-16 12:09:11 UTC
(
hide
)
Description:
Bug 12583: DelItem prototype - Add unit tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-07-16 12:09:11 UTC
Size:
4.06 KB
patch
obsolete
>From 4693f38edc4937ce2e02bc906115e9e313ccaf82 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 16 Jul 2014 14:07:33 +0200 >Subject: [PATCH] Bug 12583: DelItem prototype - Add unit tests > >DelItem should return 1 if the item has been deleted, otherwise 0. > >Test plan: >Verify that t/db_dependent/Items/DelItem.t returns green >--- > C4/Items.pm | 14 +++++++++--- > t/db_dependent/Items/DelItem.t | 49 ++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 60 insertions(+), 3 deletions(-) > create mode 100644 t/db_dependent/Items/DelItem.t > >diff --git a/C4/Items.pm b/C4/Items.pm >index 4aaa078..fe05814 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -648,8 +648,11 @@ sub DelItem { > $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); > } > >+ # If there is no biblionumber for the given itemnumber, there is nothing to delete >+ return 0 unless $biblionumber; >+ > # FIXME check the item has no current issues >- _koha_delete_item( $itemnumber ); >+ my $deleted = _koha_delete_item( $itemnumber ); > > # get the MARC record > my $record = GetMarcBiblio($biblionumber); >@@ -657,6 +660,7 @@ sub DelItem { > > #search item field code > logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); >+ return $deleted; > } > > =head2 CheckItemPreSave >@@ -2355,6 +2359,10 @@ sub _koha_delete_item { > my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?"); > $sth->execute($itemnum); > my $data = $sth->fetchrow_hashref(); >+ >+ # There is no item to delete >+ return 0 unless $data; >+ > my $query = "INSERT INTO deleteditems SET "; > my @bind = (); > foreach my $key ( keys %$data ) { >@@ -2368,8 +2376,8 @@ sub _koha_delete_item { > > # delete from items table > $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?"); >- $sth->execute($itemnum); >- return; >+ my $deleted = $sth->execute($itemnum); >+ return ( $deleted == 1 ) ? 1 : 0; > } > > =head2 _marc_from_item_hash >diff --git a/t/db_dependent/Items/DelItem.t b/t/db_dependent/Items/DelItem.t >new file mode 100644 >index 0000000..35ff6e4 >--- /dev/null >+++ b/t/db_dependent/Items/DelItem.t >@@ -0,0 +1,49 @@ >+use Modern::Perl; >+ >+use MARC::Record; >+use C4::Biblio; >+ >+use Test::More tests => 7; >+ >+BEGIN { >+ use_ok('C4::Items'); >+} >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my ( $biblionumber, $bibitemnum ) = get_biblio(); >+ >+my ( $item_bibnum, $item_bibitemnum, $itemnumber ); >+( $item_bibnum, $item_bibitemnum, $itemnumber ) = >+ AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber ); >+ >+my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); >+is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); >+my $deleted_item = GetItem($itemnumber); >+is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." ); >+ >+( $item_bibnum, $item_bibitemnum, $itemnumber ) = >+ AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber ); >+$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); >+is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); >+$deleted_item = GetItem($itemnumber); >+is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." ); >+ >+$deleted = DelItem( { itemnumber => $itemnumber + 1} ); >+is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" ); >+ >+$deleted = DelItem( { itemnumber => $itemnumber + 1, biblionumber => $biblionumber } ); >+is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" ); >+ >+# Helper method to set up a Biblio. >+sub get_biblio { >+ my $bib = MARC::Record->new(); >+ $bib->append_fields( >+ MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ), >+ MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library' ), >+ ); >+ my ( $bibnum, $bibitemnum ) = AddBiblio( $bib, '' ); >+ return ( $bibnum, $bibitemnum ); >+} >-- >2.0.0.rc2
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 12583
:
29746
|
29747
|
29748
|
30053
|
30054
|
30055
|
30110
|
30111
|
30112