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 => 160; |
21 |
use Test::More tests => 172; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use Encode qw( encode_utf8 ); |
23 |
use Encode qw( encode_utf8 ); |
24 |
use utf8; |
24 |
use utf8; |
Lines 92-97
my $csv_headers = 'cardnumber,surname,firstname,title,othernames,initials,stree
Link Here
|
92 |
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'; |
92 |
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'; |
93 |
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'; |
93 |
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'; |
94 |
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'; |
94 |
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'; |
|
|
95 |
my $csv_one_line_b = '1000,Nancy2,Jenkins2,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'; |
95 |
|
96 |
|
96 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
97 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
97 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
98 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
Lines 183-188
is($result_3a->{imported}, 0, 'Got the expected 0 imported result from import_pa
Link Here
|
183 |
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
184 |
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
184 |
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); |
185 |
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); |
185 |
|
186 |
|
|
|
187 |
# Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from |
188 |
# overwrite but firstname is not |
189 |
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b); |
190 |
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!"; |
191 |
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ] }; |
192 |
|
193 |
# When ... |
194 |
my $result_3c; |
195 |
warning_is { $result_3c = $patrons_import->import_patrons($params_3c) } |
196 |
undef, |
197 |
"No warning raised by import_patrons"; |
198 |
|
199 |
# Then ... |
200 |
is($result_3c->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons when matched and overwrite set'); |
201 |
is($result_3c->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
202 |
is($result_3c->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
203 |
|
204 |
is($result_3c->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched and overwritten'); |
205 |
is($result_3c->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
206 |
is($result_3c->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
207 |
|
208 |
is($result_3c->{imported}, 0, 'Got the expected 0 imported result from import_patrons'); |
209 |
is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
210 |
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); |
211 |
|
212 |
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' }); |
213 |
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" ); |
214 |
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" ); |
215 |
|
186 |
# Given ... valid file handle, good matchpoint that does not match and conflicting userid. |
216 |
# Given ... valid file handle, good matchpoint that does not match and conflicting userid. |
187 |
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a); |
217 |
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a); |
188 |
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!"; |
218 |
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!"; |