Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Test C4::HoldsQueue::CreateQueue() for both transport cost matrix |
4 |
# and StaticHoldsQueueWeight array (no RandomizeHoldsQueueWeight, no point) |
5 |
# Wraps tests in transaction that's rolled back, so no data is destroyed |
6 |
# MySQL WARNING: This makes sense only if your tables are InnoDB, otherwise |
7 |
# transactions are not supported and mess is left behind |
8 |
|
9 |
use Modern::Perl; |
10 |
|
11 |
use C4::Context; |
12 |
|
13 |
use Data::Dumper; |
14 |
|
15 |
use Test::More tests => 3; |
16 |
|
17 |
use C4::Branch; |
18 |
use C4::ItemType; |
19 |
use C4::Members; |
20 |
|
21 |
BEGIN { |
22 |
use FindBin; |
23 |
use lib $FindBin::Bin; |
24 |
use_ok('C4::Reserves'); |
25 |
use_ok('C4::HoldsQueue'); |
26 |
} |
27 |
|
28 |
# Start transaction |
29 |
my $dbh = C4::Context->dbh; |
30 |
$dbh->{AutoCommit} = 0; |
31 |
$dbh->{RaiseError} = 1; |
32 |
|
33 |
my $TITLE = "Test Holds Queue XXX"; |
34 |
|
35 |
my %data = ( |
36 |
cardnumber => 'CARDNUMBER42', |
37 |
firstname => 'my firstname', |
38 |
surname => 'my surname', |
39 |
categorycode => 'S', |
40 |
branchcode => 'MPL', |
41 |
); |
42 |
|
43 |
my $borrowernumber = AddMember(%data); |
44 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
45 |
# Set special (for this test) branches |
46 |
my $borrower_branchcode = $borrower->{branchcode}; |
47 |
my $branches = C4::Branch::GetBranches; |
48 |
my @other_branches = grep { $_ ne $borrower_branchcode } keys %$branches; |
49 |
my $least_cost_branch_code = pop @other_branches |
50 |
or BAIL_OUT("No point testing only one branch..."); |
51 |
my @item_types = C4::ItemType->all; |
52 |
my $itemtype = grep { $_->{notforloan} == 1 } @item_types |
53 |
or BAIL_OUT("No adequate itemtype"); |
54 |
|
55 |
# Bug 14297 |
56 |
$itemtype = $item_types[0]->{itemtype}; |
57 |
my $library_A = 'CPL'; |
58 |
my $library_B = 'FFL'; |
59 |
my $library_C = 'MPL'; # Same as our borrower's home library |
60 |
$dbh->do("DELETE FROM reserves"); |
61 |
$dbh->do("DELETE FROM issues"); |
62 |
$dbh->do("DELETE FROM items"); |
63 |
$dbh->do("DELETE FROM biblio"); |
64 |
$dbh->do("DELETE FROM biblioitems"); |
65 |
$dbh->do("DELETE FROM transport_cost"); |
66 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
67 |
$dbh->do("DELETE FROM hold_fill_targets"); |
68 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
69 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
70 |
$dbh->do("DELETE FROM default_circ_rules"); |
71 |
$dbh->do("DELETE FROM branch_item_rules"); |
72 |
|
73 |
$dbh->do(" |
74 |
INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01') |
75 |
"); |
76 |
|
77 |
my $biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$TITLE'") |
78 |
or BAIL_OUT("Cannot find newly created biblio record"); |
79 |
|
80 |
$dbh->do("INSERT INTO biblioitems (biblionumber, marcxml, itemtype) VALUES ($biblionumber, '', '$itemtype')"); |
81 |
|
82 |
my $biblioitemnumber = |
83 |
$dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber") |
84 |
or BAIL_OUT("Cannot find newly created biblioitems record"); |
85 |
|
86 |
$dbh->do(" |
87 |
INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype) |
88 |
VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype') |
89 |
"); |
90 |
|
91 |
$dbh->do(" |
92 |
INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype) |
93 |
VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype') |
94 |
"); |
95 |
|
96 |
$dbh->do(" |
97 |
INSERT INTO branch_item_rules ( branchcode, itemtype, holdallowed, returnbranch ) VALUES |
98 |
( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' ); |
99 |
"); |
100 |
|
101 |
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", |
102 |
undef, join( ',', $library_B, $library_A, $library_C ) ); |
103 |
$dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHoldsQueueWeight'" ); |
104 |
|
105 |
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 ); |
106 |
C4::HoldsQueue::CreateQueue(); |
107 |
my $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
108 |
is( @$holds_queue, 1, "Bug 14297 - Holds Queue building ignoring holds where pickup & home branch don't match and item is not from least cost branch" ); |
109 |
# End Bug 14297 |
110 |
|
111 |
# Cleanup |
112 |
$dbh->rollback; |
113 |
|