Koha/t/db_dependent/Reserves.t
Galen Charlton 7957dd2a06 Bug 10289: (follow-up) don't set cardnumber for test patron
Since the patron barcode is nullable, and since the tests using
the test patron don't care what the barcode is, don't set it.  This
avoids the tests failing if the test database happens to already
have a patron record with the hard-coded barcode that used
to be supplied.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2013-07-08 14:29:32 +00:00

78 lines
2.1 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 4;
use MARC::Record;
use C4::Branch;
use C4::Biblio;
use C4::Items;
use C4::Members;
BEGIN {
use_ok('C4::Reserves');
}
my $dbh = C4::Context->dbh;
# Start transaction
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
# Setup Test------------------------
# Helper biblio.
diag("\nCreating biblio instance for testing.");
my $bib = MARC::Record->new();
my $title = 'Silence in the library';
$bib->append_fields(
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
MARC::Field->new('245', ' ', ' ', a => $title),
);
my ($bibnum, $bibitemnum);
($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
# Helper item for that biblio.
diag("Creating item instance for testing.");
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
# Modify item; setting barcode.
my $testbarcode = '97531';
ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
# Create a borrower
my %data = (
firstname => 'my firstname',
surname => 'my surname',
categorycode => 'S',
branchcode => 'CPL',
);
my $borrowernumber = AddMember(%data);
my $borrower = GetMember( borrowernumber => $borrowernumber );
my $biblionumber = $bibnum;
my $barcode = $testbarcode;
my $constraint = 'a';
my $bibitems = '';
my $priority = '1';
my $resdate = undef;
my $expdate = undef;
my $notes = '';
my $checkitem = undef;
my $found = undef;
my @branches = GetBranchesLoop();
my $branch = $branches[0][0]{value};
AddReserve($branch, $borrowernumber, $biblionumber,
$constraint, $bibitems, $priority, $resdate, $expdate, $notes,
$title, $checkitem, $found);
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
is($status, "Reserved", "CheckReserves Test 1");
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
is($status, "Reserved", "CheckReserves Test 2");
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
is($status, "Reserved", "CheckReserves Test 3");