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

(-)a/t/db_dependent/Koha/CirculationRules.t (-2 / +126 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use Koha::CirculationRules;
25
use Koha::CirculationRules;
26
use Koha::Database;
26
use Koha::Database;
27
27
28
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
29
30
30
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
Lines 282-284 subtest 'get_onshelfholds_policy() tests' => sub { Link Here
282
283
283
    $schema->storage->txn_rollback;
284
    $schema->storage->txn_rollback;
284
};
285
};
285
- 
286
287
subtest 'get_lostreturn_policy() tests' => sub {
288
    plan tests => 6;
289
290
    $schema->storage->txn_begin;
291
292
    $schema->resultset('CirculationRule')->search()->delete;
293
294
    my $default_rule = $builder->build(
295
        {
296
            source => 'CirculationRule',
297
            value  => {
298
                branchcode   => undef,
299
                categorycode => undef,
300
                itemtype     => undef,
301
                rule_name    => 'refund',
302
                rule_value   => 1
303
            }
304
        }
305
    );
306
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
307
    my $specific_rule_false = $builder->build(
308
        {
309
            source => 'CirculationRule',
310
            value  => {
311
                branchcode   => $branchcode,
312
                categorycode => undef,
313
                itemtype     => undef,
314
                rule_name    => 'refund',
315
                rule_value   => 0
316
            }
317
        }
318
    );
319
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
320
    my $specific_rule_true = $builder->build(
321
        {
322
            source => 'CirculationRule',
323
            value  => {
324
                branchcode   => $branchcode2,
325
                categorycode => undef,
326
                itemtype     => undef,
327
                rule_name    => 'refund',
328
                rule_value   => 1
329
            }
330
        }
331
    );
332
    # Make sure we have an unused branchcode
333
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
334
    my $specific_rule_dummy = $builder->build(
335
        {
336
            source => 'CirculationRule',
337
            value  => {
338
                branchcode   => $branchcode3,
339
                categorycode => undef,
340
                itemtype     => undef,
341
                rule_name    => 'refund',
342
            }
343
        }
344
    );
345
    my $branch_without_rule = $specific_rule_dummy->{ branchcode };
346
    Koha::CirculationRules
347
        ->search(
348
            {
349
                branchcode   => $branch_without_rule,
350
                categorycode => undef,
351
                itemtype     => undef,
352
                rule_name    => 'refund'
353
            }
354
          )
355
        ->next
356
        ->delete;
357
358
    my $item = $builder->build_sample_item(
359
        {
360
            homebranch    => $specific_rule_true->{branchcode},
361
            holdingbranch => $specific_rule_false->{branchcode}
362
        }
363
    );
364
    my $params = {
365
        return_branch => $specific_rule_true->{ branchcode },
366
        item          => $item
367
    };
368
369
    # Specific rules
370
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
371
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
372
          1,'Specific rule for checkin branch is applied (true)');
373
374
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
375
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
376
         1,'Specific rule for home branch is applied (true)');
377
378
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
379
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
380
         0,'Specific rule for holoding branch is applied (false)');
381
382
    # Default rule check
383
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
384
    $params->{return_branch} = $branch_without_rule;
385
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
386
         1,'No rule for branch, global rule applied (true)');
387
388
    # Change the default value just to try
389
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
390
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
391
         0,'No rule for branch, global rule applied (false)');
392
393
    # No default rule defined check
394
    Koha::CirculationRules
395
        ->search(
396
            {
397
                branchcode   => undef,
398
                categorycode => undef,
399
                itemtype     => undef,
400
                rule_name    => 'refund'
401
            }
402
          )
403
        ->next
404
        ->delete;
405
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
406
         1,'No rule for branch, no default rule, fallback default (true)');
407
408
    $schema->storage->txn_rollback;
409
};

Return to bug 25663