Bug 28220: Add test for updating an existing patron
Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
7624ab0a96
commit
e755139334
1 changed files with 79 additions and 1 deletions
|
@ -845,7 +845,7 @@ subtest 'test_format_dates' => sub {
|
|||
|
||||
subtest 'patron_attributes' => sub {
|
||||
|
||||
plan tests => 16;
|
||||
plan tests => 17;
|
||||
|
||||
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1);
|
||||
|
||||
|
@ -968,6 +968,84 @@ subtest 'patron_attributes' => sub {
|
|||
is( $patron, undef );
|
||||
}
|
||||
|
||||
subtest 'update existing patron' => sub {
|
||||
plan tests => 6;
|
||||
|
||||
my $patron = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { cardnumber => $cardnumber }
|
||||
}
|
||||
);
|
||||
|
||||
my $attributes = {
|
||||
$unique_attribute_type->code => ['my unique attribute 1'],
|
||||
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ],
|
||||
$normal_attribute_type->code => ['my normal attribute 1'],
|
||||
};
|
||||
my $fh = build_csv({ %$attributes });
|
||||
my $result = $patrons_import->import_patrons(
|
||||
{
|
||||
file => $fh,
|
||||
matchpoint => 'cardnumber',
|
||||
overwrite_cardnumber => 1,
|
||||
preserve_extended_attributes => 1
|
||||
}
|
||||
);
|
||||
|
||||
is( $result->{overwritten}, 1 );
|
||||
|
||||
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } );
|
||||
|
||||
# Adding a new non-repeatable attribute
|
||||
my $new_attributes = {
|
||||
$normal_attribute_type->code => ['my normal attribute 2'],
|
||||
};
|
||||
$fh = build_csv({ %$new_attributes });
|
||||
$result = $patrons_import->import_patrons(
|
||||
{
|
||||
file => $fh,
|
||||
matchpoint => 'cardnumber',
|
||||
overwrite_cardnumber => 1,
|
||||
preserve_extended_attributes => 1
|
||||
}
|
||||
);
|
||||
|
||||
is( $result->{overwritten}, 1 );
|
||||
|
||||
# The normal_attribute_type has been replaced with 'my normal attribute 2'
|
||||
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } );
|
||||
|
||||
|
||||
# uniqueness
|
||||
$patron->extended_attributes->delete; # reset
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patron::Attributes',
|
||||
value => { code => $unique_attribute_type->code, attribute => 'unique' }
|
||||
}
|
||||
);
|
||||
$attributes = {
|
||||
$unique_attribute_type->code => ['unique'],
|
||||
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ],
|
||||
$normal_attribute_type->code => ['my normal attribute 1'],
|
||||
};
|
||||
$fh = build_csv({ %$attributes });
|
||||
$result = $patrons_import->import_patrons(
|
||||
{
|
||||
file => $fh,
|
||||
matchpoint => 'cardnumber',
|
||||
overwrite_cardnumber => 1,
|
||||
preserve_extended_attributes => 1
|
||||
}
|
||||
);
|
||||
|
||||
is( $result->{overwritten}, 0 );
|
||||
|
||||
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } );
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
# got is { code => $code, attribute => $attribute }
|
||||
|
|
Loading…
Reference in a new issue