|
Lines 6-12
use Test::More tests => 1;
Link Here
|
| 6 |
use t::lib::Mocks; |
6 |
use t::lib::Mocks; |
| 7 |
use t::lib::TestBuilder; |
7 |
use t::lib::TestBuilder; |
| 8 |
use Koha::Database; |
8 |
use Koha::Database; |
| 9 |
use Koha::IssuingRules; |
9 |
use Koha::CirculationRules; |
| 10 |
use Koha::Caches; |
10 |
use Koha::Caches; |
| 11 |
|
11 |
|
| 12 |
my $schema = Koha::Database->new->schema; |
12 |
my $schema = Koha::Database->new->schema; |
|
Lines 19-32
subtest 'guess_article_requestable_itemtypes' => sub {
Link Here
|
| 19 |
|
19 |
|
| 20 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
20 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
| 21 |
t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc'); |
21 |
t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc'); |
| 22 |
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY ); |
22 |
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); |
| 23 |
Koha::IssuingRules->delete; |
23 |
Koha::CirculationRules->delete; |
| 24 |
my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
24 |
my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 25 |
my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
25 |
my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 26 |
my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
26 |
my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
| 27 |
my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
27 |
my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
| 28 |
my $rule1 = $builder->build_object({ |
28 |
my $rule1 = $builder->build_object({ |
| 29 |
class => 'Koha::IssuingRules', |
29 |
class => 'Koha::CirculationRules', |
| 30 |
value => { |
30 |
value => { |
| 31 |
branchcode => 'MPL', # no worries: no FK |
31 |
branchcode => 'MPL', # no worries: no FK |
| 32 |
categorycode => '*', |
32 |
categorycode => '*', |
|
Lines 35-41
subtest 'guess_article_requestable_itemtypes' => sub {
Link Here
|
| 35 |
}, |
35 |
}, |
| 36 |
}); |
36 |
}); |
| 37 |
my $rule2 = $builder->build_object({ |
37 |
my $rule2 = $builder->build_object({ |
| 38 |
class => 'Koha::IssuingRules', |
38 |
class => 'Koha::CirculationRules', |
| 39 |
value => { |
39 |
value => { |
| 40 |
branchcode => '*', |
40 |
branchcode => '*', |
| 41 |
categorycode => $catg1->categorycode, |
41 |
categorycode => $catg1->categorycode, |
|
Lines 44-76
subtest 'guess_article_requestable_itemtypes' => sub {
Link Here
|
| 44 |
}, |
44 |
}, |
| 45 |
}); |
45 |
}); |
| 46 |
|
46 |
|
| 47 |
my $res = Koha::IssuingRules->guess_article_requestable_itemtypes; |
47 |
my $res = Koha::CirculationRules->guess_article_requestable_itemtypes; |
| 48 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
48 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
| 49 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
49 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
| 50 |
is( $res->{$itype2->itemtype}, 1, 'Item type 2 seems permitted' ); |
50 |
is( $res->{$itype2->itemtype}, 1, 'Item type 2 seems permitted' ); |
| 51 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
51 |
$res = Koha::CirculationRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
| 52 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
52 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
| 53 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
53 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
| 54 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
54 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
| 55 |
|
55 |
|
| 56 |
# Change the rules |
56 |
# Change the rules |
| 57 |
$rule2->itemtype('*')->store; |
57 |
$rule2->itemtype('*')->store; |
| 58 |
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY ); |
58 |
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); |
| 59 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes; |
59 |
$res = Koha::CirculationRules->guess_article_requestable_itemtypes; |
| 60 |
is( $res->{'*'}, 1, 'Item type * seems permitted' ); |
60 |
is( $res->{'*'}, 1, 'Item type * seems permitted' ); |
| 61 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
61 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
| 62 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
62 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
| 63 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
63 |
$res = Koha::CirculationRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
| 64 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
64 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
| 65 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
65 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
| 66 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
66 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
| 67 |
|
67 |
|
| 68 |
# Finally test the overriding pref |
68 |
# Finally test the overriding pref |
| 69 |
t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always'); |
69 |
t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always'); |
| 70 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes({}); |
70 |
$res = Koha::CirculationRules->guess_article_requestable_itemtypes({}); |
| 71 |
is( $res->{'*'}, 1, 'Override algorithm with pref setting' ); |
71 |
is( $res->{'*'}, 1, 'Override algorithm with pref setting' ); |
| 72 |
|
72 |
|
| 73 |
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY ); |
73 |
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); |
| 74 |
}; |
74 |
}; |
| 75 |
|
75 |
|
| 76 |
$schema->storage->txn_rollback; |
76 |
$schema->storage->txn_rollback; |
| 77 |
- |
|
|