Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[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 => 2;
8
9 use t::lib::Mocks;
10 use Koha::Authority::ControlledIndicators;
11
12 subtest "Simple tests" => sub {
13     plan tests => 8;
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
57 subtest "Tests for sub _thesaurus_info" => sub {
58     plan tests => 10;
59
60     t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q|marc21,600,ignored,ind2:thesaurus|);
61     my $oInd = Koha::Authority::ControlledIndicators->new;
62
63     my $record = MARC::Record->new;
64     $record->append_fields(
65         MARC::Field->new( '008', (' 'x11).'a' ),
66         MARC::Field->new( '040', '', '', f => 'very_special' ),
67     );
68
69     # Case 1: LOC code a in auth record should become 0 in 6XX ind2
70     my $res = $oInd->get({
71         flavour => "MARC21",
72         report_tag  => '100',
73         auth_record => $record,
74         biblio_tag  => '600',
75     });
76     is( $res->{ind2}, '0', 'Indicator matched for LOC headings' );
77     is( $res->{sub2}, undef, 'No subfield 2' );
78
79     # Case 2: Code n (Not applicable) should become 4 (source not specified)
80     $record->field('008')->update( (' 'x11).'n' );
81     $res = $oInd->get({
82         flavour => "MARC21",
83         report_tag  => '100',
84         auth_record => $record,
85         biblio_tag  => '600',
86     });
87     is( $res->{ind2}, '4', 'Source not specified' );
88     is( $res->{sub2}, undef, 'No subfield 2' );
89
90     # Case 3: AAT thesaurus (and subfield $2)
91     $record->field('008')->update( (' 'x11).'r' );
92     $res = $oInd->get({
93         flavour => "MARC21",
94         report_tag  => '100',
95         auth_record => $record,
96         biblio_tag  => '600',
97     });
98     is( $res->{ind2}, '7', 'AAT, see subfield 2' );
99     is( $res->{sub2}, 'aat', 'Subfield 2 verified' );
100
101     # Case 4: Code z triggers a fetch from 040$f (and subfield $2)
102     $record->field('008')->update( (' 'x11).'z' );
103     $res = $oInd->get({
104         flavour => "MARC21",
105         report_tag  => '100',
106         auth_record => $record,
107         biblio_tag  => '600',
108     });
109     is( $res->{ind2}, '7', 'Code z, see subfield 2' );
110     is( $res->{sub2}, 'very_special', 'Subfield 2 from 040$f' );
111
112     # Case 5: Code e does not belong in 008/11
113     $record->field('008')->update( (' 'x11).'e' );
114     $res = $oInd->get({
115         flavour => "MARC21",
116         report_tag  => '100',
117         auth_record => $record,
118         biblio_tag  => '600',
119     });
120     is( $res->{ind2}, '4', 'Code e triggers not specified' );
121     is( $res->{sub2}, undef, 'No subfield 2' );
122 };