From 3a5a16d2702646afd569ed0748b5f9c7ebaafc48 Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Wed, 23 Oct 2013 00:38:25 +0200 Subject: [PATCH 2/2] Bug 10869 Followup: Unit tests for DelOrder [The best would be to add a second sign-off to this patch, as I had to to a little change, to take into account the recent rewrite of t/db_dependent/Acquisition.t: $ordernumber3 is now $ordernumbers[2] Mathieu Saby] 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 | 3 ++- t/db_dependent/Acquisition.t | 55 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 98e1abd..ddfbe90 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1299,7 +1299,7 @@ sub NewOrder { =head3 NewOrderItem - &NewOrderItem(); + &NewOrderItem( $itemnumber, $ordernumber ); =cut @@ -1833,6 +1833,7 @@ cancelled. sub DelOrder { my ($ordernumber,$biblionumber) = @_; + return if !$ordernumber; my $dbh = C4::Context->dbh; my $query = " UPDATE aqorders diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 1bd9a13..1a58985 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 => 76; +use Test::More tests => 80; BEGIN { use_ok('C4::Acquisition'); @@ -911,4 +913,55 @@ is( $nonexistent_order, undef, 'GetOrder returns undef if no ordernumber is give $nonexistent_order = GetOrder( 424242424242 ); is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' ); +# +# test DelOrder +# use: +# &DelOrder($ordernumber,$biblionumber); + +# create 3 items on the same record and link 2 of them to the order +# we use the order $ordernumbers[2], which has the status 'complete' and no cancellation date before we try to delete it + +# 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, $ordernumbers[2]); +NewOrderItem ($itemnumber2, $ordernumbers[2]); + +# 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 ($ordernumbers[2],$biblionumber2); +$order3 = GetOrder( $ordernumbers[2] ); +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.9.5