Bug 35343: Add record accessor method to Koha::Authority

Code lifted from bug 31794 to fix already backported bug 26611.

Unit tests included.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 40115a2c8cba3e081ffd0710899ef4556a3bbb54)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2022-12-06 17:07:02 -03:00 committed by Matt Blenkinsop
parent 2e99040bfe
commit f86419cea7
2 changed files with 57 additions and 9 deletions

View file

@ -95,8 +95,7 @@ sub controlled_indicators {
? 'UNIMARCAUTH'
: 'MARC21';
if( !$record ) {
$record = MARC::Record->new_from_xml(
$self->marcxml, 'UTF-8', $flavour );
$record = $self->record;
}
if( !$self->{_report_tag} ) {
@ -125,12 +124,7 @@ Return a list of identifiers of the authors which are in 024$2$a
sub get_identifiers {
my ( $self, $params ) = @_;
my $flavour =
C4::Context->preference('marcflavour') eq 'UNIMARC'
? 'UNIMARCAUTH'
: 'MARC21';
my $record =
MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
my $record = $self->record;
my @identifiers;
for my $field ( $record->field('024') ) {
@ -143,6 +137,24 @@ sub get_identifiers {
return \@identifiers;
}
=head3 record
my $record = $authority->record()
Return the MARC::Record for this authority
=cut
sub record {
my ( $self ) = @_;
my $flavour =
C4::Context->preference('marcflavour') eq 'UNIMARC'
? 'UNIMARCAUTH'
: 'MARC21';
return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
}
=head2 Class Methods
=head3 type

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 8;
use Test::More tests => 9;
use MARC::Field;
use MARC::File::XML;
use MARC::Record;
@ -285,4 +285,40 @@ subtest 'get_identifiers' => sub {
);
};
subtest 'record tests' => sub {
plan tests => 3;
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
my $record = MARC::Record->new();
$record->add_fields(
[
'100', ' ', ' ',
a => 'Lastname, Firstname',
b => 'b',
c => 'c',
i => 'i'
],
[
'024', '', '',
a => '0000-0002-1234-5678',
2 => 'orcid',
6 => 'https://orcid.org/0000-0002-1234-5678'
],
[
'024', '', '',
a => '01234567890',
2 => 'scopus',
6 => 'https://www.scopus.com/authid/detail.uri?authorId=01234567890'
],
);
my $authid = C4::AuthoritiesMarc::AddAuthority($record, undef, 'PERSO_NAME');
my $authority = Koha::Authorities->find($authid);
my $authority_record = $authority->record;
is ($authority_record->field('100')->subfield('a'), 'Lastname, Firstname');
my @fields_024 = $authority_record->field('024');
is ($fields_024[0]->subfield('a'), '0000-0002-1234-5678');
is ($fields_024[1]->subfield('a'), '01234567890');
};
$schema->storage->txn_rollback;