Lines 1-6
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
|
2 |
|
3 |
use Test::More tests => 78; |
3 |
use Test::More tests => 94; |
|
|
4 |
|
5 |
use Koha::SimpleMARC; |
4 |
|
6 |
|
5 |
use_ok("MARC::Field"); |
7 |
use_ok("MARC::Field"); |
6 |
use_ok("MARC::Record"); |
8 |
use_ok("MARC::Record"); |
Lines 151-157
like( $template_id, qr|^\d+$|, "new template returns an id" );
Link Here
|
151 |
|
153 |
|
152 |
is( AddModificationTemplateAction( |
154 |
is( AddModificationTemplateAction( |
153 |
$template_id, 'delete_field', 0, |
155 |
$template_id, 'delete_field', 0, |
154 |
'245', '', '', '', '', '', |
156 |
'245', '', '', '', '', |
155 |
'', '', '', |
157 |
'', '', '', |
156 |
'if', '245', 'a', 'equals', 'Bad title', '', |
158 |
'if', '245', 'a', 'equals', 'Bad title', '', |
157 |
'Delete field 245 if 245$a eq "Bad title"' |
159 |
'Delete field 245 if 245$a eq "Bad title"' |
Lines 183-197
is( AddModificationTemplateAction(
Link Here
|
183 |
|
185 |
|
184 |
is( AddModificationTemplateAction( |
186 |
is( AddModificationTemplateAction( |
185 |
$template_id, 'move_field', 0, |
187 |
$template_id, 'move_field', 0, |
186 |
'952', 'd', '', '952', 'e', '', |
188 |
'952', 'd', '', '952', 'e', |
187 |
'', '', '', |
189 |
'', '', '', |
188 |
'if', '952', 'c', 'equals', '^GEN', '1', |
190 |
'if', '952', 'c', 'equals', '^GEN', '1', |
189 |
'Move field 952$d to 952$e if 952$c =~ /^GE/' |
191 |
'Move field 952$d to 952$e if 952$c =~ /^GEN/' |
190 |
), 1, 'Add fifth action: move field 952$d to 952$e if 952$c =~ /^GE/'); |
192 |
), 1, 'Add fifth action: move field 952$d to 952$e if 952$c =~ /^GEN/'); |
191 |
|
193 |
|
192 |
is( AddModificationTemplateAction( |
194 |
is( AddModificationTemplateAction( |
193 |
$template_id, 'update_field', 0, |
195 |
$template_id, 'update_field', 0, |
194 |
'650', 'a', 'Computer algorithms.', '', '', '', |
196 |
'650', 'a', 'Computer algorithms.', '', '', |
195 |
'', '', '', |
197 |
'', '', '', |
196 |
'if', '650', '9', 'equals', '499', '', |
198 |
'if', '650', '9', 'equals', '499', '', |
197 |
'Update field 650$a with "Computer algorithms." to 651 if 650$9 == 499' |
199 |
'Update field 650$a with "Computer algorithms." to 651 if 650$9 == 499' |
Lines 199-218
is( AddModificationTemplateAction(
Link Here
|
199 |
|
201 |
|
200 |
is( AddModificationTemplateAction( |
202 |
is( AddModificationTemplateAction( |
201 |
$template_id, 'move_field', 0, |
203 |
$template_id, 'move_field', 0, |
202 |
'650', '', '', '651', '', '', |
204 |
'650', '', '', '651', '', |
203 |
'', '', '', |
205 |
'', '', '', |
204 |
'if', '650', '9', 'equals', '499', '', |
206 |
'if', '650', '9', 'equals', '499', '', |
205 |
'Move field 650 to 651 if 650$9 == 499' |
207 |
'Move field 650 to 651 if 650$9 == 499' |
206 |
), 1, 'Add seventh action: move field 650 to 651 if 650$9 == 499'); |
208 |
), 1, 'Add seventh action: move field 650 to 651 if 650$9 == 499'); |
207 |
|
209 |
|
|
|
210 |
is( AddModificationTemplateAction( |
211 |
$template_id, 'update_field', 0, |
212 |
'999', 'a', 'non existent.', '', '', |
213 |
'', '', '', |
214 |
'', '', '', '', '', '', |
215 |
'Update non existent field 999$a with "non existent"' |
216 |
), 1, 'Add eighth action: update field non existent 999$a with "non existent."'); |
208 |
|
217 |
|
209 |
my $record = new_record(); |
218 |
my $record = new_record(); |
210 |
|
219 |
|
211 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
220 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
212 |
|
221 |
|
213 |
my $expected_record = expected_record(); |
222 |
my $expected_record = expected_record_1(); |
214 |
is_deeply( $record, $expected_record, "Record modification as expected"); |
223 |
is_deeply( $record, $expected_record, "Record modification as expected"); |
215 |
|
224 |
|
|
|
225 |
$template_id = AddModificationTemplate("another_template_test"); |
226 |
|
227 |
# Duplicate 245 => 3x245 |
228 |
is( AddModificationTemplateAction( |
229 |
$template_id, 'copy_field', 0, |
230 |
'245', '', '', '245', '', |
231 |
'', '', '', |
232 |
'if', '245', 'a', 'equals', 'Bad title', '', |
233 |
'Copy field 245 if 245$a eq "Bad title"' |
234 |
), 1, 'Add action: copy field 245 if 245$a eq "Bad title"'); |
235 |
|
236 |
$record = new_record(); |
237 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
238 |
|
239 |
my @fields_245a = Koha::SimpleMARC::read_field({ |
240 |
record => $record, |
241 |
field => '245', |
242 |
subfield => 'a', |
243 |
}); |
244 |
is_deeply( \@fields_245a, [ |
245 |
'The art of computer programming', |
246 |
'Bad title', |
247 |
'Bad title', |
248 |
], 'Copy field has copied the "Bad title"' ); |
249 |
|
250 |
# Update first "Bad title" |
251 |
is( AddModificationTemplateAction( |
252 |
$template_id, 'update_field', 1, |
253 |
'245', 'a', 'Bad title updated', '', '', |
254 |
'', '', '', |
255 |
'if', '245', 'a', 'equals', 'Bad title', '', |
256 |
'Update first 245$a matching "Bad title" with "Bad title updated"' |
257 |
), 1, 'Add action: update field 245$a matching "Bad title" with "Bad title updated'); |
258 |
|
259 |
$record = new_record(); |
260 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
261 |
|
262 |
@fields_245a = Koha::SimpleMARC::read_field({ |
263 |
record => $record, |
264 |
field => '245', |
265 |
subfield => 'a', |
266 |
}); |
267 |
is_deeply( \@fields_245a, [ |
268 |
'The art of computer programming', |
269 |
'Bad title updated', |
270 |
'Bad title', |
271 |
], 'update_field has update first the "Bad title"' ); |
272 |
|
273 |
# Duplicate first 245 => 3x245 |
274 |
is( AddModificationTemplateAction( |
275 |
$template_id, 'copy_field', 1, |
276 |
'245', '', '', '245', '', |
277 |
'', '', '', |
278 |
'if', '245', 'a', 'equals', '^Bad title', '1', |
279 |
'Copy field 245 if 245$a =~ "^Bad title"' |
280 |
), 1, 'Add action: copy field 245 if 245$a =~ "^Bad title"'); |
281 |
|
282 |
$record = new_record(); |
283 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
284 |
|
285 |
@fields_245a = Koha::SimpleMARC::read_field({ |
286 |
record => $record, |
287 |
field => '245', |
288 |
subfield => 'a', |
289 |
}); |
290 |
is_deeply( \@fields_245a, [ |
291 |
'The art of computer programming', |
292 |
'Bad title updated', |
293 |
'Bad title', |
294 |
'Bad title updated', |
295 |
], 'Copy field has copied first "^Bad title"' ); |
296 |
|
297 |
# Delete first ^Bad title |
298 |
is( AddModificationTemplateAction( |
299 |
$template_id, 'delete_field', 1, |
300 |
'245', '', '', '', '', |
301 |
'', '', '', |
302 |
'if', '245', 'a', 'equals', '^Bad title', '1', |
303 |
'Delete first 245$a mathing ^Bad title' |
304 |
), 1, 'Delete first 245$a mathing ^Bad title'); |
305 |
|
306 |
$record = new_record(); |
307 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
308 |
@fields_245a = Koha::SimpleMARC::read_field({ |
309 |
record => $record, |
310 |
field => '245', |
311 |
subfield => 'a', |
312 |
}); |
313 |
is_deeply( \@fields_245a, [ |
314 |
'The art of computer programming', |
315 |
'Bad title', |
316 |
'Bad title updated', |
317 |
], 'delete field has been deleted the right field"' ); |
318 |
|
319 |
is( AddModificationTemplateAction( |
320 |
$template_id, 'delete_field', 0, |
321 |
'245', '', '', '', '', |
322 |
'', '', '', |
323 |
'if', '245', 'a', 'equals', 'updated$', '1', |
324 |
'Delete first 245$a mathing updated$' |
325 |
), 1, 'Delete first 245$a mathing updated$'); |
326 |
|
327 |
$record = new_record(); |
328 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
329 |
@fields_245a = Koha::SimpleMARC::read_field({ |
330 |
record => $record, |
331 |
field => '245', |
332 |
subfield => 'a', |
333 |
}); |
334 |
is_deeply( \@fields_245a, [ |
335 |
'The art of computer programming', |
336 |
'Bad title' |
337 |
], 'delete field has been deleted the right field"' ); |
338 |
|
216 |
sub new_record { |
339 |
sub new_record { |
217 |
my $record = MARC::Record->new; |
340 |
my $record = MARC::Record->new; |
218 |
$record->leader('03174nam a2200445 a 4500'); |
341 |
$record->leader('03174nam a2200445 a 4500'); |
Lines 229-235
sub new_record {
Link Here
|
229 |
), |
352 |
), |
230 |
MARC::Field->new( |
353 |
MARC::Field->new( |
231 |
245, '1', '4', |
354 |
245, '1', '4', |
232 |
a => 'field to remove', |
355 |
a => 'Bad title', |
233 |
c => 'Donald E. Knuth.', |
356 |
c => 'Donald E. Knuth.', |
234 |
), |
357 |
), |
235 |
MARC::Field->new( |
358 |
MARC::Field->new( |
Lines 254-260
sub new_record {
Link Here
|
254 |
return $record; |
377 |
return $record; |
255 |
} |
378 |
} |
256 |
|
379 |
|
257 |
sub expected_record { |
380 |
sub expected_record_1 { |
258 |
my $record = MARC::Record->new; |
381 |
my $record = MARC::Record->new; |
259 |
$record->leader('03174nam a2200445 a 4500'); |
382 |
$record->leader('03174nam a2200445 a 4500'); |
260 |
my @fields = ( |
383 |
my @fields = ( |
Lines 288-298
sub expected_record {
Link Here
|
288 |
a => 'Computer algorithms.', |
411 |
a => 'Computer algorithms.', |
289 |
9 => '499', |
412 |
9 => '499', |
290 |
), |
413 |
), |
|
|
414 |
MARC::Field->new( |
415 |
999, ' ', ' ', |
416 |
a => 'non existent.', |
417 |
), |
291 |
); |
418 |
); |
292 |
$record->append_fields(@fields); |
419 |
$record->append_fields(@fields); |
293 |
return $record; |
420 |
return $record; |
294 |
} |
421 |
} |
295 |
|
422 |
|
|
|
423 |
sub expected_record_2 { |
424 |
my $record = MARC::Record->new; |
425 |
$record->leader('03174nam a2200445 a 4500'); |
426 |
my @fields = ( |
427 |
MARC::Field->new( |
428 |
100, '1', ' ', |
429 |
a => 'Knuth, Donald Ervin', |
430 |
d => '1938', |
431 |
), |
432 |
MARC::Field->new( |
433 |
245, '1', '4', |
434 |
a => 'The art of computer programming', |
435 |
c => 'Donald E. Knuth.', |
436 |
), |
437 |
MARC::Field->new( |
438 |
650, ' ', '0', |
439 |
9 => '462', |
440 |
), |
441 |
MARC::Field->new( |
442 |
952, ' ', ' ', |
443 |
p => '3010023917_updated', |
444 |
y => 'BK', |
445 |
c => 'GEN', |
446 |
e => '2001-06-25', |
447 |
), |
448 |
MARC::Field->new( |
449 |
246, '', ' ', |
450 |
a => 'The art of computer programming', |
451 |
), |
452 |
MARC::Field->new( |
453 |
651, ' ', '0', |
454 |
a => 'Computer algorithms.', |
455 |
9 => '499', |
456 |
), |
457 |
MARC::Field->new( |
458 |
999, ' ', ' ', |
459 |
a => 'non existent.', |
460 |
), |
461 |
); |
462 |
$record->append_fields(@fields); |
463 |
return $record; |
464 |
} |
296 |
|
465 |
|
297 |
# C4::Context->userenv |
466 |
# C4::Context->userenv |
298 |
sub Mock_userenv { |
467 |
sub Mock_userenv { |
299 |
- |
|
|