View | Details | Raw Unified | Return to bug 7933
Collapse All | Expand All

(-)a/t/Biblio/RemoveHiddenSubfields.t (-1 / +60 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 6;
5
6
use C4::Biblio;
7
8
# Avoid "redefined subroutine" warnings
9
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
10
*C4::Biblio::GetMarcStructure = \&Mock_GetMarcStructure;
11
12
my $tagslib = {
13
    '200' => { a   => { hidden => '0' } },
14
    '300' => { a   => { hidden => '1' } },
15
    '009' => { '@' => { hidden => '-2' } },
16
};
17
18
my $record_ori = MARC::Record->new;
19
$record_ori->append_fields(
20
    MARC::Field->new( '200', '', '', 'a' => 'Text to show' ) );
21
$record_ori->append_fields(
22
    MARC::Field->new( '300', '', '', 'a' => 'Text to hide OPAC' ) );
23
$record_ori->append_fields(
24
    MARC::Field->new( '009', 'Text to hide Intranet' ) );
25
26
my $record_opac = $record_ori->clone;
27
RemoveHiddenSubfields( $record_opac, $tagslib, 'opac' );
28
is( $record_opac->subfield( '200', 'a' ),
29
    'Text to show',
30
    'RemoveHiddenSubfields for OPAC does not remove always visible subfields' );
31
is( $record_opac->subfield( '300', 'a' ),
32
    undef, 'RemoveHiddenSubfields for OPAC removes OPAC hidden subfields' );
33
is(
34
    $record_opac->field('009')->data,
35
    'Text to hide Intranet',
36
    'RemoveHiddenSubfields for OPAC does not remove Intranet hidden subfields'
37
);
38
39
my $record_intra = $record_ori->clone;
40
RemoveHiddenSubfields( $record_intra, $tagslib, 'intranet' );
41
is(
42
    $record_intra->subfield( '200', 'a' ),
43
    'Text to show',
44
'RemoveHiddenSubfields for Intranet does not remove always visible subfields'
45
);
46
is(
47
    $record_intra->subfield( '300', 'a' ),
48
    'Text to hide OPAC',
49
    'RemoveHiddenSubfields for Intranet does not remove OPAC hidden subfields'
50
);
51
is( $record_intra->field('009'),
52
    undef,
53
    'RemoveHiddenSubfields for Intranet removes Intranet hidden subfields' );
54
55
# Mocked subs
56
57
# C4::Biblio::GetMarcStructure
58
sub Mock_GetMarcStructure {
59
    return $tagslib;
60
}

Return to bug 7933