From dbb8dd0beaa19c0612cf56efedc020084ebf925e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 May 2013 16:18:59 +0200 Subject: [PATCH] Bug 10336: HoldsQueue.t needs to create its own data After applying this patch and the patch submitted in bug 10495, you can run prove t/db_dependent/HoldsQueue.t and admire that all tests pass. This patch creates a borrower and uses Koha routines instead of directly request the database. --- t/db_dependent/HoldsQueue.t | 45 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 7fb459a..0e4b981 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -6,14 +6,18 @@ # MySQL WARNING: This makes sense only if your tables are InnoDB, otherwise # transactions are not supported and mess is left behind -use strict; -use warnings; +use Modern::Perl; + use C4::Context; use Data::Dumper; use Test::More tests => 18; +use C4::Branch; +use C4::ItemType; +use C4::Members; + BEGIN { use FindBin; use lib $FindBin::Bin; @@ -21,28 +25,33 @@ BEGIN { use_ok('C4::HoldsQueue'); } -my $TITLE = "Test Holds Queue XXX"; -# Pick a plausible borrower. Easier than creating one. -my $BORROWER_QRY = <dbh; -my $borrower = $dbh->selectrow_hashref($BORROWER_QRY); -my $borrowernumber = $borrower->{borrowernumber}; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +my $TITLE = "Test Holds Queue XXX"; + +my %data = ( + cardnumber => 'CARDNUMBER42', + firstname => 'my firstname', + surname => 'my surname', + categorycode => 'S', + branchcode => 'CPL', +); + +my $borrowernumber = AddMember(%data); +my $borrower = GetMember( borrowernumber => $borrowernumber ); # Set special (for this test) branches my $borrower_branchcode = $borrower->{branchcode}; -my @other_branches = grep { $_ ne $borrower_branchcode } @{ $dbh->selectcol_arrayref("SELECT branchcode FROM branches") }; +my $branches = C4::Branch::GetBranches; +my @other_branches = grep { $_ ne $borrower_branchcode } keys %$branches; my $least_cost_branch_code = pop @other_branches or BAIL_OUT("No point testing only one branch..."); -my $itemtype = $dbh->selectrow_array("SELECT min(itemtype) FROM itemtypes WHERE notforloan = 0") +my @item_types = C4::ItemType->all; +my $itemtype = grep { $_->{notforloan} == 1 } @item_types or BAIL_OUT("No adequate itemtype"); -# Start transaction -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - #Set up the stage # Sysprefs and cost matrix $dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef, @@ -144,8 +153,6 @@ ok( $queue_item # Cleanup $dbh->rollback; -exit; - sub test_queue { my ($test_name, $use_cost_matrix, $pick_branch, $hold_branch) = @_; -- 1.7.10.4