Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use Test::More tests => 1; |
5 |
|
6 |
use t::lib::Mocks; |
7 |
use t::lib::TestBuilder; |
8 |
use Koha::Database; |
9 |
use Koha::IssuingRules; |
10 |
|
11 |
my $schema = Koha::Database->new->schema; |
12 |
$schema->storage->txn_begin; |
13 |
our $builder = t::lib::TestBuilder->new; |
14 |
|
15 |
subtest 'guess_article_requestable_itemtypes' => sub { |
16 |
plan tests => 12; |
17 |
|
18 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
19 |
Koha::IssuingRules->delete; |
20 |
my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
21 |
my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
22 |
my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
23 |
my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
24 |
my $rule1 = $builder->build_object({ |
25 |
class => 'Koha::IssuingRules', |
26 |
value => { |
27 |
branchcode => 'MPL', # no worries: no FK |
28 |
categorycode => '*', |
29 |
itemtype => $itype1->itemtype, |
30 |
article_requests => 'bib_only', |
31 |
}, |
32 |
}); |
33 |
my $rule2 = $builder->build_object({ |
34 |
class => 'Koha::IssuingRules', |
35 |
value => { |
36 |
branchcode => '*', |
37 |
categorycode => $catg1->categorycode, |
38 |
itemtype => $itype2->itemtype, |
39 |
article_requests => 'yes', |
40 |
}, |
41 |
}); |
42 |
|
43 |
my $res = Koha::IssuingRules->guess_article_requestable_itemtypes; |
44 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
45 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
46 |
is( $res->{$itype2->itemtype}, 1, 'Item type 2 seems permitted' ); |
47 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
48 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
49 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
50 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
51 |
|
52 |
# Change the rules |
53 |
$rule2->itemtype('*')->store; |
54 |
$Koha::IssuingRules::last_article_requestable_guesses = {}; |
55 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes; |
56 |
is( $res->{'*'}, 1, 'Item type * seems permitted' ); |
57 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
58 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
59 |
$res = Koha::IssuingRules->guess_article_requestable_itemtypes({ categorycode => $catg2->categorycode }); |
60 |
is( $res->{'*'}, undef, 'Item type * seems not permitted' ); |
61 |
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' ); |
62 |
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); |
63 |
|
64 |
$Koha::IssuingRules::last_article_requestable_guesses = {}; |
65 |
}; |
66 |
|
67 |
$schema->storage->txn_rollback; |