Bug 14769: Introduce Koha::Authority::ControlledIndicators
[koha.git] / t / Koha / Authority / ControlledIndicators.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use Data::Dumper qw/Dumper/;
5 use MARC::Record;
6 use MARC::Field;
7 use Test::More tests => 1;
8
9 use t::lib::Mocks;
10 use Koha::Authority::ControlledIndicators;
11
12 subtest "Simple tests" => sub {
13     plan tests => 10;
14
15     t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q|
16 marc21,600,ind1:auth1,ind2:x
17 marc21,700,ind1:auth2,
18 marc21,800,ind1:,
19     |);
20
21     my $oInd = Koha::Authority::ControlledIndicators->new;
22
23     is_deeply( $oInd->get({}), {}, 'Empty hash for no parameters' );
24     my $record = MARC::Record->new;
25     $record->append_fields(
26         MARC::Field->new( '100', '3', '4', a => 'My name' ),
27     );
28     my $res = $oInd->get({
29         flavour => "MARC21",
30         report_tag  => '100',
31         auth_record => $record,
32         biblio_tag  => '600',
33     });
34     is( $res->{ind1}, '3', 'Check 1st indicator' );
35     is( exists $res->{ind2}, 1, 'Check existence of 2nd indicator key' );
36     is( $res->{ind2}, 'x', 'Check 2nd indicator value' );
37
38     $res = $oInd->get({
39         flavour => "MARC21",
40         report_tag  => '100',
41         auth_record => $record,
42         biblio_tag  => '700',
43     });
44     is( $res->{ind1}, '4', 'Check 1st indicator' );
45     is( exists $res->{ind2}, '', 'Check if 2nd indicator key does not exist' );
46
47     $res = $oInd->get({
48         flavour => "MARC21",
49         report_tag  => '100',
50         auth_record => $record,
51         biblio_tag  => '800',
52     });
53     is( $res->{ind1}, '', 'ind1: clears 1st indicator' );
54     is( exists $res->{ind2}, '', 'Check if 2nd indicator key does not exist' );
55
56     # Test caching
57     t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q{} );
58     $res = $oInd->get({
59         flavour => "MARC21",
60         report_tag  => '100',
61         auth_record => $record,
62         biblio_tag  => '700',
63     });
64     is( $res->{ind1}, '4', 'Cache not cleared yet' );
65     $oInd->clear;
66     $res = $oInd->get({
67         flavour => "MARC21",
68         report_tag  => '100',
69         auth_record => $record,
70         biblio_tag  => '700',
71     });
72     is_deeply( $res, {}, 'Cache cleared' );
73 };