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

(-)a/t/db_dependent/Holds_12086.t (-23 / +22 lines)
Lines 13-23 use C4::Items; Link Here
13
use C4::Members;
13
use C4::Members;
14
use C4::Reserves;
14
use C4::Reserves;
15
15
16
BEGIN {
17
    use FindBin;
18
    use lib $FindBin::Bin;
19
}
20
21
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
22
17
23
# Start transaction
18
# Start transaction
Lines 28-33 $dbh->do("DELETE FROM reserves"); Link Here
28
$dbh->do("DELETE FROM old_reserves");
23
$dbh->do("DELETE FROM old_reserves");
29
24
30
*C4::Context::userenv = \&Mock_userenv;
25
*C4::Context::userenv = \&Mock_userenv;
26
31
sub Mock_userenv {
27
sub Mock_userenv {
32
    my $userenv = { flags => 1, id => '1', branch => 'CPL' };
28
    my $userenv = { flags => 1, id => '1', branch => 'CPL' };
33
    return $userenv;
29
    return $userenv;
Lines 38-58 my $borrowers_count = 3; Link Here
38
# Setup Test------------------------
34
# Setup Test------------------------
39
# Helper biblio.
35
# Helper biblio.
40
diag("Creating biblio instance for testing.");
36
diag("Creating biblio instance for testing.");
41
my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
37
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
42
38
43
# Helper item for that biblio.
39
# Helper item for that biblio.
44
diag("Creating item instance for testing.");
40
diag("Creating item instance for testing.");
45
my $item_barcode = '99999999999999999999';
41
my $item_barcode = 'my_barcode';
46
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $item_barcode } , $bibnum);
42
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
43
    { homebranch => 'CPL', holdingbranch => 'CPL', barcode => $item_barcode },
44
    $bibnum );
47
45
48
# Create some borrowers
46
# Create some borrowers
49
my @borrowernumbers;
47
my @borrowernumbers;
50
foreach (1..$borrowers_count) {
48
foreach my $i ( 1 .. $borrowers_count ) {
51
    my $borrowernumber = AddMember(
49
    my $borrowernumber = AddMember(
52
        firstname =>  'my firstname',
50
        firstname    => 'my firstname',
53
        surname => 'my surname ' . $_,
51
        surname      => 'my surname ' . $i,
54
        categorycode => 'S',
52
        categorycode => 'S',
55
        branchcode => 'CPL',
53
        branchcode   => 'CPL',
56
    );
54
    );
57
    push @borrowernumbers, $borrowernumber;
55
    push @borrowernumbers, $borrowernumber;
58
}
56
}
Lines 60-75 foreach (1..$borrowers_count) { Link Here
60
my $biblionumber = $bibnum;
58
my $biblionumber = $bibnum;
61
59
62
my @branches = GetBranchesLoop();
60
my @branches = GetBranchesLoop();
63
my $branch = $branches[0][0]{value};
61
my $branch   = $branches[0][0]{value};
64
62
65
# Create five item level holds
63
# Create five item level holds
66
foreach my $borrowernumber ( @borrowernumbers ) {
64
foreach my $borrowernumber (@borrowernumbers) {
67
    AddReserve(
65
    AddReserve(
68
        $branch,
66
        $branch,
69
        $borrowernumber,
67
        $borrowernumber,
70
        $biblionumber,
68
        $biblionumber,
71
        my $constraint = 'a',
69
        my $constraint = 'a',
72
        my $bibitems = q{},
70
        my $bibitems   = q{},
73
        my $priority,
71
        my $priority,
74
        my $resdate,
72
        my $resdate,
75
        my $expdate,
73
        my $expdate,
Lines 81-100 foreach my $borrowernumber ( @borrowernumbers ) { Link Here
81
}
79
}
82
80
83
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
81
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
84
C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ), $item_barcode, my $datedue, my $cancelreserve = 'revert' );
82
C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ),
83
    $item_barcode, my $datedue, my $cancelreserve = 'revert' );
85
84
86
my $priorities = $dbh->selectall_arrayref("SELECT priority FROM reserves ORDER BY priority ASC");
85
my $priorities = $dbh->selectall_arrayref(
87
ok( scalar @$priorities == 2, 'Only 2 holds remain in the reserves table' );
86
    "SELECT priority FROM reserves ORDER BY priority ASC");
87
ok( scalar @$priorities == 2,   'Only 2 holds remain in the reserves table' );
88
ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
88
ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
89
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
89
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
90
90
91
# Helper method to set up a Biblio.
91
# Helper method to set up a Biblio.
92
sub create_helper_biblio {
92
sub create_helper_biblio {
93
    my $bib = MARC::Record->new();
93
    my $bib   = MARC::Record->new();
94
    my $title = 'Silence in the library';
94
    my $title = 'Silence in the library';
95
    $bib->append_fields(
95
    $bib->append_fields(
96
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
96
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
97
        MARC::Field->new('245', ' ', ' ', a => $title),
97
        MARC::Field->new( '245', ' ', ' ', a => $title ),
98
    );
98
    );
99
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
99
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
100
}
100
}
101
- 

Return to bug 12086