View | Details | Raw Unified | Return to bug 8728
Collapse All | Expand All

(-)a/t/db_dependent/Reserves.t (-17 / +43 lines)
Lines 5-10 use warnings; Link Here
5
use C4::Branch;
5
use C4::Branch;
6
6
7
use Test::More tests => 4;
7
use Test::More tests => 4;
8
use MARC::Record;
9
use C4::Biblio;
10
use C4::Items;
8
11
9
BEGIN {
12
BEGIN {
10
	use FindBin;
13
	use FindBin;
Lines 12-17 BEGIN { Link Here
12
	use_ok('C4::Reserves');
15
	use_ok('C4::Reserves');
13
}
16
}
14
17
18
# Setup Test------------------------
19
# Helper biblio.
20
diag("\nCreating biblio instance for testing.");
21
my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
22
23
# Helper item for that biblio.
24
diag("Creating item instance for testing.");
25
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
26
27
# Modify item; setting barcode.
28
my $testbarcode = '97531';
29
ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
30
31
# Get a borrower
15
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
16
my $query = qq/SELECT borrowernumber
33
my $query = qq/SELECT borrowernumber
17
    FROM   borrowers
34
    FROM   borrowers
Lines 20-46 my $sth = $dbh->prepare($query); Link Here
20
$sth->execute;
37
$sth->execute;
21
my $borrower = $sth->fetchrow_hashref;
38
my $borrower = $sth->fetchrow_hashref;
22
39
23
$query = qq/SELECT biblionumber, title, itemnumber, barcode
24
    FROM biblio
25
    LEFT JOIN items USING (biblionumber)
26
    WHERE barcode <> ""
27
    AND barcode IS NOT NULL
28
    LIMIT  1/;
29
$sth = $dbh->prepare($query);
30
$sth->execute;
31
my $biblio = $sth->fetchrow_hashref;
32
33
34
my $borrowernumber = $borrower->{'borrowernumber'};
40
my $borrowernumber = $borrower->{'borrowernumber'};
35
my $biblionumber   = $biblio->{'biblionumber'};
41
my $biblionumber   = $bibnum;
36
my $itemnumber     = $biblio->{'itemnumber'};
42
my $barcode        = $testbarcode;
37
my $barcode        = $biblio->{'barcode'};
38
43
39
my $constraint     = 'a';
44
my $constraint     = 'a';
40
my $bibitems       = '';
45
my $bibitems       = '';
41
my $priority       = '1';
46
my $priority       = '1';
47
my $resdate        = undef;
48
my $expdate        = undef;
42
my $notes          = '';
49
my $notes          = '';
43
my $title          = $biblio->{'title'};
44
my $checkitem      = undef;
50
my $checkitem      = undef;
45
my $found          = undef;
51
my $found          = undef;
46
52
Lines 48-54 my @branches = GetBranchesLoop(); Link Here
48
my $branch = $branches[0][0]{value};
54
my $branch = $branches[0][0]{value};
49
55
50
AddReserve($branch,    $borrowernumber, $biblionumber,
56
AddReserve($branch,    $borrowernumber, $biblionumber,
51
        $constraint, $bibitems,  $priority,       $notes,
57
        $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
52
        $title,      $checkitem, $found);
58
        $title,      $checkitem, $found);
53
        
59
        
54
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
60
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
Lines 60-62 ok($status eq "Reserved", "CheckReserves Test 2"); Link Here
60
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
66
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
61
ok($status eq "Reserved", "CheckReserves Test 3");
67
ok($status eq "Reserved", "CheckReserves Test 3");
62
68
63
- 
69
70
# Teardown Test---------------------
71
# Delete item.
72
diag("Deleting item testing instance.");
73
DelItem($dbh, $bibnum, $itemnumber);
74
75
# Delete helper Biblio.
76
diag("Deleting biblio testing instance.");
77
DelBiblio($bibnum);
78
79
# Helper method to set up a Biblio.
80
sub create_helper_biblio {
81
    my $bib = MARC::Record->new();
82
    my $title = 'Silence in the library';
83
    $bib->append_fields(
84
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
85
        MARC::Field->new('245', ' ', ' ', a => $title),
86
    );
87
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
88
}
89

Return to bug 8728