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

(-)a/t/db_dependent/Circulation.t (-4 / +4 lines)
Lines 3658-3665 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
3658
                branchcode   => undef,
3658
                branchcode   => undef,
3659
                categorycode => undef,
3659
                categorycode => undef,
3660
                itemtype     => undef,
3660
                itemtype     => undef,
3661
                rule_name    => 'refund',
3661
                rule_name    => 'lostreturn',
3662
                rule_value   => 1
3662
                rule_value   => 'refund'
3663
            }
3663
            }
3664
        }
3664
        }
3665
    );
3665
    );
Lines 3851-3858 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
3851
                branchcode   => undef,
3851
                branchcode   => undef,
3852
                categorycode => undef,
3852
                categorycode => undef,
3853
                itemtype     => undef,
3853
                itemtype     => undef,
3854
                rule_name    => 'refund',
3854
                rule_name    => 'lostreturn',
3855
                rule_value   => 1
3855
                rule_value   => 'refund'
3856
            }
3856
            }
3857
        }
3857
        }
3858
    );
3858
    );
(-)a/t/db_dependent/Koha/CirculationRules.t (-22 / +38 lines)
Lines 279-293 subtest 'get_lostreturn_policy() tests' => sub { Link Here
279
279
280
    $schema->resultset('CirculationRule')->search()->delete;
280
    $schema->resultset('CirculationRule')->search()->delete;
281
281
282
    my $default_rule = $builder->build(
282
    my $default_rule_charge = $builder->build(
283
        {
283
        {
284
            source => 'CirculationRule',
284
            source => 'CirculationRule',
285
            value  => {
285
            value  => {
286
                branchcode   => undef,
286
                branchcode   => undef,
287
                categorycode => undef,
287
                categorycode => undef,
288
                itemtype     => undef,
288
                itemtype     => undef,
289
                rule_name    => 'refund',
289
                rule_name    => 'lostreturn',
290
                rule_value   => 1
290
                rule_value   => 'charge'
291
            }
291
            }
292
        }
292
        }
293
    );
293
    );
Lines 299-332 subtest 'get_lostreturn_policy() tests' => sub { Link Here
299
                branchcode   => $branchcode,
299
                branchcode   => $branchcode,
300
                categorycode => undef,
300
                categorycode => undef,
301
                itemtype     => undef,
301
                itemtype     => undef,
302
                rule_name    => 'refund',
302
                rule_name    => 'lostreturn',
303
                rule_value   => 0
303
                rule_value   => 0
304
            }
304
            }
305
        }
305
        }
306
    );
306
    );
307
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
307
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
308
    my $specific_rule_true = $builder->build(
308
    my $specific_rule_refund = $builder->build(
309
        {
309
        {
310
            source => 'CirculationRule',
310
            source => 'CirculationRule',
311
            value  => {
311
            value  => {
312
                branchcode   => $branchcode2,
312
                branchcode   => $branchcode2,
313
                categorycode => undef,
313
                categorycode => undef,
314
                itemtype     => undef,
314
                itemtype     => undef,
315
                rule_name    => 'refund',
315
                rule_name    => 'lostreturn',
316
                rule_value   => 1
316
                rule_value   => 'refund'
317
            }
317
            }
318
        }
318
        }
319
    );
319
    );
320
    # Make sure we have an unused branchcode
321
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
320
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
322
    my $specific_rule_dummy = $builder->build(
321
    my $specific_rule_restore = $builder->build(
323
        {
322
        {
324
            source => 'CirculationRule',
323
            source => 'CirculationRule',
325
            value  => {
324
            value  => {
326
                branchcode   => $branchcode3,
325
                branchcode   => $branchcode3,
327
                categorycode => undef,
326
                categorycode => undef,
328
                itemtype     => undef,
327
                itemtype     => undef,
329
                rule_name    => 'refund',
328
                rule_name    => 'lostreturn',
329
                rule_value   => 'restore'
330
            }
331
        }
332
    );
333
334
    # Make sure we have an unused branchcode
335
    my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode};
336
    my $specific_rule_dummy = $builder->build(
337
        {
338
            source => 'CirculationRule',
339
            value  => {
340
                branchcode   => $branchcode4,
341
                categorycode => undef,
342
                itemtype     => undef,
343
                rule_name    => 'lostreturn',
344
                rule_value   => 'refund'
330
            }
345
            }
331
        }
346
        }
332
    );
347
    );
Lines 337-343 subtest 'get_lostreturn_policy() tests' => sub { Link Here
337
                branchcode   => $branch_without_rule,
352
                branchcode   => $branch_without_rule,
338
                categorycode => undef,
353
                categorycode => undef,
339
                itemtype     => undef,
354
                itemtype     => undef,
340
                rule_name    => 'refund'
355
                rule_name    => 'lostreturn',
356
                rule_value   => 'refund'
341
            }
357
            }
342
          )
358
          )
343
        ->next
359
        ->next
Lines 345-380 subtest 'get_lostreturn_policy() tests' => sub { Link Here
345
361
346
    my $item = $builder->build_sample_item(
362
    my $item = $builder->build_sample_item(
347
        {
363
        {
348
            homebranch    => $specific_rule_false->{branchcode},
364
            homebranch    => $specific_rule_restore->{branchcode},
349
            holdingbranch => $specific_rule_true->{branchcode}
365
            holdingbranch => $specific_rule_false->{branchcode}
350
        }
366
        }
351
    );
367
    );
352
    my $params = {
368
    my $params = {
353
        return_branch => $specific_rule_true->{ branchcode },
369
        return_branch => $specific_rule_refund->{ branchcode },
354
        item          => $item
370
        item          => $item
355
    };
371
    };
356
372
357
    # Specific rules
373
    # Specific rules
358
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
374
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
359
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
375
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
360
          1,'Specific rule for checkin branch is applied (true)');
376
        'refund','Specific rule for checkin branch is applied (refund)');
361
377
362
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
378
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
363
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
379
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
364
         0,'Specific rule for home branch is applied (false)');
380
         'restore','Specific rule for home branch is applied (restore)');
365
381
366
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
382
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
367
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
383
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
368
         1,'Specific rule for holding branch is applied (true)');
384
         0,'Specific rule for holding branch is applied (false)');
369
385
370
    # Default rule check
386
    # Default rule check
371
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
387
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
372
    $params->{return_branch} = $branch_without_rule;
388
    $params->{return_branch} = $branch_without_rule;
373
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
389
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
374
         1,'No rule for branch, global rule applied (true)');
390
         'charge','No rule for branch, global rule applied (charge)');
375
391
376
    # Change the default value just to try
392
    # Change the default value just to try
377
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
393
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store;
378
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
394
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
379
         0,'No rule for branch, global rule applied (false)');
395
         0,'No rule for branch, global rule applied (false)');
380
396
Lines 385-402 subtest 'get_lostreturn_policy() tests' => sub { Link Here
385
                branchcode   => undef,
401
                branchcode   => undef,
386
                categorycode => undef,
402
                categorycode => undef,
387
                itemtype     => undef,
403
                itemtype     => undef,
388
                rule_name    => 'refund'
404
                rule_name    => 'lostreturn'
389
            }
405
            }
390
          )
406
          )
391
        ->next
407
        ->next
392
        ->delete;
408
        ->delete;
393
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
409
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
394
         1,'No rule for branch, no default rule, fallback default (true)');
410
         'refund','No rule for branch, no default rule, fallback default (refund)');
395
411
396
    # Fallback to ItemHoldBranch if CheckinLibrary is undefined
412
    # Fallback to ItemHoldBranch if CheckinLibrary is undefined
397
    $params->{return_branch} = undef;
413
    $params->{return_branch} = undef;
398
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
414
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
399
         0,'return_branch undefined, fallback to ItemHomeBranch rule (false)');
415
         'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)');
400
416
401
    $schema->storage->txn_rollback;
417
    $schema->storage->txn_rollback;
402
};
418
};
(-)a/t/db_dependent/Koha/IssuingRules.t (-7 / +6 lines)
Lines 163-172 subtest 'set_rule' => sub { Link Here
163
        lives_ok( sub {
163
        lives_ok( sub {
164
            Koha::CirculationRules->set_rule( {
164
            Koha::CirculationRules->set_rule( {
165
                branchcode => $branchcode,
165
                branchcode => $branchcode,
166
                rule_name => 'refund',
166
                rule_name => 'lostreturn',
167
                rule_value => '',
167
                rule_value => '',
168
            } );
168
            } );
169
        }, 'setting refund with branch' );
169
        }, 'setting lostreturn with branch' );
170
170
171
        lives_ok( sub {
171
        lives_ok( sub {
172
            Koha::CirculationRules->set_rule( {
172
            Koha::CirculationRules->set_rule( {
Lines 204-213 subtest 'set_rule' => sub { Link Here
204
204
205
        throws_ok( sub {
205
        throws_ok( sub {
206
            Koha::CirculationRules->set_rule( {
206
            Koha::CirculationRules->set_rule( {
207
                rule_name => 'refund',
207
                rule_name => 'lostreturn',
208
                rule_value => '',
208
                rule_value => '',
209
            } );
209
            } );
210
        }, qr/branchcode/, 'setting refund without branch fails' );
210
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
211
211
212
        throws_ok( sub {
212
        throws_ok( sub {
213
            Koha::CirculationRules->set_rule( {
213
            Koha::CirculationRules->set_rule( {
Lines 244-253 subtest 'set_rule' => sub { Link Here
244
            Koha::CirculationRules->set_rule( {
244
            Koha::CirculationRules->set_rule( {
245
                branchcode => $branchcode,
245
                branchcode => $branchcode,
246
                categorycode => $categorycode,
246
                categorycode => $categorycode,
247
                rule_name => 'refund',
247
                rule_name => 'lostreturn',
248
                rule_value => '',
248
                rule_value => '',
249
            } );
249
            } );
250
        }, qr/categorycode/, 'setting refund with categorycode fails' );
250
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
251
251
252
        throws_ok( sub {
252
        throws_ok( sub {
253
            Koha::CirculationRules->set_rule( {
253
            Koha::CirculationRules->set_rule( {
254
- 

Return to bug 23091