4 use Data
::Dumper qw
/Dumper/;
7 use Test
::More tests
=> 2;
10 use Koha
::Authority
::ControlledIndicators
;
12 subtest
"Simple tests" => sub {
15 t
::lib
::Mocks
::mock_preference
('AuthorityControlledIndicators', q
|
16 marc21
,600,ind1
:auth1
,ind2
:x
17 marc21
,700,ind1
:auth2
,
21 my $oInd = Koha
::Authority
::ControlledIndicators
->new;
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' ),
28 my $res = $oInd->get({
31 auth_record
=> $record,
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' );
41 auth_record
=> $record,
44 is
( $res->{ind1
}, '4', 'Check 1st indicator' );
45 is
( exists $res->{ind2
}, '', 'Check if 2nd indicator key does not exist' );
50 auth_record
=> $record,
53 is
( $res->{ind1
}, '', 'ind1: clears 1st indicator' );
54 is
( exists $res->{ind2
}, '', 'Check if 2nd indicator key does not exist' );
57 subtest
"Tests for sub _thesaurus_info" => sub {
60 t
::lib
::Mocks
::mock_preference
('AuthorityControlledIndicators', q
|marc21
,600,ignored
,ind2
:thesaurus
|);
61 my $oInd = Koha
::Authority
::ControlledIndicators
->new;
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' ),
69 # Case 1: LOC code a in auth record should become 0 in 6XX ind2
70 my $res = $oInd->get({
73 auth_record
=> $record,
76 is
( $res->{ind2
}, '0', 'Indicator matched for LOC headings' );
77 is
( $res->{sub2
}, undef, 'No subfield 2' );
79 # Case 2: Code n (Not applicable) should become 4 (source not specified)
80 $record->field('008')->update( (' 'x11
).'n' );
84 auth_record
=> $record,
87 is
( $res->{ind2
}, '4', 'Source not specified' );
88 is
( $res->{sub2
}, undef, 'No subfield 2' );
90 # Case 3: AAT thesaurus (and subfield $2)
91 $record->field('008')->update( (' 'x11
).'r' );
95 auth_record
=> $record,
98 is
( $res->{ind2
}, '7', 'AAT, see subfield 2' );
99 is
( $res->{sub2
}, 'aat', 'Subfield 2 verified' );
101 # Case 4: Code z triggers a fetch from 040$f (and subfield $2)
102 $record->field('008')->update( (' 'x11
).'z' );
106 auth_record
=> $record,
109 is
( $res->{ind2
}, '7', 'Code z, see subfield 2' );
110 is
( $res->{sub2
}, 'very_special', 'Subfield 2 from 040$f' );
112 # Case 5: Code e does not belong in 008/11
113 $record->field('008')->update( (' 'x11
).'e' );
117 auth_record
=> $record,
120 is
( $res->{ind2
}, '4', 'Code e triggers not specified' );
121 is
( $res->{sub2
}, undef, 'No subfield 2' );