From 3796af407685077e693e51605acf0adb7d1f7b9b Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
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
---
 Koha/Biblio.pm               | 14 +++++++++++++
 t/db_dependent/Koha/Biblio.t | 40 +++++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm
index 927d7b898e0..b26760c21d4 100644
--- a/Koha/Biblio.pm
+++ b/Koha/Biblio.pm
@@ -1660,6 +1660,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 0576acca567..c5e61e78d21 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;
 
@@ -1733,6 +1733,44 @@ subtest 'normalized_oclc' => sub {
     );
 };
 
+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;
+};
+
 subtest 'ratings' => sub {
     plan tests => 1;
     # See t/db_dependent/Koha/Ratings.t
-- 
2.47.1