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

(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-131 / +158 lines)
Lines 23-90 my $dbh = C4::Context->dbh; Link Here
23
23
24
my $builder = t::lib::TestBuilder->new;
24
my $builder = t::lib::TestBuilder->new;
25
25
26
my $library1 = $builder->build({
26
my $library1 = $builder->build( { source => 'Branch', } );
27
    source => 'Branch',
27
my $library2 = $builder->build( { source => 'Branch', } );
28
});
28
my $itemtype = $builder->build(
29
my $library2 = $builder->build({
29
    {   source => 'Itemtype',
30
    source => 'Branch',
30
        value  => { notforloan => 0 }
31
});
32
my $itemtype = $builder->build({
33
    source => 'Itemtype',
34
    value  => { notforloan => 0 }
35
})->{itemtype};
36
37
t::lib::Mocks::mock_userenv({ branchcode => $library1->{branchcode} });
38
39
40
my $patron1 = $builder->build_object({
41
    class => 'Koha::Patrons',
42
    value => {
43
        branchcode => $library1->{branchcode},
44
        dateexpiry => '3000-01-01',
45
    }
31
    }
46
});
32
)->{itemtype};
33
34
t::lib::Mocks::mock_userenv( { branchcode => $library1->{branchcode} } );
35
36
my $patron1 = $builder->build_object(
37
    {   class => 'Koha::Patrons',
38
        value => {
39
            branchcode => $library1->{branchcode},
40
            dateexpiry => '3000-01-01',
41
        }
42
    }
43
);
47
my $borrower1 = $patron1->unblessed;
44
my $borrower1 = $patron1->unblessed;
48
45
49
my $patron2 = $builder->build_object({
46
my $patron2 = $builder->build_object(
50
    class => 'Koha::Patrons',
47
    {   class => 'Koha::Patrons',
51
    value => {
48
        value => {
52
        branchcode => $library1->{branchcode},
49
            branchcode => $library1->{branchcode},
53
        dateexpiry => '3000-01-01',
50
            dateexpiry => '3000-01-01',
51
        }
54
    }
52
    }
55
});
53
);
56
54
57
my $patron3 = $builder->build_object({
55
my $patron3 = $builder->build_object(
58
    class => 'Koha::Patrons',
56
    {   class => 'Koha::Patrons',
59
    value => {
57
        value => {
60
        branchcode => $library2->{branchcode},
58
            branchcode => $library2->{branchcode},
61
        dateexpiry => '3000-01-01',
59
            dateexpiry => '3000-01-01',
60
        }
62
    }
61
    }
63
});
62
);
64
63
65
my $library_A = $library1->{branchcode};
64
my $library_A = $library1->{branchcode};
66
my $library_B = $library2->{branchcode};
65
my $library_B = $library2->{branchcode};
67
66
68
my $biblio = $builder->build_sample_biblio({itemtype=>$itemtype});
67
my $biblio       = $builder->build_sample_biblio( { itemtype => $itemtype } );
69
my $biblionumber = $biblio->biblionumber;
68
my $biblionumber = $biblio->biblionumber;
70
my $item1  = $builder->build_sample_item({
69
my $item1        = $builder->build_sample_item(
71
    biblionumber=>$biblionumber,
70
    {   biblionumber  => $biblionumber,
72
    itype=>$itemtype,
71
        itype         => $itemtype,
73
    homebranch => $library_A,
72
        homebranch    => $library_A,
74
    holdingbranch => $library_A
73
        holdingbranch => $library_A
75
});
74
    }
76
my $item2  = $builder->build_sample_item({
75
);
77
    biblionumber=>$biblionumber,
76
my $item2 = $builder->build_sample_item(
78
    itype=>$itemtype,
77
    {   biblionumber  => $biblionumber,
79
    homebranch => $library_A,
78
        itype         => $itemtype,
80
    holdingbranch => $library_A
79
        homebranch    => $library_A,
81
});
80
        holdingbranch => $library_A
81
    }
82
);
82
83
83
# Test hold_fulfillment_policy
84
# Test hold_fulfillment_policy
84
$dbh->do("DELETE FROM circulation_rules");
85
$dbh->do("DELETE FROM circulation_rules");
85
Koha::CirculationRules->set_rules(
86
Koha::CirculationRules->set_rules(
86
    {
87
    {   categorycode => undef,
87
        categorycode => undef,
88
        itemtype     => $itemtype,
88
        itemtype     => $itemtype,
89
        branchcode   => undef,
89
        branchcode   => undef,
90
        rules        => {
90
        rules        => {
Lines 98-138 Koha::CirculationRules->set_rules( Link Here
98
98
99
my $is;
99
my $is;
100
100
101
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
101
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
102
is( $is, 1, "Items availability: both of 2 items are available" );
102
is( $is, 1, "Items availability: both of 2 items are available" );
103
103
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
105
is( $is, 0, "Item cannot be held, 2 items available" );
105
is( $is, 0, "Item cannot be held, 2 items available" );
106
106
107
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
107
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
108
108
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
110
is( $is, 1, "Items availability: one item is available" );
110
is( $is, 1, "Items availability: one item is available" );
111
111
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
113
is( $is, 0, "Item cannot be held, 1 item available" );
113
is( $is, 0, "Item cannot be held, 1 item available" );
114
114
115
AddIssue( $patron2->unblessed, $item2->barcode );
115
AddIssue( $patron2->unblessed, $item2->barcode );
116
116
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
118
is( $is, 0, "Items availability: none of items are available" );
118
is( $is, 0, "Items availability: none of items are available" );
119
119
120
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
120
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
121
is( $is, 1, "Item can be held, no items available" );
121
is( $is, 1, "Item can be held, no items available" );
122
122
123
AddReturn( $item1->barcode );
123
AddReturn( $item1->barcode );
124
124
125
{ # Remove the issue for the first patron, and modify the branch for item1
125
{    # Remove the issue for the first patron, and modify the branch for item1
126
    subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub {
126
    subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub {
127
        plan tests => 2;
127
        plan tests => 2;
128
128
129
        my $hold_allowed_from_home_library = 1;
129
        my $hold_allowed_from_home_library  = 1;
130
        my $hold_allowed_from_any_libraries = 2;
130
        my $hold_allowed_from_any_libraries = 2;
131
131
132
        subtest 'Item is available at a different library' => sub {
132
        subtest 'Item is available at a different library' => sub {
133
            plan tests => 13;
133
            plan tests => 13;
134
134
135
            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
135
            $item1->set( { homebranch => $library_B, holdingbranch => $library_B } )->store;
136
136
            #Scenario is:
137
            #Scenario is:
137
            #One shelf holds is 'If all unavailable'/2
138
            #One shelf holds is 'If all unavailable'/2
138
            #Item 1 homebranch library B is available
139
            #Item 1 homebranch library B is available
Lines 140-207 AddReturn( $item1->barcode ); Link Here
140
            #Borrower1 is from library A
141
            #Borrower1 is from library A
141
142
142
            {
143
            {
143
                set_holdallowed_rule( $hold_allowed_from_home_library );
144
                set_holdallowed_rule($hold_allowed_from_home_library);
144
145
145
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
146
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
146
147
147
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
148
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
148
                is( $is, 0, "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
149
                is( $is, 0, "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
149
150
150
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
151
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
151
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
152
                is( $is, 1,
152
                $is = IsAvailableForItemLevelRequest( $item1, $patron2);
153
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
153
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level" );
154
                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
155
                $is = IsAvailableForItemLevelRequest( $item1, $patron2 );
156
                is( $is, 1,
157
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
158
                      . "One item is available at home library, holdable = one available => the hold is not allowed at item level" );
154
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
159
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
160
155
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
161
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
156
162
157
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
163
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
158
                is( $is, 1, "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
164
                is( $is, 1,
165
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
166
167
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
168
                is( $is, 0,
169
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
170
                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
159
171
160
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
172
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
161
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
162
173
163
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
174
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
175
                is( $is, 0,
176
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" );
164
177
165
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
178
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
166
                is( $is, 0, "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" );
179
                is( $is, 1,
180
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
181
                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
167
182
168
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
169
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
170
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
183
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
171
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
184
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
172
185
173
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
186
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
174
                is( $is, 1, "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" );
187
                is( $is, 1,
188
                    "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" );
175
189
176
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
190
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
177
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
191
                is( $is, 0,
192
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
193
                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
178
            }
194
            }
179
195
180
            {
196
            {
181
                set_holdallowed_rule( $hold_allowed_from_any_libraries );
197
                set_holdallowed_rule($hold_allowed_from_any_libraries);
182
198
183
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
199
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
184
200
185
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
201
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
186
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
202
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
187
203
188
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
204
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
189
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
205
                is( $is, 0,
206
                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
207
                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
190
208
191
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
209
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
192
210
193
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
211
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
194
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" );
212
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" );
195
213
196
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
214
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
197
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
215
                is( $is, 0,
216
                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
217
                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
198
            }
218
            }
199
        };
219
        };
200
220
201
        subtest 'Item is available at the same library' => sub {
221
        subtest 'Item is available at the same library' => sub {
202
            plan tests => 8;
222
            plan tests => 8;
203
223
204
            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
224
            $item1->set( { homebranch => $library_A, holdingbranch => $library_A } )->store;
225
205
            #Scenario is:
226
            #Scenario is:
206
            #One shelf holds is 'If all unavailable'/2
227
            #One shelf holds is 'If all unavailable'/2
207
            #Item 1 homebranch library A is available
228
            #Item 1 homebranch library A is available
Lines 211-288 AddReturn( $item1->barcode ); Link Here
211
            #ReservesControlBranch is not checked in these subs we are testing?
232
            #ReservesControlBranch is not checked in these subs we are testing?
212
233
213
            {
234
            {
214
                set_holdallowed_rule( $hold_allowed_from_home_library );
235
                set_holdallowed_rule($hold_allowed_from_home_library);
215
236
216
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
237
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
217
238
218
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
239
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
219
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
240
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
220
241
221
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
242
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
222
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
243
                is( $is, 0,
244
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
245
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
223
246
224
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
247
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
225
248
226
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
249
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
227
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
250
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
228
251
229
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
252
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
230
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
253
                is( $is, 0,
254
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
255
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
231
            }
256
            }
232
257
233
            {
258
            {
234
                set_holdallowed_rule( $hold_allowed_from_any_libraries );
259
                set_holdallowed_rule($hold_allowed_from_any_libraries);
235
260
236
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
261
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
237
262
238
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
263
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
239
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
264
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
240
265
241
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
266
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
242
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
267
                is( $is, 0,
268
                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
269
                      . "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
243
270
244
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
271
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
245
272
246
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
273
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
247
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
274
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
248
275
249
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
276
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
250
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
277
                is( $is, 0,
278
                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
279
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
251
            }
280
            }
252
        };
281
        };
253
    };
282
    };
254
}
283
}
255
284
256
my $itemtype2 = $builder->build({
285
my $itemtype2 = $builder->build(
257
    source => 'Itemtype',
286
    {   source => 'Itemtype',
258
    value  => { notforloan => 0 }
287
        value  => { notforloan => 0 }
259
})->{itemtype};
260
my $item3 = $builder->build_sample_item({ itype => $itemtype2 });
261
262
my $hold = $builder->build({
263
    source => 'Reserve',
264
    value =>{
265
        itemnumber => $item3->itemnumber,
266
        found => 'T'
267
    }
288
    }
268
});
289
)->{itemtype};
290
my $item3 = $builder->build_sample_item( { itype => $itemtype2 } );
291
292
my $hold = $builder->build(
293
    {   source => 'Reserve',
294
        value  => {
295
            itemnumber => $item3->itemnumber,
296
            found      => 'T'
297
        }
298
    }
299
);
269
300
270
Koha::CirculationRules->set_rules(
301
Koha::CirculationRules->set_rules(
271
    {
302
    {   categorycode => undef,
272
        categorycode => undef,
273
        itemtype     => $itemtype2,
303
        itemtype     => $itemtype2,
274
        branchcode   => undef,
304
        branchcode   => undef,
275
        rules        => {
305
        rules        => {
276
            maxissueqty     => 99,
306
            maxissueqty  => 99,
277
            onshelfholds    => 0,
307
            onshelfholds => 0,
278
        }
308
        }
279
    }
309
    }
280
);
310
);
281
311
282
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
312
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
283
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" );
313
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" );
284
314
285
$is = IsAvailableForItemLevelRequest( $item3, $patron1);
315
$is = IsAvailableForItemLevelRequest( $item3, $patron1 );
286
is( $is, 1, "Item can be held, items in transit are not available" );
316
is( $is, 1, "Item can be held, items in transit are not available" );
287
317
288
subtest 'Check holds availability with different item types' => sub {
318
subtest 'Check holds availability with different item types' => sub {
Lines 363-382 subtest 'Check holds availability with different item types' => sub { Link Here
363
    is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
393
    is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
364
};
394
};
365
395
366
367
# Cleanup
396
# Cleanup
368
$schema->storage->txn_rollback;
397
$schema->storage->txn_rollback;
369
398
370
sub set_holdallowed_rule {
399
sub set_holdallowed_rule {
371
    my ( $holdallowed, $branchcode ) = @_;
400
    my ( $holdallowed, $branchcode ) = @_;
372
    Koha::CirculationRules->set_rules(
401
    Koha::CirculationRules->set_rules(
373
        {
402
        {   branchcode => $branchcode || undef,
374
            branchcode   => $branchcode || undef,
403
            itemtype   => undef,
375
            itemtype     => undef,
404
            rules      => {
376
            rules        => {
405
                holdallowed             => $holdallowed,
377
                holdallowed              => $holdallowed,
406
                hold_fulfillment_policy => 'any',
378
                hold_fulfillment_policy  => 'any',
407
                returnbranch            => 'homebranch',
379
                returnbranch             => 'homebranch',
380
            }
408
            }
381
        }
409
        }
382
    );
410
    );
383
- 

Return to bug 24683