Lines 845-851
subtest 'test_format_dates' => sub {
Link Here
|
845 |
|
845 |
|
846 |
subtest 'patron_attributes' => sub { |
846 |
subtest 'patron_attributes' => sub { |
847 |
|
847 |
|
848 |
plan tests => 16; |
848 |
plan tests => 17; |
849 |
|
849 |
|
850 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
850 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
851 |
|
851 |
|
Lines 968-973
subtest 'patron_attributes' => sub {
Link Here
|
968 |
is( $patron, undef ); |
968 |
is( $patron, undef ); |
969 |
} |
969 |
} |
970 |
|
970 |
|
|
|
971 |
subtest 'update existing patron' => sub { |
972 |
plan tests => 6; |
973 |
|
974 |
my $patron = $builder->build_object( |
975 |
{ |
976 |
class => 'Koha::Patrons', |
977 |
value => { cardnumber => $cardnumber } |
978 |
} |
979 |
); |
980 |
|
981 |
my $attributes = { |
982 |
$unique_attribute_type->code => ['my unique attribute 1'], |
983 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
984 |
$normal_attribute_type->code => ['my normal attribute 1'], |
985 |
}; |
986 |
my $fh = build_csv({ %$attributes }); |
987 |
my $result = $patrons_import->import_patrons( |
988 |
{ |
989 |
file => $fh, |
990 |
matchpoint => 'cardnumber', |
991 |
overwrite_cardnumber => 1, |
992 |
preserve_extended_attributes => 1 |
993 |
} |
994 |
); |
995 |
|
996 |
is( $result->{overwritten}, 1 ); |
997 |
|
998 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
999 |
|
1000 |
# Adding a new non-repeatable attribute |
1001 |
my $new_attributes = { |
1002 |
$normal_attribute_type->code => ['my normal attribute 2'], |
1003 |
}; |
1004 |
$fh = build_csv({ %$new_attributes }); |
1005 |
$result = $patrons_import->import_patrons( |
1006 |
{ |
1007 |
file => $fh, |
1008 |
matchpoint => 'cardnumber', |
1009 |
overwrite_cardnumber => 1, |
1010 |
preserve_extended_attributes => 1 |
1011 |
} |
1012 |
); |
1013 |
|
1014 |
is( $result->{overwritten}, 1 ); |
1015 |
|
1016 |
# The normal_attribute_type has been replaced with 'my normal attribute 2' |
1017 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } ); |
1018 |
|
1019 |
|
1020 |
# uniqueness |
1021 |
$patron->extended_attributes->delete; # reset |
1022 |
$builder->build_object( |
1023 |
{ |
1024 |
class => 'Koha::Patron::Attributes', |
1025 |
value => { code => $unique_attribute_type->code, attribute => 'unique' } |
1026 |
} |
1027 |
); |
1028 |
$attributes = { |
1029 |
$unique_attribute_type->code => ['unique'], |
1030 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1031 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1032 |
}; |
1033 |
$fh = build_csv({ %$attributes }); |
1034 |
$result = $patrons_import->import_patrons( |
1035 |
{ |
1036 |
file => $fh, |
1037 |
matchpoint => 'cardnumber', |
1038 |
overwrite_cardnumber => 1, |
1039 |
preserve_extended_attributes => 1 |
1040 |
} |
1041 |
); |
1042 |
|
1043 |
is( $result->{overwritten}, 0 ); |
1044 |
|
1045 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
1046 |
|
1047 |
}; |
1048 |
|
971 |
}; |
1049 |
}; |
972 |
|
1050 |
|
973 |
# got is { code => $code, attribute => $attribute } |
1051 |
# got is { code => $code, attribute => $attribute } |
974 |
- |
|
|