Bug 28478: Add get_opac_suppression extractor
This patch adds an extractor method for the historically hardcoded field 942$n. This way we have a single place in which we code the extraction and sanitization of its value. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t => SUCCESS: Tests pass! All use cases are covered! 3. Sign off :-D Signed-off-by: Magnus Enger <magnus@libriotech.no> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
This commit is contained in:
parent
a8078a4f3d
commit
b8ff17d259
|
|
@ -76,6 +76,23 @@ sub metadata {
|
|||
return $self->{metadata};
|
||||
}
|
||||
|
||||
=head2 get_opac_suppression
|
||||
|
||||
my $opac_suppressed = $extractor->get_opac_suppression();
|
||||
|
||||
Returns whether the record is flagged as suppressed in the OPAC.
|
||||
FIXME: Revisit after 38330 discussion
|
||||
|
||||
=cut
|
||||
|
||||
sub get_opac_suppression {
|
||||
my ($self) = @_;
|
||||
|
||||
my $record = $self->metadata;
|
||||
|
||||
return $record->subfield( '942', 'n' ) ? 1 : 0;
|
||||
}
|
||||
|
||||
=head3 _normalize_string
|
||||
|
||||
my $normalized_string = $self->_normalize_string($string);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright 2025 Koha Development team
|
||||
#
|
||||
# This file is part of Koha
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::Exception;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
||||
use Koha::Biblio::Metadata::Extractor;
|
||||
|
||||
my $schema = Koha::Database->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
||||
subtest 'get_opac_suppression() tests' => sub {
|
||||
|
||||
plan tests => 8;
|
||||
|
||||
foreach my $marcflavour (qw( MARC21 UNIMARC )) {
|
||||
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour );
|
||||
|
||||
my $record = MARC::Record->new();
|
||||
my $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $record } );
|
||||
|
||||
is( $extractor->get_opac_suppression(), 0, 'If 942$n absent, then not suppressed' );
|
||||
|
||||
$record->append_fields( MARC::Field->new( '942', q{}, q{}, n => '' ) );
|
||||
is( $extractor->get_opac_suppression(), 0, 'If 942$n has empty string, then not suppressed' );
|
||||
|
||||
$record->field('942')->replace_with( MARC::Field->new( '942', q{}, q{}, n => 'potato' ) );
|
||||
is( $extractor->get_opac_suppression(), 1, 'If 942$n has something different than false, then suppressed' );
|
||||
|
||||
$record->field('942')->replace_with( MARC::Field->new( '942', q{}, q{}, n => '1' ) );
|
||||
is( $extractor->get_opac_suppression(), 1, 'If 942$n is 1, then suppressed' );
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue