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

(-)a/Koha/CirculationRules.pm (-1 / +1 lines)
Lines 481-487 sub guess_article_requestable_itemtypes { Link Here
481
    });
481
    });
482
    return $res if !$rules;
482
    return $res if !$rules;
483
    foreach my $rule ( $rules->as_list ) {
483
    foreach my $rule ( $rules->as_list ) {
484
        $res->{ $rule->itemtype } = 1;
484
        $res->{ $rule->itemtype // '*' } = 1;
485
    }
485
    }
486
    $last_article_requestable_guesses->{$key} = $res;
486
    $last_article_requestable_guesses->{$key} = $res;
487
    $cache->set_in_cache(GUESSED_ITEMTYPES_KEY, $last_article_requestable_guesses);
487
    $cache->set_in_cache(GUESSED_ITEMTYPES_KEY, $last_article_requestable_guesses);
(-)a/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t (-17 / +17 lines)
Lines 21-48 subtest 'guess_article_requestable_itemtypes' => sub { Link Here
21
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
21
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
22
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
22
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
23
    Koha::CirculationRules->delete;
23
    Koha::CirculationRules->delete;
24
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
24
    my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
25
    my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
25
    my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' });
26
    my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' });
26
    my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' });
27
    my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' });
27
    my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' });
28
    my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' });
28
    my $rule1 = $builder->build_object({
29
    my $rule1 = Koha::CirculationRules->set_rule(
29
        class => 'Koha::CirculationRules',
30
        {
30
        value => {
31
            branchcode   => $library->branchcode,
31
            branchcode => 'MPL', # no worries: no FK
32
            categorycode => undef,
32
            categorycode => '*',
33
            itemtype     => $itype1->itemtype,
33
            itemtype => $itype1->itemtype,
34
            rule_name    => 'article_requests',
34
            article_requests => 'bib_only',
35
            rule_value   => 'bib_only',
35
        },
36
        },
36
    });
37
    );
37
    my $rule2 = $builder->build_object({
38
    my $rule2 = Koha::CirculationRules->set_rule(
38
        class => 'Koha::CirculationRules',
39
        {
39
        value => {
40
            branchcode   => undef,
40
            branchcode => '*',
41
            categorycode => $catg1->categorycode,
41
            categorycode => $catg1->categorycode,
42
            itemtype => $itype2->itemtype,
42
            itemtype     => $itype2->itemtype,
43
            article_requests => 'yes',
43
            rule_name    => 'article_requests',
44
            rule_value   => 'yes',
44
        },
45
        },
45
    });
46
    );
46
47
47
    my $res = Koha::CirculationRules->guess_article_requestable_itemtypes;
48
    my $res = Koha::CirculationRules->guess_article_requestable_itemtypes;
48
    is( $res->{'*'}, undef, 'Item type * seems not permitted' );
49
    is( $res->{'*'}, undef, 'Item type * seems not permitted' );
Lines 54-60 subtest 'guess_article_requestable_itemtypes' => sub { Link Here
54
    is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
55
    is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
55
56
56
    # Change the rules
57
    # Change the rules
57
    $rule2->itemtype('*')->store;
58
    $rule2->itemtype(undef)->store;
58
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
59
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
59
    $res = Koha::CirculationRules->guess_article_requestable_itemtypes;
60
    $res = Koha::CirculationRules->guess_article_requestable_itemtypes;
60
    is( $res->{'*'}, 1, 'Item type * seems permitted' );
61
    is( $res->{'*'}, 1, 'Item type * seems permitted' );
61
- 

Return to bug 18936