Bug 14778: Make 3 tests pass
[koha.git] / t / db_dependent / ImportBatch.t
blob661cd339d1ad9b79cba8c3611aa8e22880a11e5e
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use C4::Context;
7 use Test::More tests => 7;
9 BEGIN {
10 use_ok('C4::ImportBatch');
13 # Start transaction
14 my $dbh = C4::Context->dbh;
15 $dbh->{AutoCommit} = 0;
16 $dbh->{RaiseError} = 1;
18 # clear
19 $dbh->do('DELETE FROM import_batches');
21 my $sample_import_batch1 = {
22 matcher_id => 1,
23 template_id => 1,
24 branchcode => 'QRT',
25 overlay_action => 'create_new',
26 nomatch_action => 'create_new',
27 item_action => 'always_add',
28 import_status => 'staged',
29 batch_type => 'z3950',
30 file_name => 'test.mrc',
31 comments => 'test',
32 record_type => 'auth',
35 my $sample_import_batch2 = {
36 matcher_id => 2,
37 template_id => 2,
38 branchcode => 'QRZ',
39 overlay_action => 'create_new',
40 nomatch_action => 'create_new',
41 item_action => 'always_add',
42 import_status => 'staged',
43 batch_type => 'z3950',
44 file_name => 'test.mrc',
45 comments => 'test',
46 record_type => 'auth',
49 my $id_import_batch1 = C4::ImportBatch::AddImportBatch($sample_import_batch1);
50 my $id_import_batch2 = C4::ImportBatch::AddImportBatch($sample_import_batch2);
52 like( $id_import_batch1, '/^\d+$/', "AddImportBatch for sample_import_batch1 return an id" );
53 like( $id_import_batch2, '/^\d+$/', "AddImportBatch for sample_import_batch2 return an id" );
55 #Test GetImportBatch
56 my $importbatch2 = C4::ImportBatch::GetImportBatch( $id_import_batch2 );
57 delete $importbatch2->{upload_timestamp};
58 delete $importbatch2->{import_batch_id};
59 delete $importbatch2->{num_records};
60 delete $importbatch2->{num_items};
62 is_deeply( $importbatch2, $sample_import_batch2,
63 "GetImportBatch returns the right informations about $sample_import_batch2" );
65 my $importbatch1 = C4::ImportBatch::GetImportBatch( $id_import_batch1 );
66 delete $importbatch1->{upload_timestamp};
67 delete $importbatch1->{import_batch_id};
68 delete $importbatch1->{num_records};
69 delete $importbatch1->{num_items};
71 is_deeply( $importbatch1, $sample_import_batch1,
72 "GetImportBatch returns the right informations about $sample_import_batch1" );
74 my $record = MARC::Record->new;
75 # FIXME Create another MARC::Record which won't be modified
76 # AddItemsToImportBiblio will remove the items field from the record passed in parameter.
77 my $original_record = MARC::Record->new;
78 $record->leader('03174nam a2200445 a 4500');
79 $original_record->leader('03174nam a2200445 a 4500');
80 my ($item_tag, $item_subfield) = C4::Biblio::GetMarcFromKohaField('items.itemnumber','');
81 my @fields = (
82 MARC::Field->new(
83 100, '1', ' ',
84 a => 'Knuth, Donald Ervin',
85 d => '1938',
87 MARC::Field->new(
88 245, '1', '4',
89 a => 'The art of computer programming',
90 c => 'Donald E. Knuth.',
92 MARC::Field->new(
93 650, ' ', '0',
94 a => 'Computer programming.',
95 9 => '462',
97 MARC::Field->new(
98 $item_tag, ' ', ' ',
99 e => 'my edition',
100 i => 'my item part',
102 MARC::Field->new(
103 $item_tag, ' ', ' ',
104 e => 'my edition 2',
105 i => 'my item part 2',
108 $record->append_fields(@fields);
109 $original_record->append_fields(@fields);
110 my $import_record_id = AddBiblioToBatch( $id_import_batch1, 0, $record, 'utf8', int(rand(99999)), 0 );
111 AddItemsToImportBiblio( $id_import_batch1, $import_record_id, $record, 0 );
113 my $record_from_import_biblio_with_items = C4::ImportBatch::GetRecordFromImportBiblio( $import_record_id, 'embed_items' );
114 $original_record->leader($record_from_import_biblio_with_items->leader());
115 is_deeply( $record_from_import_biblio_with_items, $original_record, 'GetRecordFromImportBiblio should return the record with items if specified' );
116 $original_record->delete_fields($original_record->field($item_tag)); #Remove items fields
117 my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImportBiblio( $import_record_id );
118 $original_record->leader($record_from_import_biblio_without_items->leader());
119 is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' );