|
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 188-194
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 188 |
|
225 |
|
| 189 |
# Create a test file |
226 |
# Create a test file |
| 190 |
my ( $fh, $name ) = tempfile(); |
227 |
my ( $fh, $name ) = tempfile(); |
| 191 |
print $fh q| |
228 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
|
|
229 |
print $fh q{ |
| 230 |
003 = NLAmRIJ |
| 231 |
100,a = 20220520d u||y0frey50 ba |
| 232 |
700,a = Author |
| 233 |
200,ind2 = 0 |
| 234 |
200,a = Silence in the library |
| 235 |
500 , a= Some note |
| 236 |
|
| 237 |
700,a = Another |
| 238 |
245,a = Noise in the library}; |
| 239 |
close $fh; |
| 240 |
} else { |
| 241 |
print $fh q| |
| 192 |
003 = NLAmRIJ |
242 |
003 = NLAmRIJ |
| 193 |
100,a = Author |
243 |
100,a = Author |
| 194 |
245,ind2 = 0 |
244 |
245,ind2 = 0 |
|
Lines 197-203
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 197 |
|
247 |
|
| 198 |
100,a = Another |
248 |
100,a = Another |
| 199 |
245,a = Noise in the library|; |
249 |
245,a = Noise in the library|; |
| 200 |
close $fh; |
250 |
close $fh; |
|
|
251 |
} |
| 201 |
|
252 |
|
| 202 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
253 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 203 |
|
254 |
|
|
Lines 208-217
subtest "RecordsFromMarcPlugin" => sub {
Link Here
|
| 208 |
my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); |
259 |
my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); |
| 209 |
is( @$records, 2, 'Two results returned' ); |
260 |
is( @$records, 2, 'Two results returned' ); |
| 210 |
is( ref $records->[0], 'MARC::Record', 'Returned MARC::Record object' ); |
261 |
is( ref $records->[0], 'MARC::Record', 'Returned MARC::Record object' ); |
| 211 |
is( $records->[0]->subfield('245', 'a'), 'Silence in the library', |
262 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
| 212 |
'Checked one field in first record' ); |
263 |
is( $records->[0]->subfield('200', 'a'), 'Silence in the library', |
| 213 |
is( $records->[1]->subfield('100', 'a'), 'Another', |
264 |
'Checked one field in first record' ); |
| 214 |
'Checked one field in second record' ); |
265 |
is( $records->[1]->subfield('700', 'a'), 'Another', |
|
|
266 |
'Checked one field in second record' ); |
| 267 |
} else { |
| 268 |
is( $records->[0]->subfield('245', 'a'), 'Silence in the library', |
| 269 |
'Checked one field in first record' ); |
| 270 |
is( $records->[1]->subfield('100', 'a'), 'Another', |
| 271 |
'Checked one field in second record' ); |
| 272 |
} |
| 215 |
}; |
273 |
}; |
| 216 |
|
274 |
|
| 217 |
subtest "_get_commit_action" => sub { |
275 |
subtest "_get_commit_action" => sub { |