From 1b4bb5709299264e33b2fec7df174742c31f7ea7 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 18 Dec 2024 11:13:08 -0300 Subject: [PATCH] Bug 28478: Add Koha::Biblio->opac_suppressed() This patch adds a convenient method at the Koha::Biblio level, as a wrapper for the extrator added on this bug. Following the established pattern we adopted a while back. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass! All use cases covered! 3. Sign off :-D Signed-off-by: Magnus Enger Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer --- Koha/Biblio.pm | 14 +++++++ t/db_dependent/Koha/Biblio.t | 73 ++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index c9baa0d154..e3971b1cb5 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1681,6 +1681,20 @@ sub normalized_upc { return $self->metadata_extractor->get_normalized_upc; } +=head3 opac_suppressed + + my $opac_suppressed = $biblio->opac_suppressed(); + +Returns whether the record is flagged as suppressed in the OPAC. +FIXME: Revisit after 38330 discussion + +=cut + +sub opac_suppressed { + my ($self) = @_; + return $self->metadata_extractor->get_opac_suppression(); +} + =head3 normalized_oclc my $normalized_oclc = $biblio->normalized_oclc diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index c1fd10a01e..9b20beb6bd 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 39; +use Test::More tests => 40; use Test::Exception; use Test::Warn; @@ -907,8 +907,6 @@ subtest 'get_marc_components() tests' => sub { subtest 'get_components_query' => sub { plan tests => 12; - $schema->storage->txn_begin; - my $biblio = $builder->build_sample_biblio(); my $biblionumber = $biblio->biblionumber; my $record = $biblio->metadata->record; @@ -953,16 +951,11 @@ subtest 'get_components_query' => sub { is( $comp_sort, "title_asc", "$engine: UseControlNumber enabled with MarcOrgCode sort if correct" ); $record->delete_field($marc_003_field); } - - $schema->storage->txn_rollback; - }; subtest 'get_volumes_query' => sub { plan tests => 3; - $schema->storage->txn_begin; - my $biblio = $builder->build_sample_biblio(); my $biblionumber = $biblio->biblionumber; my $record = $biblio->metadata->record; @@ -1002,8 +995,6 @@ subtest 'get_volumes_query' => sub { "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") NOT (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode" ); - - $schema->storage->txn_rollback; }; subtest 'generate_marc_host_field' => sub { @@ -1078,9 +1069,8 @@ subtest 'generate_marc_host_field' => sub { is( $link->subfield('y'), undef, 'MARC::Field->subfield(w) returns undef if 010a is empty' ); is( $link->subfield('0'), '1234', 'MARC::Field->subfield(0) returns content from 001' ); - t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); - $schema->storage->txn_rollback; + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); }; subtest 'link_marc_host' => sub { @@ -1806,12 +1796,9 @@ subtest 'item_groups() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'normalized_isbn() tests' => sub { - +subtest 'normalized_isbn' => sub { plan tests => 1; - $schema->storage->txn_begin; - # We will move the tests from GetNormalizedISBN here when it will get replaced my $biblio = $builder->build_sample_biblio(); $biblio->biblioitem->set( { isbn => '9781250067128 | 125006712X' } )->store; @@ -1819,16 +1806,11 @@ subtest 'normalized_isbn() tests' => sub { $biblio->normalized_isbn, C4::Koha::GetNormalizedISBN( $biblio->biblioitem->isbn ), 'normalized_isbn is a wrapper around C4::Koha::GetNormalizedISBN' ); - - $schema->storage->txn_rollback; }; -subtest 'normalized_upc() tests' => sub { - +subtest 'normalized_upc' => sub { plan tests => 1; - $schema->storage->txn_begin; - # We will move the tests from GetNormalizedUPC here when it will get replaced # Note that only a single test exist and it's not really meaningful... my $biblio = $builder->build_sample_biblio(); @@ -1836,16 +1818,11 @@ subtest 'normalized_upc() tests' => sub { $biblio->normalized_upc, C4::Koha::GetNormalizedUPC( $biblio->metadata->record ), 'normalized_upc is a wrapper around C4::Koha::GetNormalizedUPC' ); - - $schema->storage->txn_rollback; }; -subtest 'normalized_oclc() tests' => sub { - +subtest 'normalized_oclc' => sub { plan tests => 1; - $schema->storage->txn_begin; - # We will move the tests from GetNormalizedOCLC here when it will get replaced # Note that only a single test exist and it's not really meaningful... my $biblio = $builder->build_sample_biblio(); @@ -1853,6 +1830,42 @@ subtest 'normalized_oclc() tests' => sub { $biblio->normalized_oclc, C4::Koha::GetNormalizedOCLCNumber( $biblio->metadata->record ), 'normalized_oclc is a wrapper around C4::Koha::GetNormalizedOCLCNumber' ); +}; + +subtest 'opac_suppressed() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $record = MARC::Record->new; + $record->append_fields( + MARC::Field->new( '245', '', '', a => 'Some title 1' ), + MARC::Field->new( '942', '', '', n => '1' ), + ); + + my ($biblio_id) = AddBiblio( $record, qw{} ); + my $biblio = Koha::Biblios->find($biblio_id); + + ok( $biblio->opac_suppressed(), 'Record is suppressed' ); + + $record->field('942')->replace_with( MARC::Field->new( '942', '', '', n => '0' ) ); + ($biblio_id) = AddBiblio( $record, qw{} ); + $biblio = Koha::Biblios->find($biblio_id); + + ok( !$biblio->opac_suppressed(), 'Record is not suppressed' ); + + $record->field('942')->replace_with( MARC::Field->new( '942', '', '', n => '' ) ); + ($biblio_id) = AddBiblio( $record, qw{} ); + $biblio = Koha::Biblios->find($biblio_id); + + ok( !$biblio->opac_suppressed(), 'Record is not suppressed' ); + + $record->delete_field( $record->field('942') ); + ($biblio_id) = AddBiblio( $record, qw{} ); + $biblio = Koha::Biblios->find($biblio_id); + + ok( !$biblio->opac_suppressed(), 'Record is not suppressed' ); $schema->storage->txn_rollback; }; @@ -1868,8 +1881,6 @@ subtest 'opac_summary_html' => sub { plan tests => 2; - $schema->storage->txn_begin; - my $author = 'my author'; my $title = 'my title'; my $isbn = '9781250067128 | 125006712X'; @@ -1888,8 +1899,6 @@ subtest 'opac_summary_html' => sub { sprintf( 'Replace %s, %s, %s AND %s please', $author, $title, $biblio->normalized_isbn, $biblio->biblionumber ), 'opac_summary_html replaces the different patterns' ); - - $schema->storage->txn_rollback; }; subtest 'can_be_edited() tests' => sub {