|
Lines 10-15
use t::lib::Mocks;
Link Here
|
| 10 |
use t::lib::TestBuilder; |
10 |
use t::lib::TestBuilder; |
| 11 |
|
11 |
|
| 12 |
use Koha::Database; |
12 |
use Koha::Database; |
|
|
13 |
use Koha::Import::Records; |
| 13 |
|
14 |
|
| 14 |
BEGIN { |
15 |
BEGIN { |
| 15 |
# Mock pluginsdir before loading Plugins module |
16 |
# Mock pluginsdir before loading Plugins module |
|
Lines 17-23
BEGIN {
Link Here
|
| 17 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
18 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 18 |
|
19 |
|
| 19 |
use_ok('Koha::Plugins'); |
20 |
use_ok('Koha::Plugins'); |
| 20 |
use_ok('C4::ImportBatch', qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio GetRecordFromImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin )); |
21 |
use_ok('C4::ImportBatch', qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin )); |
| 21 |
} |
22 |
} |
| 22 |
|
23 |
|
| 23 |
# Start transaction |
24 |
# Start transaction |
|
Lines 93-139
my $original_record = MARC::Record->new;
Link Here
|
| 93 |
$record->leader('03174nam a2200445 a 4500'); |
94 |
$record->leader('03174nam a2200445 a 4500'); |
| 94 |
$original_record->leader('03174nam a2200445 a 4500'); |
95 |
$original_record->leader('03174nam a2200445 a 4500'); |
| 95 |
my ($item_tag, $item_subfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); |
96 |
my ($item_tag, $item_subfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); |
| 96 |
my @fields = ( |
97 |
my @fields; |
| 97 |
MARC::Field->new( |
98 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
| 98 |
100, '1', ' ', |
99 |
@fields = ( |
| 99 |
a => 'Knuth, Donald Ervin', |
100 |
MARC::Field->new( |
| 100 |
d => '1938', |
101 |
100, ' ', ' ', |
| 101 |
), |
102 |
a => '20220520d u||y0frey50 ba', |
| 102 |
MARC::Field->new( |
103 |
), |
| 103 |
245, '1', '4', |
104 |
MARC::Field->new( |
| 104 |
a => 'The art of computer programming', |
105 |
700, ' ', ' ', |
| 105 |
c => 'Donald E. Knuth.', |
106 |
a => 'Knuth, Donald Ervin', |
| 106 |
), |
107 |
f => '1938', |
| 107 |
MARC::Field->new( |
108 |
), |
| 108 |
650, ' ', '0', |
109 |
MARC::Field->new( |
| 109 |
a => 'Computer programming.', |
110 |
200, ' ', ' ', |
| 110 |
9 => '462', |
111 |
a => 'The art of computer programming', |
| 111 |
), |
112 |
f => 'Donald E. Knuth.', |
| 112 |
MARC::Field->new( |
113 |
), |
| 113 |
$item_tag, ' ', ' ', |
114 |
MARC::Field->new( |
| 114 |
e => 'my edition ❤', |
115 |
650, ' ', '0', |
| 115 |
i => 'my item part', |
116 |
a => 'Computer programming.', |
| 116 |
), |
117 |
9 => '462', |
| 117 |
MARC::Field->new( |
118 |
), |
| 118 |
$item_tag, ' ', ' ', |
119 |
MARC::Field->new( |
| 119 |
e => 'my edition 2', |
120 |
$item_tag, ' ', ' ', |
| 120 |
i => 'my item part 2', |
121 |
e => 'my edition ❤', |
| 121 |
), |
122 |
i => 'my item part', |
| 122 |
); |
123 |
), |
|
|
124 |
MARC::Field->new( |
| 125 |
$item_tag, ' ', ' ', |
| 126 |
e => 'my edition 2', |
| 127 |
i => 'my item part 2', |
| 128 |
), |
| 129 |
); |
| 130 |
} else { |
| 131 |
@fields = ( |
| 132 |
MARC::Field->new( |
| 133 |
100, '1', ' ', |
| 134 |
a => 'Knuth, Donald Ervin', |
| 135 |
d => '1938', |
| 136 |
), |
| 137 |
MARC::Field->new( |
| 138 |
245, '1', '4', |
| 139 |
a => 'The art of computer programming', |
| 140 |
c => 'Donald E. Knuth.', |
| 141 |
), |
| 142 |
MARC::Field->new( |
| 143 |
650, ' ', '0', |
| 144 |
a => 'Computer programming.', |
| 145 |
9 => '462', |
| 146 |
), |
| 147 |
MARC::Field->new( |
| 148 |
$item_tag, ' ', ' ', |
| 149 |
e => 'my edition ❤', |
| 150 |
i => 'my item part', |
| 151 |
), |
| 152 |
MARC::Field->new( |
| 153 |
$item_tag, ' ', ' ', |
| 154 |
e => 'my edition 2', |
| 155 |
i => 'my item part 2', |
| 156 |
), |
| 157 |
); |
| 158 |
} |
| 123 |
$record->append_fields(@fields); |
159 |
$record->append_fields(@fields); |
| 124 |
$original_record->append_fields(@fields); |
160 |
$original_record->append_fields(@fields); |
| 125 |
my $import_record_id = AddBiblioToBatch( $id_import_batch1, 0, $record, 'utf8', int(rand(99999)), 0 ); |
161 |
my $import_record_id = AddBiblioToBatch( $id_import_batch1, 0, $record, 'utf8', int(rand(99999)), 0 ); |
| 126 |
AddItemsToImportBiblio( $id_import_batch1, $import_record_id, $record, 0 ); |
162 |
AddItemsToImportBiblio( $id_import_batch1, $import_record_id, $record, 0 ); |
| 127 |
|
163 |
|
| 128 |
my $record_from_import_biblio_with_items = C4::ImportBatch::GetRecordFromImportBiblio( $import_record_id, 'embed_items' ); |
164 |
my $import_record = Koha::Import::Records->find($import_record_id); |
|
|
165 |
my $record_from_import_biblio_with_items = $import_record->get_marc_record({ embed_items => 1 }); |
| 129 |
$original_record->leader($record_from_import_biblio_with_items->leader()); |
166 |
$original_record->leader($record_from_import_biblio_with_items->leader()); |
| 130 |
is_deeply( $record_from_import_biblio_with_items, $original_record, 'GetRecordFromImportBiblio should return the record with items if specified' ); |
167 |
is_deeply( $record_from_import_biblio_with_items, $original_record, 'Koha::Import::Record::get_marc_record should return the record with items if specified' ); |
| 131 |
my $utf8_field = $record_from_import_biblio_with_items->subfield($item_tag, 'e'); |
168 |
my $utf8_field = $record_from_import_biblio_with_items->subfield($item_tag, 'e'); |
| 132 |
is($utf8_field, 'my edition ❤'); |
169 |
is($utf8_field, 'my edition ❤'); |
| 133 |
$original_record->delete_fields($original_record->field($item_tag)); #Remove items fields |
170 |
$original_record->delete_fields($original_record->field($item_tag)); #Remove items fields |
| 134 |
my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImportBiblio( $import_record_id ); |
171 |
my $record_from_import_biblio_without_items = $import_record->get_marc_record(); |
| 135 |
$original_record->leader($record_from_import_biblio_without_items->leader()); |
172 |
$original_record->leader($record_from_import_biblio_without_items->leader()); |
| 136 |
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' ); |
173 |
is_deeply( $record_from_import_biblio_without_items, $original_record, 'Koha::Import::Record::get_marc_record should return the record without items by default' ); |
| 137 |
|
174 |
|
| 138 |
my $another_biblio = $builder->build_sample_biblio; |
175 |
my $another_biblio = $builder->build_sample_biblio; |
| 139 |
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber ); |
176 |
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber ); |
|
Lines 175-181
my $id_import_batch3 = C4::ImportBatch::AddImportBatch($sample_import_batch3);
Link Here
|
| 175 |
|
212 |
|
| 176 |
# Test CleanBatch |
213 |
# Test CleanBatch |
| 177 |
C4::ImportBatch::CleanBatch( $id_import_batch3 ); |
214 |
C4::ImportBatch::CleanBatch( $id_import_batch3 ); |
| 178 |
my $import_record = get_import_record( $id_import_batch3 ); |
215 |
$import_record = get_import_record( $id_import_batch3 ); |
| 179 |
is( $import_record, "0E0", "Batch 3 has been cleaned" ); |
216 |
is( $import_record, "0E0", "Batch 3 has been cleaned" ); |
| 180 |
|
217 |
|
| 181 |
# Test DeleteBatch |
218 |
# Test DeleteBatch |
|
Lines 221-227
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 221 |
|
258 |
|
| 222 |
# Create a test file |
259 |
# Create a test file |
| 223 |
my ( $fh, $name ) = tempfile(); |
260 |
my ( $fh, $name ) = tempfile(); |
| 224 |
print $fh q| |
261 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
|
|
262 |
print $fh q{ |
| 263 |
003 = NLAmRIJ |
| 264 |
100,a = 20220520d u||y0frey50 ba |
| 265 |
700,a = Author |
| 266 |
200,ind2 = 0 |
| 267 |
200,a = Silence in the library |
| 268 |
500 , a= Some note |
| 269 |
|
| 270 |
700,a = Another |
| 271 |
245,a = Noise in the library}; |
| 272 |
close $fh; |
| 273 |
} else { |
| 274 |
print $fh q| |
| 225 |
003 = NLAmRIJ |
275 |
003 = NLAmRIJ |
| 226 |
100,a = Author |
276 |
100,a = Author |
| 227 |
245,ind2 = 0 |
277 |
245,ind2 = 0 |
|
Lines 230-236
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 230 |
|
280 |
|
| 231 |
100,a = Another |
281 |
100,a = Another |
| 232 |
245,a = Noise in the library|; |
282 |
245,a = Noise in the library|; |
| 233 |
close $fh; |
283 |
close $fh; |
|
|
284 |
} |
| 234 |
|
285 |
|
| 235 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
286 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 236 |
|
287 |
|
|
Lines 241-250
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 241 |
my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); |
292 |
my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); |
| 242 |
is( @$records, 2, 'Two results returned' ); |
293 |
is( @$records, 2, 'Two results returned' ); |
| 243 |
is( ref $records->[0], 'MARC::Record', 'Returned MARC::Record object' ); |
294 |
is( ref $records->[0], 'MARC::Record', 'Returned MARC::Record object' ); |
| 244 |
is( $records->[0]->subfield('245', 'a'), 'Silence in the library', |
295 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
| 245 |
'Checked one field in first record' ); |
296 |
is( $records->[0]->subfield('200', 'a'), 'Silence in the library', |
| 246 |
is( $records->[1]->subfield('100', 'a'), 'Another', |
297 |
'Checked one field in first record' ); |
| 247 |
'Checked one field in second record' ); |
298 |
is( $records->[1]->subfield('700', 'a'), 'Another', |
|
|
299 |
'Checked one field in second record' ); |
| 300 |
} else { |
| 301 |
is( $records->[0]->subfield('245', 'a'), 'Silence in the library', |
| 302 |
'Checked one field in first record' ); |
| 303 |
is( $records->[1]->subfield('100', 'a'), 'Another', |
| 304 |
'Checked one field in second record' ); |
| 305 |
} |
| 248 |
}; |
306 |
}; |
| 249 |
|
307 |
|
| 250 |
subtest "_get_commit_action" => sub { |
308 |
subtest "_get_commit_action" => sub { |