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

(-)a/t/db_dependent/HoldsQueue.t (-1 / +60 lines)
Lines 12-18 use C4::Context; Link Here
12
12
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use Test::More tests => 21;
15
use Test::More tests => 22;
16
16
17
17
18
use C4::Branch;
18
use C4::Branch;
Lines 297-302 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
297
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
297
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
298
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
298
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
299
299
300
# Bug 14297
301
$borrowernumber = AddMember(%data);
302
$borrower = GetMember( borrowernumber => $borrowernumber );
303
$borrower_branchcode = $borrower->{branchcode};
304
$itemtype = $item_types[0]->{itemtype};
305
my $library_A = 'CPL';
306
my $library_B = 'FFL';
307
my $library_C = 'MPL'; # Same as our borrower's home library
308
$dbh->do("DELETE FROM reserves");
309
$dbh->do("DELETE FROM issues");
310
$dbh->do("DELETE FROM items");
311
$dbh->do("DELETE FROM biblio");
312
$dbh->do("DELETE FROM biblioitems");
313
$dbh->do("DELETE FROM transport_cost");
314
$dbh->do("DELETE FROM tmp_holdsqueue");
315
$dbh->do("DELETE FROM hold_fill_targets");
316
$dbh->do("DELETE FROM default_branch_circ_rules");
317
$dbh->do("DELETE FROM default_branch_item_rules");
318
$dbh->do("DELETE FROM default_circ_rules");
319
$dbh->do("DELETE FROM branch_item_rules");
320
321
$dbh->do("
322
    INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')
323
");
324
325
$biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$TITLE'")
326
  or BAIL_OUT("Cannot find newly created biblio record");
327
328
$dbh->do("INSERT INTO biblioitems (biblionumber, marcxml, itemtype) VALUES ($biblionumber, '', '$itemtype')");
329
330
$biblioitemnumber =
331
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
332
  or BAIL_OUT("Cannot find newly created biblioitems record");
333
334
$dbh->do("
335
    INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
336
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
337
");
338
339
$dbh->do("
340
    INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
341
    VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
342
");
343
344
$dbh->do("
345
    INSERT INTO branch_item_rules ( branchcode, itemtype, holdallowed, returnbranch ) VALUES
346
    ( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' );
347
");
348
349
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'",
350
    undef, join( ',', $library_B, $library_A, $library_C ) );
351
$dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHoldsQueueWeight'" );
352
353
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
354
C4::HoldsQueue::CreateQueue();
355
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
356
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" );
357
# End Bug 14297
358
300
# Cleanup
359
# Cleanup
301
$dbh->rollback;
360
$dbh->rollback;
302
361
(-)a/t/db_dependent/HoldsQueue_Bug_14297.t (-1 / +113 lines)
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

Return to bug 14297