Lines 6-11
use C4::Context;
Link Here
|
6 |
use C4::Items; |
6 |
use C4::Items; |
7 |
use C4::Circulation; |
7 |
use C4::Circulation; |
8 |
use Koha::IssuingRule; |
8 |
use Koha::IssuingRule; |
|
|
9 |
use Koha::Items; |
9 |
|
10 |
|
10 |
use Test::More tests => 4; |
11 |
use Test::More tests => 4; |
11 |
|
12 |
|
Lines 31-46
C4::Context->set_userenv(0,0,0,'firstname','surname', $library1->{branchcode}, '
Link Here
|
31 |
|
32 |
|
32 |
my $bib_title = "Test Title"; |
33 |
my $bib_title = "Test Title"; |
33 |
|
34 |
|
34 |
my $borrower1 = $builder->build({ |
35 |
my $patron1 = $builder->build_object({ |
35 |
source => 'Borrower', |
36 |
class => 'Koha::Patrons', |
36 |
value => { |
37 |
value => { |
37 |
branchcode => $library1->{branchcode}, |
38 |
branchcode => $library1->{branchcode}, |
38 |
dateexpiry => '3000-01-01', |
39 |
dateexpiry => '3000-01-01', |
39 |
} |
40 |
} |
40 |
}); |
41 |
}); |
41 |
|
42 |
|
42 |
my $borrower2 = $builder->build({ |
43 |
my $patron2 = $builder->build_object({ |
43 |
source => 'Borrower', |
44 |
class => 'Koha::Patrons', |
44 |
value => { |
45 |
value => { |
45 |
branchcode => $library1->{branchcode}, |
46 |
branchcode => $library1->{branchcode}, |
46 |
dateexpiry => '3000-01-01', |
47 |
dateexpiry => '3000-01-01', |
Lines 49-56
my $borrower2 = $builder->build({
Link Here
|
49 |
|
50 |
|
50 |
# Test hold_fulfillment_policy |
51 |
# Test hold_fulfillment_policy |
51 |
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") }; |
52 |
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") }; |
52 |
my $borrowernumber1 = $borrower1->{borrowernumber}; |
|
|
53 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
54 |
my $library_A = $library1->{branchcode}; |
53 |
my $library_A = $library1->{branchcode}; |
55 |
|
54 |
|
56 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')"); |
55 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')"); |
Lines 64-90
my $biblioitemnumber =
Link Here
|
64 |
$dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber") |
63 |
$dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber") |
65 |
or BAIL_OUT("Cannot find newly created biblioitems record"); |
64 |
or BAIL_OUT("Cannot find newly created biblioitems record"); |
66 |
|
65 |
|
67 |
$dbh->do(" |
66 |
my $item1 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf1', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } }); |
68 |
INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype) |
|
|
69 |
VALUES ('AllowHoldIf1', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype') |
70 |
"); |
71 |
|
67 |
|
72 |
my $itemnumber1 = |
68 |
my $item2 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf2', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } }); |
73 |
$dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber") |
|
|
74 |
or BAIL_OUT("Cannot find newly created item"); |
75 |
|
76 |
my $item1 = GetItem( $itemnumber1 ); |
77 |
|
78 |
$dbh->do(" |
79 |
INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype) |
80 |
VALUES ('AllowHoldIf2', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype') |
81 |
"); |
82 |
|
83 |
my $itemnumber2 = |
84 |
$dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC") |
85 |
or BAIL_OUT("Cannot find newly created item"); |
86 |
|
87 |
my $item2 = GetItem( $itemnumber2 ); |
88 |
|
69 |
|
89 |
$dbh->do("DELETE FROM issuingrules"); |
70 |
$dbh->do("DELETE FROM issuingrules"); |
90 |
my $rule = Koha::IssuingRule->new( |
71 |
my $rule = Koha::IssuingRule->new( |
Lines 101-117
my $rule = Koha::IssuingRule->new(
Link Here
|
101 |
); |
82 |
); |
102 |
$rule->store(); |
83 |
$rule->store(); |
103 |
|
84 |
|
104 |
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
85 |
my $is = IsAvailableForItemLevelRequest( $item1, $patron1); |
105 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
86 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
106 |
|
87 |
|
107 |
AddIssue( $borrower2, $item1->{barcode} ); |
88 |
AddIssue( $patron2, $item1->barcode ); |
108 |
|
89 |
|
109 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
90 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
110 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
91 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
111 |
|
92 |
|
112 |
AddIssue( $borrower2, $item2->{barcode} ); |
93 |
AddIssue( $patron2, $item2->barcode ); |
113 |
|
94 |
|
114 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
95 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
115 |
is( $is, 1, "Item can be held, no items available" ); |
96 |
is( $is, 1, "Item can be held, no items available" ); |
116 |
|
97 |
|
117 |
# Cleanup |
98 |
# Cleanup |