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 => 4; |
848 |
plan tests => 6; |
849 |
|
849 |
|
850 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
850 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
851 |
|
851 |
|
Lines 875-880
subtest 'patron_attributes' => sub {
Link Here
|
875 |
my $non_existent_attribute_type_code = $non_existent_attribute_type->code; |
875 |
my $non_existent_attribute_type_code = $non_existent_attribute_type->code; |
876 |
$non_existent_attribute_type->delete; |
876 |
$non_existent_attribute_type->delete; |
877 |
|
877 |
|
|
|
878 |
our $cardnumber = "1042"; |
879 |
|
878 |
# attributes is { code => \@attributes } |
880 |
# attributes is { code => \@attributes } |
879 |
sub build_csv { |
881 |
sub build_csv { |
880 |
my ($attributes) = @_; |
882 |
my ($attributes) = @_; |
Lines 882-888
subtest 'patron_attributes' => sub {
Link Here
|
882 |
my $csv_headers = 'cardnumber,surname,firstname,branchcode,categorycode,patron_attributes'; |
884 |
my $csv_headers = 'cardnumber,surname,firstname,branchcode,categorycode,patron_attributes'; |
883 |
my @attributes_str = map { my $code = $_; map { sprintf "%s:%s", $code, $_ } @{ $attributes->{$code} } } keys %$attributes; |
885 |
my @attributes_str = map { my $code = $_; map { sprintf "%s:%s", $code, $_ } @{ $attributes->{$code} } } keys %$attributes; |
884 |
my $attributes_str = join ',', @attributes_str; |
886 |
my $attributes_str = join ',', @attributes_str; |
885 |
my $csv_line = sprintf '1042,John,D,MPL,PT,"%s"', $attributes_str; |
887 |
my $csv_line = sprintf '%s,John,D,MPL,PT,"%s"', $cardnumber, $attributes_str; |
886 |
my $filename = make_csv( $temp_dir, $csv_headers, $csv_line ); |
888 |
my $filename = make_csv( $temp_dir, $csv_headers, $csv_line ); |
887 |
open( my $fh, "<:encoding(utf8)", $filename ) or die "cannot open $filename: $!"; |
889 |
open( my $fh, "<:encoding(utf8)", $filename ) or die "cannot open $filename: $!"; |
888 |
return $fh; |
890 |
return $fh; |
Lines 899-905
subtest 'patron_attributes' => sub {
Link Here
|
899 |
|
901 |
|
900 |
is( $result->{imported}, 1 ); |
902 |
is( $result->{imported}, 1 ); |
901 |
|
903 |
|
902 |
my $patron = Koha::Patrons->find({cardnumber => "1042"}); |
904 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
903 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
905 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
904 |
$patron->delete; |
906 |
$patron->delete; |
905 |
} |
907 |
} |
Lines 918-929
subtest 'patron_attributes' => sub {
Link Here
|
918 |
}; |
920 |
}; |
919 |
my $fh = build_csv({ %$attributes }); |
921 |
my $fh = build_csv({ %$attributes }); |
920 |
|
922 |
|
921 |
throws_ok { |
923 |
my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); |
922 |
$patrons_import->import_patrons({file => $fh}); |
924 |
my $error = $result->{errors}->[0]; |
923 |
} |
925 |
is( $error->{patron_attribute_unique_id_constraint}, 1 ); |
924 |
'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint'; |
926 |
is( $error->{patron_id}, $cardnumber ); |
|
|
927 |
is( $error->{attribute}->code, $unique_attribute_type->code ); |
925 |
|
928 |
|
926 |
my $patron = Koha::Patrons->find({cardnumber => "1042"}); |
929 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
927 |
is( $patron, undef ); |
930 |
is( $patron, undef ); |
928 |
|
931 |
|
929 |
} |
932 |
} |
930 |
- |
|
|