From d56d28e2088f2f8e7680e5710acb33d78b5c52a0 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Thu, 13 Jun 2013 10:12:08 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 7933: Unit test for C4::Biblio::RemoveHiddenSubfields Signed-off-by: Bernardo Gonzalez Kriegel Run without errors. No koha-qa errors --- t/Biblio/RemoveHiddenSubfields.t | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 t/Biblio/RemoveHiddenSubfields.t diff --git a/t/Biblio/RemoveHiddenSubfields.t b/t/Biblio/RemoveHiddenSubfields.t new file mode 100755 index 0000000..2261606 --- /dev/null +++ b/t/Biblio/RemoveHiddenSubfields.t @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Test::More tests => 6; + +use C4::Biblio; + +# Avoid "redefined subroutine" warnings +local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ }; +*C4::Biblio::GetMarcStructure = \&Mock_GetMarcStructure; + +my $tagslib = { + '200' => { a => { hidden => '0' } }, + '300' => { a => { hidden => '1' } }, + '009' => { '@' => { hidden => '-2' } }, +}; + +my $record_ori = MARC::Record->new; +$record_ori->append_fields( + MARC::Field->new( '200', '', '', 'a' => 'Text to show' ) ); +$record_ori->append_fields( + MARC::Field->new( '300', '', '', 'a' => 'Text to hide OPAC' ) ); +$record_ori->append_fields( + MARC::Field->new( '009', 'Text to hide Intranet' ) ); + +my $record_opac = $record_ori->clone; +RemoveHiddenSubfields( $record_opac, $tagslib, 'opac' ); +is( $record_opac->subfield( '200', 'a' ), + 'Text to show', + 'RemoveHiddenSubfields for OPAC does not remove always visible subfields' ); +is( $record_opac->subfield( '300', 'a' ), + undef, 'RemoveHiddenSubfields for OPAC removes OPAC hidden subfields' ); +is( + $record_opac->field('009')->data, + 'Text to hide Intranet', + 'RemoveHiddenSubfields for OPAC does not remove Intranet hidden subfields' +); + +my $record_intra = $record_ori->clone; +RemoveHiddenSubfields( $record_intra, $tagslib, 'intranet' ); +is( + $record_intra->subfield( '200', 'a' ), + 'Text to show', +'RemoveHiddenSubfields for Intranet does not remove always visible subfields' +); +is( + $record_intra->subfield( '300', 'a' ), + 'Text to hide OPAC', + 'RemoveHiddenSubfields for Intranet does not remove OPAC hidden subfields' +); +is( $record_intra->field('009'), + undef, + 'RemoveHiddenSubfields for Intranet removes Intranet hidden subfields' ); + +# Mocked subs + +# C4::Biblio::GetMarcStructure +sub Mock_GetMarcStructure { + return $tagslib; +} -- 1.7.9.5