|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use CGI; |
| 5 |
use Encode qw( encode ); |
| 6 |
use Test::More tests => 2; |
| 7 |
|
| 8 |
use C4::Biblio; |
| 9 |
|
| 10 |
my ( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber", '' ); |
| 11 |
subtest 'Biblio record' => sub { |
| 12 |
plan tests => 10; |
| 13 |
my $leader = '00203nam a2200097 4500'; |
| 14 |
my $input = CGI->new; |
| 15 |
$input->param( -name => 'biblionumber', -value => '42' ); |
| 16 |
$input->param( -name => 'tag_000_indicator1_570367553534', -value => '' ); |
| 17 |
$input->param( -name => 'tag_000_indicator2_570367553534', -value => '' ); |
| 18 |
$input->param( -name => 'tag_000_code_00_570367_810561', -value => '' ); |
| 19 |
$input->param( -name => 'tag_000_subfield_00_570367_810561', -value => $leader ); |
| 20 |
$input->param( -name => 'tag_010_indicator1_493056', -value => '' ); |
| 21 |
$input->param( -name => 'tag_010_indicator2_493056', -value => '' ); |
| 22 |
$input->param( -name => 'tag_010_code_a_493056_296409', -value => 'a' ); |
| 23 |
$input->param( -name => 'tag_010_subfield_a_493056_296409', -value => Encode::encode( 'utf-8', "first isbn é" ) ); |
| 24 |
$input->param( -name => 'tag_010_indicator1_49305613979', -value => '' ); |
| 25 |
$input->param( -name => 'tag_010_indicator2_49305613979', -value => '' ); |
| 26 |
$input->param( -name => 'tag_010_code_a_493056_29640913979', -value => 'a' ); |
| 27 |
$input->param( -name => 'tag_010_subfield_a_493056_29640913979', -value => Encode::encode( 'utf-8', "second isbn à" ) ); # 2 010 fields |
| 28 |
$input->param( -name => 'tag_100_indicator1_588794844868', -value => '' ); |
| 29 |
$input->param( -name => 'tag_100_indicator2_588794844868', -value => '' ); |
| 30 |
$input->param( -name => 'tag_100_code_a_588794_15537', -value => 'a' ); |
| 31 |
$input->param( -name => 'tag_100_subfield_a_588794_15537', -value => '20160112d u||y0frey5050 ba' ); |
| 32 |
$input->param( -name => 'tag_200_indicator1_593269251146', -value => '' ); |
| 33 |
$input->param( -name => 'tag_200_indicator2_593269251146', -value => '' ); |
| 34 |
$input->param( -name => 'tag_200_code_a_593269_944056', -value => 'a' ); |
| 35 |
$input->param( -name => 'tag_200_subfield_a_593269_944056', -value => 'first title' ); # 2 200$a in the same field |
| 36 |
$input->param( -name => 'tag_200_code_a_593269_94405618065', -value => 'a' ); |
| 37 |
$input->param( -name => 'tag_200_subfield_a_593269_94405618065', -value => 'second title' ); |
| 38 |
$input->param( -name => 'tag_200_code_b_593269_250538', -value => 'b' ); |
| 39 |
$input->param( -name => 'tag_200_subfield_b_593269_250538', -value => 'DVD' ); |
| 40 |
$input->param( -name => 'tag_200_code_f_593269_445603', -value => 'f' ); |
| 41 |
$input->param( -name => 'tag_200_subfield_f_593269_445603', -value => 'author' ); |
| 42 |
$input->param( -name => 'tag_200_code_h_593269_616594', -value => 'h' ); # Empty field |
| 43 |
$input->param( -name => 'tag_200_subfield_h_593269_616594', -value => '' ); |
| 44 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator1_588794844868", -value => "" ); |
| 45 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator2_588794844868", -value => "" ); |
| 46 |
$input->param( -name => "tag_${biblionumbertagfield}_code_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagsubfield ); |
| 47 |
$input->param( -name => "tag_${biblionumbertagfield}_subfield_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagfield ); |
| 48 |
|
| 49 |
my $record = C4::Biblio::TransformHtmlToMarc($input, 1); |
| 50 |
|
| 51 |
my @all_fields = $record->fields; |
| 52 |
is( @all_fields, 5, 'The record should have been created with 5 fields (biblionumber + 2x010 + 1x100 + 1x200)' ); |
| 53 |
my @fields_010 = $record->field('010'); |
| 54 |
is( @fields_010, 2, 'The record should have been created with 2 010' ); |
| 55 |
my @fields_100 = $record->field('100'); |
| 56 |
is( @fields_100, 1, 'The record should have been created with 1 100' ); |
| 57 |
my @fields_200 = $record->field('200'); |
| 58 |
is( @fields_200, 1, 'The record should have been created with 1 200' ); |
| 59 |
|
| 60 |
is_deeply( $fields_010[0]->subfields(), [ 'a', 'first isbn é' ], 'The first isbn should be correct' ); |
| 61 |
is_deeply( $fields_010[1]->subfields(), [ 'a', 'second isbn à' ], 'The second isbn should be correct' ); |
| 62 |
|
| 63 |
my @subfields_200_a = $record->subfield( 200, 'a' ); |
| 64 |
is( @subfields_200_a, 2, 'The record should have been created with 2 200$a' ); |
| 65 |
is_deeply( \@subfields_200_a, [ 'first title', 'second title' ], 'The 2 titles should have been kept in the correct order' ); |
| 66 |
|
| 67 |
my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); |
| 68 |
is( @subfields_biblionumber, 1, 'The record should contain only one biblionumber field' ); |
| 69 |
|
| 70 |
is( $record->leader, $leader, 'The leader should have been kept' ); |
| 71 |
}; |
| 72 |
|
| 73 |
subtest 'Add authority record' => sub { |
| 74 |
plan tests => 1; |
| 75 |
|
| 76 |
my $input = CGI->new; |
| 77 |
$input->param( -name => 'tag_200_indicator1_906288', -value => '' ); |
| 78 |
$input->param( -name => 'tag_200_indicator2_906288', -value => '' ); |
| 79 |
$input->param( -name => 'tag_200_code_a_906288_722171', -value => 'a' ); |
| 80 |
$input->param( -name => 'tag_200_subfield_a_906288_722171', -value => 'a 200$a' ); |
| 81 |
$input->param( -name => 'tag_200_code_b_906288_611549', -value => 'b' ); |
| 82 |
$input->param( -name => 'tag_200_subfield_b_906288_611549', -value => 'a 200$b' ); |
| 83 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator1_198510", -value => "" ); |
| 84 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator2_198510", -value => "" ); |
| 85 |
$input->param( -name => "tag_${biblionumbertagfield}_code_${biblionumbertagsubfield}_198510_886205", -value => $biblionumbertagsubfield ); |
| 86 |
$input->param( -name => "tag_${biblionumbertagfield}_subfield_${biblionumbertagsubfield}_198510_886205", -value => "a biblionumber which is not a biblionumber" ); |
| 87 |
|
| 88 |
my $record = C4::Biblio::TransformHtmlToMarc($input, 0); |
| 89 |
|
| 90 |
my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); |
| 91 |
is( @subfields_biblionumber, 1, 'The record should contain the field which are mapped to biblio.biblionumber' ); |
| 92 |
}; |