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

(-)a/t/db_dependent/Circulation/Branch.t (-6 lines)
Lines 176-187 Koha::CirculationRules->set_rules( Link Here
176
    }
176
    }
177
);
177
);
178
178
179
$query = q|
180
    INSERT INTO default_circ_rules
181
    (singleton, holdallowed, returnbranch)
182
    VALUES( ?, ?, ? )
183
|;
184
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
185
Koha::CirculationRules->set_rules(
179
Koha::CirculationRules->set_rules(
186
    {
180
    {
187
        branchcode   => undef,
181
        branchcode   => undef,
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-4 lines)
Lines 37-47 $schema->storage->txn_begin; Link Here
37
37
38
our $dbh = C4::Context->dbh;
38
our $dbh = C4::Context->dbh;
39
39
40
$dbh->do(q|DELETE FROM branch_item_rules|);
41
$dbh->do(q|DELETE FROM issues|);
40
$dbh->do(q|DELETE FROM issues|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
45
$dbh->do(q|DELETE FROM issuingrules|);
41
$dbh->do(q|DELETE FROM issuingrules|);
46
42
47
my $builder = t::lib::TestBuilder->new();
43
my $builder = t::lib::TestBuilder->new();
(-)a/t/db_dependent/Circulation/TooMany.t (-4 lines)
Lines 43-52 $dbh->do(q|DELETE FROM branches|); Link Here
43
$dbh->do(q|DELETE FROM categories|);
43
$dbh->do(q|DELETE FROM categories|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
46
$dbh->do(q|DELETE FROM branch_item_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
46
$dbh->do(q|DELETE FROM issuingrules|);
51
Koha::CirculationRules->search()->delete();
47
Koha::CirculationRules->search()->delete();
52
48
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-14 / +22 lines)
Lines 114-122 AddReturn( $item1->barcode ); Link Here
114
114
115
        my $hold_allowed_from_home_library = 1;
115
        my $hold_allowed_from_home_library = 1;
116
        my $hold_allowed_from_any_libraries = 2;
116
        my $hold_allowed_from_any_libraries = 2;
117
        my $sth_delete_rules = $dbh->prepare(q|DELETE FROM default_circ_rules|);
118
        my $sth_insert_rule = $dbh->prepare(q|INSERT INTO default_circ_rules(singleton, holdallowed, hold_fulfillment_policy, returnbranch) VALUES ('singleton', ?, 'any', 'homebranch');|);
119
        my $sth_insert_branch_rule = $dbh->prepare(q|INSERT INTO default_branch_circ_rules(branchcode, holdallowed, hold_fulfillment_policy, returnbranch) VALUES (?, ?, 'any', 'homebranch');|);
120
117
121
        subtest 'Item is available at a different library' => sub {
118
        subtest 'Item is available at a different library' => sub {
122
            plan tests => 7;
119
            plan tests => 7;
Lines 129-143 AddReturn( $item1->barcode ); Link Here
129
            #Borrower1 is from library A
126
            #Borrower1 is from library A
130
127
131
            {
128
            {
132
                $sth_delete_rules->execute;
129
                set_holdallowed_rule( $hold_allowed_from_home_library );
133
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
134
130
135
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
131
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
136
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
132
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
137
                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" );
133
                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" );
138
                $is = IsAvailableForItemLevelRequest( $item1, $patron2);
134
                $is = IsAvailableForItemLevelRequest( $item1, $patron2);
139
                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" );
135
                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" );
140
                $sth_insert_branch_rule->execute( $library_B, $hold_allowed_from_any_libraries );
136
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
141
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
137
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
142
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
138
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
143
                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" );
139
                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" );
Lines 146-159 AddReturn( $item1->barcode ); Link Here
146
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
142
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
147
                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" );
143
                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" );
148
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
144
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
149
                $sth_insert_branch_rule->execute( $library_A, $hold_allowed_from_any_libraries );
145
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
150
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
146
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
151
                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" );
147
                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" );
152
            }
148
            }
153
149
154
            {
150
            {
155
                $sth_delete_rules->execute;
151
                set_holdallowed_rule( $hold_allowed_from_any_libraries );
156
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
157
152
158
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
153
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
159
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
154
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
Lines 178-185 AddReturn( $item1->barcode ); Link Here
178
            #ReservesControlBranch is not checked in these subs we are testing?
173
            #ReservesControlBranch is not checked in these subs we are testing?
179
174
180
            {
175
            {
181
                $sth_delete_rules->execute;
176
                set_holdallowed_rule( $hold_allowed_from_home_library );
182
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
183
177
184
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
178
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
185
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
179
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
Lines 191-198 AddReturn( $item1->barcode ); Link Here
191
            }
185
            }
192
186
193
            {
187
            {
194
                $sth_delete_rules->execute;
188
                set_holdallowed_rule( $hold_allowed_from_any_libraries );
195
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
196
189
197
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
190
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
198
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
191
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
Lines 238-240 is( $is, 1, "Item can be held, items in transit are not available" ); Link Here
238
231
239
# Cleanup
232
# Cleanup
240
$schema->storage->txn_rollback;
233
$schema->storage->txn_rollback;
241
- 
234
235
sub set_holdallowed_rule {
236
    my ( $holdallowed, $branchcode ) = @_;
237
    Koha::CirculationRules->set_rules(
238
        {
239
            branchcode   => $branchcode || undef,
240
            categorycode => undef,
241
            itemtype     => undef,
242
            rules        => {
243
                holdallowed              => $holdallowed,
244
                hold_fulfillment_policy  => 'any',
245
                returnbranch             => 'homebranch',
246
            }
247
        }
248
    );
249
}

Return to bug 18928