#!/usr/bin/perl
#
# This is to test BDIx::Conector

use Modern::Perl;

use Test::More tests => 5+4;

BEGIN {
    use_ok('C4::Biblio');
    use_ok('C4::Context');
    use_ok('MARC::Record');
}

use utf8;

my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;

my $utf8str = '123 € الت';

# Create the item
my $record = MARC::Record->new();
$record->leader('03174nam a2200445 a 4500');
$record->append_fields(
    MARC::Field->new( '245', '0', '0', a => $utf8str )
);

is('UTF-8', $record->encoding,'Bad MARC::Record encoding');
is($utf8str, $record->subfield('245', 'a'), 'Encoding problem creating MARC::Record');

my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');

for (my $i=1 ; $i <= 4 ; $i++) {
    my $db_record = C4::Biblio::GetMarcBiblio($biblionumber);
    is($utf8str, $db_record->subfield('245', 'a'), 'Error');
    sleep 900; # pause in seconds
};

C4::Biblio::DelBiblio($biblionumber);

