From 693c37f32cdb881b7fd643056bc5f187ed531194 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 May 2013 10:36:41 +0200 Subject: [PATCH] Bug 8304: UT for new subroutines --- t/AuthoritiesMarc.t | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ t/Charset.t | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 t/AuthoritiesMarc.t diff --git a/t/AuthoritiesMarc.t b/t/AuthoritiesMarc.t new file mode 100644 index 0000000..15d5ae6 --- /dev/null +++ b/t/AuthoritiesMarc.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Test::More tests => 8; + +use t::lib::Mocks; +use C4::Context; +use MARC::Field; + +BEGIN{ + use_ok('C4::AuthoritiesMarc'); +} + +t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); + +is( C4::AuthoritiesMarc::authorityflavour(), q{UNIMARCAUTH}, 'marcflavour returns "UNIMARCAUTH" if UNIMARC' ); + + +my @fields = ( + MARC::Field->new( + 200, '', '', + a => 'text0', + d => '2010', + ), + MARC::Field->new( + 201, '', '', + a => 'text1', + c => '2001', + ), + MARC::Field->new( + 202, '', '', + a => 'text2', + 9 => '2002', + ), + MARC::Field->new( + 203, '', '', + b => 'text3', + h => '2003', + ), +); + +is( C4::AuthoritiesMarc::_test_string( 'text0', @fields ), 1, "text0 exists" ); +is( C4::AuthoritiesMarc::_test_string( '2001', @fields ), 1, "2001 exists" ); +is( C4::AuthoritiesMarc::_test_string( 'text2', @fields ), 1, "text2 exists" ); +is( C4::AuthoritiesMarc::_test_string( '2003', @fields ), 1, "2003 exists" ); +is( C4::AuthoritiesMarc::_test_string( 'text4', @fields ), 0, "text4 does not exist" ); +is( C4::AuthoritiesMarc::_test_string( '2004', @fields ), 0, "2004 does not exist" ); + diff --git a/t/Charset.t b/t/Charset.t index 7de3414..5a36737 100755 --- a/t/Charset.t +++ b/t/Charset.t @@ -1,9 +1,11 @@ #!/usr/bin/perl -use strict; -use warnings; +use Modern::Perl; +use MARC::Record; +use MARC::Field; + +use Test::More tests => 10; -use Test::More tests => 6; BEGIN { use_ok('C4::Charset'); } @@ -18,3 +20,33 @@ ok(!utf8::is_utf8($octets), "verify that IsStringUTF8ish does not magically turn $octets = "a\xc2" . "c"; ok(!IsStringUTF8ish($octets), "verify octets are not valid UTF-8"); + +my $record = MARC::Record->new; +my @fields = ( + MARC::Field->new( + 200, '', '', + a => q{l&ampoule}, + ), + MARC::Field->new( + 201, '', '', + a => q{l&&école}, + ), + MARC::Field->new( + 202, '', '', + a => q{l&&&&astronaute}, + ), + MARC::Field->new( + 203, '', '', + a => q{l'ampoule}, + ), +); +$record->append_fields(@fields); + +C4::Charset::SanitizeEntity( $record ); + +is( $record->subfield('200', 'a'), q{l&ampoule}); +is( $record->subfield('201', 'a'), q{l&école}); +is( $record->subfield('202', 'a'), q{l&astronaute}); +is( $record->subfield('203', 'a'), q{l'ampoule}); + + -- 1.7.10.4