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