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

(-)a/Koha/IssuingRules.pm (-3 / +17 lines)
Lines 44-53 sub get_effective_issuing_rule { Link Here
44
    my $itemtype     = $params->{itemtype};
44
    my $itemtype     = $params->{itemtype};
45
    my $branchcode   = $params->{branchcode};
45
    my $branchcode   = $params->{branchcode};
46
46
47
    my $search_categorycode = $default;
48
    my $search_itemtype     = $default;
49
    my $search_branchcode   = $default;
50
51
    if ($categorycode) {
52
        $search_categorycode = { 'in' => [ $categorycode, $default ] };
53
    }
54
    if ($itemtype) {
55
        $search_itemtype = { 'in' => [ $itemtype, $default ] };
56
    }
57
    if ($branchcode) {
58
        $search_branchcode = { 'in' => [ $branchcode, $default ] };
59
    }
60
47
    my $rule = $self->search({
61
    my $rule = $self->search({
48
        categorycode => { 'in' => [ $categorycode, $default ] },
62
        categorycode => $search_categorycode,
49
        itemtype     => { 'in' => [ $itemtype,     $default ] },
63
        itemtype     => $search_itemtype,
50
        branchcode   => { 'in' => [ $branchcode,   $default ] },
64
        branchcode   => $search_branchcode,
51
    }, {
65
    }, {
52
        order_by => {
66
        order_by => {
53
            -desc => ['branchcode', 'categorycode', 'itemtype']
67
            -desc => ['branchcode', 'categorycode', 'itemtype']
(-)a/t/db_dependent/Koha/IssuingRules.t (-2 / +30 lines)
Lines 33-39 $schema->storage->txn_begin; Link Here
33
my $builder      = t::lib::TestBuilder->new;
33
my $builder      = t::lib::TestBuilder->new;
34
34
35
subtest 'get_effective_issuing_rule' => sub {
35
subtest 'get_effective_issuing_rule' => sub {
36
    plan tests => 2;
36
    plan tests => 3;
37
37
38
    my $patron       = $builder->build({ source => 'Borrower' });
38
    my $patron       = $builder->build({ source => 'Borrower' });
39
    my $item     = $builder->build({ source => 'Item' });
39
    my $item     = $builder->build({ source => 'Item' });
Lines 42-47 subtest 'get_effective_issuing_rule' => sub { Link Here
42
    my $itemtype     = $item->{'itype'};
42
    my $itemtype     = $item->{'itype'};
43
    my $branchcode   = $item->{'homebranch'};
43
    my $branchcode   = $item->{'homebranch'};
44
44
45
    subtest 'Call with undefined values' => sub {
46
        plan tests => 4;
47
48
        my $rule;
49
        Koha::IssuingRules->delete;
50
        ok(!Koha::IssuingRules->search->count, 'There are no issuing rules.');
51
        $rule = Koha::IssuingRules->get_effective_issuing_rule({
52
            branchcode   => undef,
53
            categorycode => undef,
54
            itemtype     => undef,
55
        });
56
        is($rule, undef, 'When I attempt to get effective issuing rule by'
57
           .' providing undefined values, then undef is returned.');
58
        ok(Koha::IssuingRule->new({
59
            branchcode => '*',
60
            categorycode => '*',
61
            itemtype => '*',
62
        })->store, 'Given I added an issuing rule branchcode => *,'
63
           .' categorycode => *, itemtype => *,');
64
        $rule = Koha::IssuingRules->get_effective_issuing_rule({
65
            branchcode   => undef,
66
            categorycode => undef,
67
            itemtype     => undef,
68
        });
69
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective'
70
           .' issuing rule by providing undefined values, then the above one is'
71
           .' returned.');
72
    };
73
45
    subtest 'Get effective issuing rule in correct order' => sub {
74
    subtest 'Get effective issuing rule in correct order' => sub {
46
        plan tests => 18;
75
        plan tests => 18;
47
76
48
- 

Return to bug 17783