From 82c036ae5a76f10fd99fa1ee952ce23bb95d67fe Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Wed, 23 Oct 2013 00:38:25 +0200 Subject: [PATCH] Bug 10869 Followup: Unit tests for DelOrder Content-Type: text/plain; charset=utf-8 DelOrder now returns undef if no ordernumber passed. This patch also adds unit tests for DelOrder. Test plan: A. With syspref AcqCreateItem = on placing an order 1. Fill a basket with some orders (some records with already existing items or holds, some without items). New items linked with the order will be created 2. Keep the basket open 3. In the catalog, supress all the items attached to one of the record used in the basket, then suppress the record 4. In the basket, check you can delete the order that was using deleted record (click on link "Delete order" in the right column of the table) 5. After deleting the order, check there is a new line in the "Deleted orders" table 6. Regression test : try to delete other orders, and check the deletion of the order implies the deletion of items created when ordering a/ If no items were attached to the record before you created the basket, you can delete some other orders, AND their record. Try to delete order and record. b/ If some items were attached to the record before you created the basket, you can delete some other orders, BUT NOT their record. Try to delete only order. After you have deleted it, the items created when ordering must have been deleted. 7. Add some other orders to your basket (some records with already existing items or holds, some without items). New items linked with the order will be created 8. In the catalog, supress all the items attached to one of the record used in the basket, then suppress the record 9. Close the basket 10. Go on receipt page 11. Search the orders of your basket 12. In receipt page, check you can delete the order that was using deleted record (click on link "Delete order" in the right column of the table) 13. Regression test : try to delete other orders a/ If no items were attached to the record before you created the basket, you can delete some other orders, AND their record. Try to delete order and record. b/ If some items were attached to the record before you created the basket, you can delete some other orders, BUT NOT their record. Try to delete only order. After you have deleted it, the items created when ordering must have been deleted. B. With syspref AcqCreateItem = on receiving an order 1. Fill a basket with some orders (some records with already existing items or holds, some without items). 2. Keep the basket open 3. In the catalog, supress all the items attached to one of the record used in the basket, then suppress the record 4. In the basket, check you can delete the order that was using deleted record (click on link "Delete order" in the right column of the table) 5. After deleting the order, check there is a new line in the "Deleted orders" table 6. Regression test : try to delete other orders a/ If no items were attached to the record before you created the basket, you can delete some other orders, AND their record. Try to delete order and record. b/ If some items were attached to the record before you created the basket, you can delete some other orders, BUT NOT their record. Try to delete only order. 7. Add some other orders to your basket (some records with already existing items or holds, some without items). 8. In the catalog, supress all the items attached to one of the record used in the basket, then suppress the record 9. Close the basket 10. Go on receipt page 11. Search the orders of your basket 12. In receipt page, check you can delete the order that was using deleted record (click on link "Delete order" in the right column of the table) 13. Regression test : try to delete other orders a/ If no items were attached to the record before you created the basket, you can delete some other orders, AND their record. Try to delete order and record. b/ If some items were attached to the record before you created the basket, you can delete some other orders, BUT NOT their record. Try to delete only order. And to test the UT: prove t/db_dependent/Acquisition.t Signed-off-by: Marcel de Rooy Amended the patch as to removing biblio parameter in DelOrder. There is no need to remove the parameter if you will search for biblionumber later on. Deleting records in aqorders_items is discussed on bug 11617. --- C4/Acquisition.pm | 4 +- t/db_dependent/Acquisition.t | 54 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4cd6e0b..8bf6324 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1285,7 +1285,7 @@ sub NewOrder { =head3 NewOrderItem - &NewOrderItem(); + &NewOrderItem( $itemnumber, $ordernumber ); =cut @@ -1762,6 +1762,7 @@ cancelled. sub DelOrder { my ($ordernumber,$biblionumber) = @_; + return if !$ordernumber; my $dbh = C4::Context->dbh; my $query = " UPDATE aqorders @@ -1770,7 +1771,6 @@ sub DelOrder { "; my $sth = $dbh->prepare($query); $sth->execute($ordernumber ); - $sth->finish; if ($biblionumber) { my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); foreach my $itemnumber (@itemnumbers){ diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 2585802..8ca1c97 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -7,8 +7,10 @@ use Modern::Perl; use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); +use C4::Items qw (AddItem GetItem); +use C4::Branch qw (ModBranch); -use Test::More tests => 62; +use Test::More tests => 66; BEGIN { use_ok('C4::Acquisition'); @@ -223,4 +225,54 @@ is($order3->{'quantityreceived'}, 2, 'Order not split up'); is($order3->{'quantity'}, 2, '2 items on order'); is($order3->{'budget_id'}, $budgetid2, 'Budget has changed'); +# +# test DelOrder +# use: +# &DelOrder($ordernumber,$biblionumber); + +# create 3 items on the same record and link 2 of them to the order + +# Add a branch +my $b1 = { + add => 1, + branchcode => 'BRA', + branchname => 'BranchA', + branchaddress1 => 'adr1A', + branchaddress2 => 'adr2A', + branchaddress3 => 'adr3A', + branchzip => 'zipA', + branchcity => 'cityA', + branchstate => 'stateA', + branchcountry => 'countryA', + branchphone => 'phoneA', + branchfax => 'faxA', + branchemail => 'emailA', + branchurl => 'urlA', + branchip => 'ipA', + branchprinter => undef, + branchnotes => 'noteA', + opac_info => 'opacA' +}; +ModBranch($b1); + +my ($item_bibnum1, $item_bibitemnum1, $itemnumber1) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +my ($item_bibnum3, $item_bibitemnum3, $itemnumber3) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +NewOrderItem ($itemnumber1, $ordernumber3); +NewOrderItem ($itemnumber2, $ordernumber3); + +# If no ordernumber is passed, the function returns undef and does not try to update database +my $return_DelOrder = DelOrder (); +is($return_DelOrder , undef, 'DelOrder returns undef with no param'); +# Cancel the order with the given order, by filling the datecancellationprinted and orderstatus fields. +DelOrder ($ordernumber3,$biblionumber2); +$order3 = GetOrder( $ordernumber3 ); +ok(($order3->{'orderstatus'} eq 'cancelled')&& (defined $order3->{'datecancellationprinted'}),'DelOrders update orderstatus and fill datecancellationprinted fields'); + +# All the items linked with that order are deleted (in items, not in aqorders_items by the way) +ok(!defined GetItem($itemnumber1) && !defined GetItem($itemnumber2), "DelOrder deletes items linked with order in items table"); + +# Other items (created manually) are not deleted. +is(GetItem($itemnumber3)->{biblionumber},$biblionumber2, "DelOrder does not delete item created manually"); + $dbh->rollback; -- 1.7.7.6