View | Details | Raw Unified | Return to bug 21465
Collapse All | Expand All

(-)a/Koha/Patrons/Import.pm (-1 / +1 lines)
Lines 206-212 sub import_patrons { Link Here
206
            and $matchpoint ne 'userid'
206
            and $matchpoint ne 'userid'
207
            and exists $borrower{userid}
207
            and exists $borrower{userid}
208
            and $borrower{userid}
208
            and $borrower{userid}
209
            and not Koha::Patron->new( { userid => $borrower{userid} } )->has_valid_userid
209
            and not ( $borrowernumber ? $patron->userid( $borrower{userid} )->has_valid_userid : Koha::Patron->new( { userid => $borrower{userid} } )->has_valid_userid )
210
        ) {
210
        ) {
211
            push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
211
            push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
212
            $invalid++;
212
            $invalid++;
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +2 lines)
Lines 1311-1317 subtest 'get_overdues' => sub { Link Here
1311
};
1311
};
1312
1312
1313
subtest 'userid_is_valid' => sub {
1313
subtest 'userid_is_valid' => sub {
1314
    plan tests => 8;
1314
    plan tests => 9;
1315
1315
1316
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1316
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1317
    my $patron_category = $builder->build_object(
1317
    my $patron_category = $builder->build_object(
Lines 1331-1336 subtest 'userid_is_valid' => sub { Link Here
1331
    my $expected_userid_patron_1 = 'tomasito.none';
1331
    my $expected_userid_patron_1 = 'tomasito.none';
1332
    my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber;
1332
    my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber;
1333
    my $patron_1       = Koha::Patrons->find($borrowernumber);
1333
    my $patron_1       = Koha::Patrons->find($borrowernumber);
1334
    is( $patron_1->has_valid_userid, 1, "Should be valid when compared against them self" );
1334
    is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' );
1335
    is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' );
1335
1336
1336
    $patron_1->userid( 'tomasito.non' );
1337
    $patron_1->userid( 'tomasito.non' );
(-)a/t/db_dependent/Koha/Patrons/Import.t (-10 / +52 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 124;
21
use Test::More tests => 142;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
# To be replaced by t::lib::Mock
24
# To be replaced by t::lib::Mock
Lines 89-94 t::lib::Mocks::mock_preference('dateformat', 'us'); Link Here
89
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
89
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
90
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
90
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
91
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
91
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
92
my $csv_one_line_a = '1001,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
92
93
93
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line);
94
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line);
94
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!";
95
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!";
Lines 135-141 is($result_2->{imported}, 0, 'Got the expected 0 imported result from import_pat Link Here
135
is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number');
136
is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number');
136
is($result_2->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with invalid card number');
137
is($result_2->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with invalid card number');
137
138
138
# Given ... valid file handle, good matchpoint but same input as prior test.
139
# Given ... valid file handle, good matchpoint that matches should not overwrite when not set.
139
my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_one_line);
140
my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_one_line);
140
open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!";
141
open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!";
141
my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', };
142
my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', };
Lines 144-160 my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', }; Link Here
144
my $result_3 = $patrons_import->import_patrons($params_3);
145
my $result_3 = $patrons_import->import_patrons($params_3);
145
146
146
# Then ...
147
# Then ...
147
is($result_3->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with duplicate userid');
148
is($result_3->{already_in_db}, 1, 'Got the expected 1 already_in_db from import_patrons with duplicate userid');
148
is($result_3->{errors}->[0]->{duplicate_userid}, 1, 'Got the expected duplicate userid error from import patrons with duplicate userid');
149
is($result_3->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)');
149
is($result_3->{errors}->[0]->{userid}, 'jjenkins0', 'Got the expected userid error from import patrons with duplicate userid');
150
is($result_3->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)');
150
151
151
is($result_3->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with duplicate userid');
152
is($result_3->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched but not overwritten');
152
is($result_3->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid');
153
is($result_3->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid');
153
is($result_3->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid');
154
is($result_3->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid');
154
155
155
is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid');
156
is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons');
156
is($result_3->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid');
157
is($result_3->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons');
157
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid');
158
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons that matched');
159
160
# Given ... valid file handle, good matchpoint that matches should overwrite when set.
161
my $filename_3a = make_csv($temp_dir, $csv_headers, $csv_one_line);
162
open(my $handle_3a, "<", $filename_3a) or die "cannot open < $filename_3: $!";
163
my $params_3a = { file => $handle_3a, matchpoint => 'cardnumber', overwrite_cardnumber => 1};
164
165
# When ...
166
my $result_3a = $patrons_import->import_patrons($params_3a);
167
168
# Then ...
169
is($result_3a->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons when matched and overwrite set');
170
is($result_3a->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)');
171
is($result_3a->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)');
172
173
is($result_3a->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched and overwritten');
174
is($result_3a->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid');
175
is($result_3a->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid');
176
177
is($result_3a->{imported}, 0, 'Got the expected 0 imported result from import_patrons');
178
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons');
179
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
180
181
# Given ... valid file handle, good matchpoint that does not match and conflicting userid.
182
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a);
183
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";
184
my $params_3b = { file => $handle_3b, matchpoint => 'cardnumber', };
185
186
# When ...
187
my $result_3b = $patrons_import->import_patrons($params_3b);
188
189
# Then ...
190
is($result_3b->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with duplicate userid');
191
is($result_3b->{errors}->[0]->{duplicate_userid}, 1, 'Got the expected duplicate userid error from import patrons with duplicate userid');
192
is($result_3b->{errors}->[0]->{userid}, 'jjenkins0', 'Got the expected userid error from import patrons with duplicate userid');
193
194
is($result_3b->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with duplicate userid');
195
is($result_3b->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid');
196
is($result_3b->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid');
197
198
is($result_3b->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid');
199
is($result_3b->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid');
200
is($result_3b->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid');
158
201
159
# Given ... a new input and mocked C4::Context
202
# Given ... a new input and mocked C4::Context
160
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1);
203
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1);
161
- 

Return to bug 21465