From 055658237550f43df84d50496bb03be6cc54fc94 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 20 Jan 2023 15:33:39 +0100 Subject: [PATCH] Bug 32336: Add unit test for UNIMARC encoding problems in REST API Signed-off-by: Jonathan Druart --- t/db_dependent/api/v1/biblios.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t index afff055e360..d0740842388 100755 --- a/t/db_dependent/api/v1/biblios.t +++ b/t/db_dependent/api/v1/biblios.t @@ -45,7 +45,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); subtest 'get() tests' => sub { - plan tests => 21; + plan tests => 22; $schema->storage->txn_begin; @@ -124,6 +124,37 @@ subtest 'get() tests' => sub { like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); }; + subtest 'marcxml encoding tests' => sub { + plan tests => 3; + + my $marcflavour = C4::Context->preference('marcflavour'); + t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); + + + my $title_with_diacritics = "L'insoutenable légèreté de l'être"; + + my $biblio = $builder->build_sample_biblio( + { + title => $title_with_diacritics, + author => "Milan Kundera" + } + ); + + my $record = $biblio->metadata->record; + $record->leader(' nam 3 4500'); + $biblio->metadata->metadata($record->as_xml_record('UNIMARC')); + $biblio->metadata->store; + + my $result = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber + => { Accept => 'application/marcxml+xml' } ) + ->status_is(200)->tx->res->body; + + my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); + + like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); + t::lib::Mocks::mock_preference('marcflavour', $marcflavour); + }; + $schema->storage->txn_rollback; }; -- 2.25.1