|
Lines 5-15
use CGI;
Link Here
|
| 5 |
use Encode qw( encode ); |
5 |
use Encode qw( encode ); |
| 6 |
use Test::More tests => 2; |
6 |
use Test::More tests => 2; |
| 7 |
|
7 |
|
|
|
8 |
use Koha::Caches; |
| 9 |
use Koha::Database; |
| 10 |
use Koha::MarcSubfieldStructures; |
| 8 |
use C4::Biblio; |
11 |
use C4::Biblio; |
| 9 |
|
12 |
|
| 10 |
my ( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" ); |
13 |
our ( $biblionumbertagfield, $biblionumbertagsubfield ); |
|
|
14 |
my $schema = Koha::Database->new->schema; |
| 15 |
$schema->storage->txn_begin; |
| 16 |
|
| 17 |
# Move field for biblionumber to imaginary 399 |
| 18 |
Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'biblio.biblionumber' })->delete; |
| 19 |
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '399', tagsubfield => 'a' })->delete; |
| 20 |
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '399', tagsubfield => 'a', kohafield => "biblio.biblionumber" })->store; |
| 21 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
| 22 |
( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" ); |
| 23 |
|
| 11 |
subtest 'Biblio record' => sub { |
24 |
subtest 'Biblio record' => sub { |
| 12 |
plan tests => 10; |
25 |
plan tests => 17; |
| 13 |
my $leader = '00203nam a2200097 4500'; |
26 |
my $leader = '00203nam a2200097 4500'; |
| 14 |
my $input = CGI->new; |
27 |
my $input = CGI->new; |
| 15 |
$input->param( -name => 'biblionumber', -value => '42' ); |
28 |
$input->param( -name => 'biblionumber', -value => '42' ); |
|
Lines 41-55
subtest 'Biblio record' => sub {
Link Here
|
| 41 |
$input->param( -name => 'tag_200_subfield_f_593269_445603', -value => 'author' ); |
54 |
$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 |
55 |
$input->param( -name => 'tag_200_code_h_593269_616594', -value => 'h' ); # Empty field |
| 43 |
$input->param( -name => 'tag_200_subfield_h_593269_616594', -value => '' ); |
56 |
$input->param( -name => 'tag_200_subfield_h_593269_616594', -value => '' ); |
|
|
57 |
|
| 58 |
# Add a field 390 before our 399 |
| 59 |
$input->param( -name => "tag_390_indicator1_123", -value => "" ); |
| 60 |
$input->param( -name => "tag_390_indicator2_123", -value => "" ); |
| 61 |
$input->param( -name => "tag_390_code_a_123", -value => 'a' ); |
| 62 |
$input->param( -name => "tag_390_subfield_a_123", -value => '390a' ); |
| 63 |
|
| 64 |
# Our imaginary biblionumber field in 399 |
| 44 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator1_588794844868", -value => "" ); |
65 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator1_588794844868", -value => "" ); |
| 45 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator2_588794844868", -value => "" ); |
66 |
$input->param( -name => "tag_${biblionumbertagfield}_indicator2_588794844868", -value => "" ); |
| 46 |
$input->param( -name => "tag_${biblionumbertagfield}_code_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagsubfield ); |
67 |
$input->param( -name => "tag_${biblionumbertagfield}_code_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagsubfield ); |
| 47 |
$input->param( -name => "tag_${biblionumbertagfield}_subfield_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagfield ); |
68 |
$input->param( -name => "tag_${biblionumbertagfield}_subfield_${biblionumbertagsubfield}_588794_784323", -value => $biblionumbertagfield ); |
| 48 |
|
69 |
|
|
|
70 |
# A field (490) after 399 |
| 71 |
$input->param( -name => "tag_490_indicator1_1123", -value => "" ); |
| 72 |
$input->param( -name => "tag_490_indicator2_1123", -value => "" ); |
| 73 |
$input->param( -name => "tag_490_code_b_1123", -value => 'b' ); |
| 74 |
$input->param( -name => "tag_490_subfield_b_1123", -value => '490b' ); |
| 75 |
|
| 49 |
my $record = C4::Biblio::TransformHtmlToMarc($input, 1); |
76 |
my $record = C4::Biblio::TransformHtmlToMarc($input, 1); |
| 50 |
|
77 |
|
| 51 |
my @all_fields = $record->fields; |
78 |
my @all_fields = $record->fields; |
| 52 |
is( @all_fields, 5, 'The record should have been created with 5 fields (biblionumber + 2x010 + 1x100 + 1x200)' ); |
79 |
is( @all_fields, 7, 'The record should have been created with 7 fields' ); |
|
|
80 |
# biblionumber + 2x010 + 100 + 200 + 390 + 490 |
| 53 |
my @fields_010 = $record->field('010'); |
81 |
my @fields_010 = $record->field('010'); |
| 54 |
is( @fields_010, 2, 'The record should have been created with 2 010' ); |
82 |
is( @fields_010, 2, 'The record should have been created with 2 010' ); |
| 55 |
my @fields_100 = $record->field('100'); |
83 |
my @fields_100 = $record->field('100'); |
|
Lines 68-73
subtest 'Biblio record' => sub {
Link Here
|
| 68 |
is( @subfields_biblionumber, 1, 'The record should contain only one biblionumber field' ); |
96 |
is( @subfields_biblionumber, 1, 'The record should contain only one biblionumber field' ); |
| 69 |
|
97 |
|
| 70 |
is( $record->leader, $leader, 'The leader should have been kept' ); |
98 |
is( $record->leader, $leader, 'The leader should have been kept' ); |
|
|
99 |
|
| 100 |
# Check the order of some fields |
| 101 |
is( $all_fields[0]->tag, '010', 'First field expected 010' ); |
| 102 |
is( $all_fields[1]->tag, '010', 'Second field also 010' ); |
| 103 |
is( $all_fields[2]->tag, '100', 'Third field is 100' ); |
| 104 |
is( $all_fields[3]->tag, '200', 'Fourth field is 200' ); |
| 105 |
is( $all_fields[4]->tag, '390', 'Fifth field is 390' ); |
| 106 |
is( $all_fields[5]->subfield('a'), 42, 'Sixth field contains bibnumber' ); |
| 107 |
is( $all_fields[6]->tag, '490', 'Last field is 490' ); |
| 71 |
}; |
108 |
}; |
| 72 |
|
109 |
|
| 73 |
subtest 'Add authority record' => sub { |
110 |
subtest 'Add authority record' => sub { |
|
Lines 90-92
subtest 'Add authority record' => sub {
Link Here
|
| 90 |
my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); |
127 |
my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); |
| 91 |
is( @subfields_biblionumber, 1, 'The record should contain the field which are mapped to biblio.biblionumber' ); |
128 |
is( @subfields_biblionumber, 1, 'The record should contain the field which are mapped to biblio.biblionumber' ); |
| 92 |
}; |
129 |
}; |
| 93 |
- |
130 |
|
|
|
131 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
| 132 |
$schema->storage->txn_rollback; |