From 984b2731319c533d366cd713c940389227bf073a Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Tue, 17 Dec 2024 13:31:39 +0000 Subject: [PATCH] Bug 38729: Unit tests --- t/db_dependent/Heading.t | 68 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t index 80ce96b842..da2acfe46e 100755 --- a/t/db_dependent/Heading.t +++ b/t/db_dependent/Heading.t @@ -18,11 +18,17 @@ use strict; use warnings; -use Test::More tests => 4; +use open qw/ :std :utf8 /; +use Test::More tests => 5; use t::lib::Mocks; use Test::MockModule; +use MARC::Record; +use MARC::Field; +use utf8; +use C4::AuthoritiesMarc qw/ AddAuthority /; + BEGIN { use_ok('C4::Heading', qw( field valid_heading_subfield )); } @@ -195,3 +201,63 @@ subtest "_search tests" => sub { is_deeply( $terms, $expected_terms, "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled"); }; + +subtest "authorities exact match tests" => sub { + + plan tests => 2; + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + my $authrec1 = MARC::Record->new; + $authrec1->leader(' nz a22 o 4500'); + $authrec1->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Rakowski, Albin', x => 'poetry' ) ); + my $authid1 = AddAuthority( $authrec1, undef, 'PERSO_NAME', { skip_record_index => 1 } ); + + my $authrec2 = MARC::Record->new; + $authrec2->leader(' nz a22 o 4500'); + $authrec2->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Rąkowski, Albin', x => 'poetry' ) ); + my $authid2 = AddAuthority( $authrec2, undef, 'PERSO_NAME', { skip_record_index => 1 } ); + + my $heading = Test::MockModule->new('C4::Heading'); + $heading->mock( + '_search', + sub { + my $self = shift; + return ( [ { authid => $authid1 }, { authid => $authid2 } ], 2 ); + } + ); + + my $biblio_field = MARC::Field->new( '600', '1', '1', a => 'Rakowski, Albin', x => 'poetry' ); + my $biblio_heading = C4::Heading->new_from_field($biblio_field); + + my $authorities = $biblio_heading->authorities(1); + is_deeply( + $authorities, [ { authid => $authid1 } ], + "Authorities filter OK - remained authority 'Rakowski' for biblio 'Rakowski'" + ); + + my $authrec3 = MARC::Record->new; + $authrec3->leader(' nz a22 o 4500'); + $authrec3->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Bruckner, Karl' ) ); + my $authid3 = AddAuthority( $authrec3, undef, 'PERSO_NAME', { skip_record_index => 1 } ); + + $heading->mock( + '_search', + sub { + my $self = shift; + return ( [ { authid => $authid3 } ], 1 ); + } + ); + + $biblio_field = MARC::Field->new( '700', '1', ' ', a => 'Brückner, Karl' ); + $biblio_heading = C4::Heading->new_from_field($biblio_field); + + $authorities = $biblio_heading->authorities(1); + is_deeply( $authorities, [], "Authorities filter OK - 'Brückner' not matched with 'Bruckner'" ); + + $schema->storage->txn_rollback; + +}; -- 2.39.5