From aa592d4669988bfd6fc258a0e40934869abb73bc Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Wed, 17 Jul 2024 09:57:53 +0100
Subject: [PATCH] Bug 37364: Unit tests

---
 t/db_dependent/Koha/Biblio.t | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t
index 7226421d232..c3943735041 100755
--- a/t/db_dependent/Koha/Biblio.t
+++ b/t/db_dependent/Koha/Biblio.t
@@ -943,7 +943,7 @@ subtest 'get_volumes_query' => sub {
 };
 
 subtest 'generate_marc_host_field' => sub {
-    plan tests => 22;
+    plan tests => 24;
 
     $schema->storage->txn_begin;
 
@@ -955,7 +955,7 @@ subtest 'generate_marc_host_field' => sub {
         MARC::Field->new( '001', '1234' ),
         MARC::Field->new( '003', 'FIRST' ),
         MARC::Field->new( '240', '', '', a => 'A uniform title' ),
-        MARC::Field->new( '260', '', '', a => 'Publication' ),
+        MARC::Field->new( '260', '', '', a => 'Publication 260' ),
         MARC::Field->new( '250', '', '', a => 'Edition a', b => 'Edition b' ),
         MARC::Field->new( '022', '', '', a => '0317-8471' ),
     );
@@ -969,7 +969,7 @@ subtest 'generate_marc_host_field' => sub {
     is( $link->tag,           '773',                 "MARC::Field->tag returns '773' when marcflavour is 'MARC21" );
     is( $link->subfield('a'), 'Some boring author',  'MARC::Field->subfield(a) returns content from 100ab' );
     is( $link->subfield('b'), 'Edition a Edition b', 'MARC::Field->subfield(b) returns content from 250ab' );
-    is( $link->subfield('d'), 'Publication',         'MARC::Field->subfield(c) returns content from 260abc' );
+    is( $link->subfield('d'), 'Publication 260',     'MARC::Field->subfield(c) returns content from 260abc' );
     is( $link->subfield('s'), 'A uniform title',     'MARC::Field->subfield(s) returns content from 240a' );
     is( $link->subfield('t'), 'Some boring read',    'MARC::Field->subfield(s) returns content from 245ab' );
     is( $link->subfield('x'), '0317-8471',           'MARC::Field->subfield(s) returns content from 022a' );
@@ -983,6 +983,30 @@ subtest 'generate_marc_host_field' => sub {
         'MARC::Field->subfield(w) returns content from 003 and 001 when "UseControlNumber" is enabled'
     );
 
+    $record->append_fields(
+        MARC::Field->new( '264', '', '', a => 'Publication 264' ),
+    );
+    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
+    $biblio = Koha::Biblios->find( $biblio->biblionumber );
+
+    $link = $biblio->generate_marc_host_field();
+    is(
+        $link->subfield('d'), 'Publication 264',
+        'MARC::Field->subfield(d) returns content from 264 in prefernce to 260'
+    );
+
+    $record->append_fields(
+        MARC::Field->new( '264', '3', '', a => 'Publication 264', b => 'Preferred' ),
+    );
+    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
+    $biblio = Koha::Biblios->find( $biblio->biblionumber );
+
+    $link = $biblio->generate_marc_host_field();
+    is(
+        $link->subfield('d'), 'Publication 264 Preferred',
+        'MARC::Field->subfield(d) returns content from 264 with indicator 1 = 3 in prefernce to 264 without'
+    );
+
     # UNIMARC tests
     t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
 
-- 
2.45.2