Bug 23873: Unit tests

This patch adds a unit test for capture groups support in
Koha::SimpleMARC.

Test plan
1) Run the test prior to applying the capture groups fix, note it fails.
2) Apply teh capture groups fix patch
3) Run the test again, it should now pass

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2021-12-13 10:20:54 +00:00 committed by Fridolin Somers
parent dfa2f4b436
commit 502a2b5483
1 changed files with 45 additions and 2 deletions

View File

@ -326,7 +326,7 @@ subtest 'update_field' => sub {
subtest 'copy_field' => sub {
plan tests => 2;
subtest 'copy subfield' => sub {
plan tests => 20;
plan tests => 21;
my $record = new_record;
$record->append_fields(
MARC::Field->new(
@ -672,6 +672,27 @@ subtest 'copy_field' => sub {
'Update a subfield: add a string at the end'
);
$record = new_record;
copy_field(
{
record => $record,
from_field => 245,
from_subfield => 'a',
to_field => 245,
to_subfield => 'a',
regex => { search => '(art)', replace => 'sm$1 $1' }
}
);
is_deeply(
[
read_field(
{ record => $record, field => '245', subfield => 'a' }
)
],
['The art of computer programming', 'The smart art of computer programming'],
'Update a subfield: use capture groups'
);
$record = new_record;
copy_field(
{
@ -900,7 +921,7 @@ subtest 'copy_field' => sub {
subtest 'copy_and_replace_field' => sub {
plan tests => 2;
subtest 'copy and replace subfield' => sub {
plan tests => 19;
plan tests => 20;
my $record = new_record;
$record->append_fields(
MARC::Field->new(
@ -1246,6 +1267,28 @@ subtest 'copy_and_replace_field' => sub {
'Copy and replace - Update a subfield: add a string at the end'
);
$record = new_record;
copy_and_replace_field(
{
record => $record,
from_field => 245,
from_subfield => 'a',
to_field => 245,
to_subfield => 'a',
regex => { search => '(art)', replace => 'sm$1 $1' }
}
);
# This is the same as update the subfield
is_deeply(
[
read_field(
{ record => $record, field => '245', subfield => 'a' }
)
],
['The smart art of computer programming'],
'Copy and replace - Update a subfield: use capture groups'
);
$record = new_record;
copy_and_replace_field(
{