7 use Test
::More tests
=> 9;
10 use_ok
('C4::ImportBatch');
14 my $dbh = C4
::Context
->dbh;
15 $dbh->{AutoCommit
} = 0;
16 $dbh->{RaiseError
} = 1;
19 $dbh->do('DELETE FROM import_batches');
21 my $sample_import_batch1 = {
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',
32 record_type
=> 'auth',
35 my $sample_import_batch2 = {
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',
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" );
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','');
84 a
=> 'Knuth, Donald Ervin',
89 a
=> 'The art of computer programming',
90 c
=> 'Donald E. Knuth.',
94 a
=> 'Computer programming.',
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' );
122 my $sample_import_batch3 = {
126 overlay_action
=> 'create_new',
127 nomatch_action
=> 'create_new',
128 item_action
=> 'always_add',
129 import_status
=> 'staged',
130 batch_type
=> 'z3950',
131 file_name
=> 'test.mrc',
133 record_type
=> 'auth',
136 my $id_import_batch3 = C4
::ImportBatch
::AddImportBatch
($sample_import_batch3);
139 C4
::ImportBatch
::CleanBatch
( $id_import_batch3 );
140 my $batch3_clean = $dbh->do('SELECT * FROM import_records WHERE import_batch_id = "$id_import_batch3"');
141 is
( $batch3_clean, "0E0", "Batch 3 has been cleaned" );
144 C4
::ImportBatch
::DeleteBatch
( $id_import_batch3 );
145 my $batch3_results = $dbh->do('SELECT * FROM import_batches WHERE import_batch_id = "$id_import_batch3"');
146 is
( $batch3_results, "0E0", "Batch 3 has been deleted");