Bug 40962: Apply ViewPolicy filter consistently in OAI Server test setup

The test built @marcxml and @oaidc expected data using metadata_record()
with no parameters, while the OAI server's get_biblio_marcxml() always
calls metadata_record({ interface => 'opac' }), which applies the
ViewPolicy filter. On nodes where the MARC framework has non-default
hidden values (or a stale cache entry), ViewPolicy strips fields like 245,
causing the expected and actual responses to diverge.

Fix by using interface => 'opac' when building the expected data, and
deriving dc:title from the filtered MARC record rather than hardcoding it,
so both sides of every comparison go through the same code path.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-03-23 07:53:40 +01:00
parent cde9628b86
commit 91f3e51e1a
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
1 changed files with 12 additions and 2 deletions

View File

@ -107,14 +107,23 @@ foreach my $index ( 0 .. NUMBER_OF_MARC_RECORDS - 1 ) {
$timestamp .= 'Z';
$timestamp =~ s/ /T/;
my $biblio = Koha::Biblios->find($biblionumber);
$record = $biblio->metadata_record;
# Use the same interface => 'opac' filter that get_biblio_marcxml applies, so
# the expected data reflects exactly what the OAI server will return regardless
# of MARC framework field-visibility settings.
$record = $biblio->metadata_record( { interface => 'opac' } );
my $record_transformed = $record->clone;
$record_transformed->delete_fields( $record_transformed->field('952') );
# Derive dc:title from the filtered MARC record before converting to an XMLin
# hash, so oai_dc expectations stay consistent with the filtered output.
my $title_tag = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '200' : '245';
my $title_field = $record->field($title_tag);
$record_transformed = XMLin( $record_transformed->as_xml_record );
$record = XMLin( $record->as_xml_record );
push @header, { datestamp => $timestamp, identifier => "TEST:$biblionumber" };
my $dc = {
'dc:title' => "Title $index",
'dc:language' => "lng",
'dc:type' => {},
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
@ -123,6 +132,7 @@ foreach my $index ( 0 .. NUMBER_OF_MARC_RECORDS - 1 ) {
'xsi:schemaLocation' =>
'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
};
$dc->{'dc:title'} = $title_field->subfield('a') if $title_field;
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
$dc->{'dc:identifier'} = $biblionumber;
}