From 36b038da19e755e85e7591bd29b899d6bd8ad5da 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 --- 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 b4e98b17f4..462a010971 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.30.2