4 use Test
::More tests
=> 1;
7 use t
::lib
::TestBuilder
;
9 use Koha
::IssuingRules
;
12 my $schema = Koha
::Database
->new->schema;
13 $schema->storage->txn_begin;
14 our $builder = t
::lib
::TestBuilder
->new;
15 our $cache = Koha
::Caches
->get_instance;
17 subtest
'guess_article_requestable_itemtypes' => sub {
20 t
::lib
::Mocks
::mock_preference
('ArticleRequests', 1);
21 $cache->clear_from_cache( Koha
::IssuingRules
::GUESSED_ITEMTYPES_KEY
);
22 Koha
::IssuingRules
->delete;
23 my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
24 my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' });
25 my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' });
26 my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' });
27 my $rule1 = $builder->build_object({
28 class => 'Koha::IssuingRules',
30 branchcode
=> 'MPL', # no worries: no FK
32 itemtype
=> $itype1->itemtype,
33 article_requests
=> 'bib_only',
36 my $rule2 = $builder->build_object({
37 class => 'Koha::IssuingRules',
40 categorycode
=> $catg1->categorycode,
41 itemtype
=> $itype2->itemtype,
42 article_requests
=> 'yes',
46 my $res = Koha
::IssuingRules
->guess_article_requestable_itemtypes;
47 is
( $res->{'*'}, undef, 'Item type * seems not permitted' );
48 is
( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
49 is
( $res->{$itype2->itemtype}, 1, 'Item type 2 seems permitted' );
50 $res = Koha
::IssuingRules
->guess_article_requestable_itemtypes({ categorycode
=> $catg2->categorycode });
51 is
( $res->{'*'}, undef, 'Item type * seems not permitted' );
52 is
( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
53 is
( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
56 $rule2->itemtype('*')->store;
57 $cache->clear_from_cache( Koha
::IssuingRules
::GUESSED_ITEMTYPES_KEY
);
58 $res = Koha
::IssuingRules
->guess_article_requestable_itemtypes;
59 is
( $res->{'*'}, 1, 'Item type * seems permitted' );
60 is
( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
61 is
( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
62 $res = Koha
::IssuingRules
->guess_article_requestable_itemtypes({ categorycode
=> $catg2->categorycode });
63 is
( $res->{'*'}, undef, 'Item type * seems not permitted' );
64 is
( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
65 is
( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
67 $cache->clear_from_cache( Koha
::IssuingRules
::GUESSED_ITEMTYPES_KEY
);
70 $schema->storage->txn_rollback;