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 => 98; |
21 |
use Test::More tests => 122; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
|
23 |
|
24 |
use Koha::Database; |
24 |
use Koha::Database; |
Lines 42-48
subtest 'test_methods' => sub {
Link Here
|
42 |
plan tests => 1; |
42 |
plan tests => 1; |
43 |
|
43 |
|
44 |
# Given ... we can reach the method(s) |
44 |
# Given ... we can reach the method(s) |
45 |
my @methods = ('import_patrons', 'set_column_keys', 'set_patron_attributes', 'check_branch_code'); |
45 |
my @methods = ('import_patrons', |
|
|
46 |
'set_attribute_types', |
47 |
'prepare_columns', |
48 |
'set_column_keys', |
49 |
'set_patron_attributes', |
50 |
'check_branch_code', |
51 |
'format_dates', |
52 |
); |
46 |
can_ok('Koha::Patrons::Import', @methods); |
53 |
can_ok('Koha::Patrons::Import', @methods); |
47 |
}; |
54 |
}; |
48 |
|
55 |
|
Lines 66-73
my $result_0 = $patrons_import->import_patrons($params_0);
Link Here
|
66 |
is($result_0, undef, 'Got the expected undef from import_patrons with no file handle'); |
73 |
is($result_0, undef, 'Got the expected undef from import_patrons with no file handle'); |
67 |
|
74 |
|
68 |
# Given ... a file handle to file with headers only. |
75 |
# Given ... a file handle to file with headers only. |
69 |
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'; |
76 |
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'; |
70 |
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,16/10/1965,CPL,PT,28/12/2014,01/07/2015,jjenkins0,DPQILy'; |
77 |
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'; |
|
|
78 |
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'; |
71 |
|
79 |
|
72 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
80 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
73 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
81 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
Lines 82-89
is(scalar @{$result_1->{errors}}, 0, 'Got the expected 0 size error array from i
Link Here
|
82 |
|
90 |
|
83 |
is($result_1->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with no matchpoint defined'); |
91 |
is($result_1->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with no matchpoint defined'); |
84 |
is($result_1->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with no matchpoint defined'); |
92 |
is($result_1->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with no matchpoint defined'); |
85 |
is($result_1->{feedback}->[0]->{value}, '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 |
is($result_1->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with no matchpoint defined'); |
86 |
'Got the expected header row value from import_patrons with no matchpoint defined'); |
|
|
87 |
|
94 |
|
88 |
is($result_1->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with no matchpoint defined'); |
95 |
is($result_1->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with no matchpoint defined'); |
89 |
is($result_1->{feedback}->[1]->{name}, 'lastimported', 'Got the expected last imported name from import_patrons with no matchpoint defined'); |
96 |
is($result_1->{feedback}->[1]->{name}, 'lastimported', 'Got the expected last imported name from import_patrons with no matchpoint defined'); |
Lines 109-116
is($result_2->{errors}->[0]->{invalid_cardnumber}, 1, 'Got the expected invalid
Link Here
|
109 |
|
116 |
|
110 |
is($result_2->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with invalid card number'); |
117 |
is($result_2->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with invalid card number'); |
111 |
is($result_2->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with invalid card number'); |
118 |
is($result_2->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with invalid card number'); |
112 |
is($result_2->{feedback}->[0]->{value}, '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', |
119 |
is($result_2->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with invalid card number'); |
113 |
'Got the expected header row value from import_patrons with invalid card number'); |
|
|
114 |
|
120 |
|
115 |
is($result_2->{imported}, 0, 'Got the expected 0 imported result from import_patrons with invalid card number'); |
121 |
is($result_2->{imported}, 0, 'Got the expected 0 imported result from import_patrons with invalid card number'); |
116 |
is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number'); |
122 |
is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number'); |
Lines 131-138
is($result_3->{errors}->[0]->{userid}, 'jjenkins0', 'Got the expected userid err
Link Here
|
131 |
|
137 |
|
132 |
is($result_3->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with duplicate userid'); |
138 |
is($result_3->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with duplicate userid'); |
133 |
is($result_3->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
139 |
is($result_3->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
134 |
is($result_3->{feedback}->[0]->{value}, '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', |
140 |
is($result_3->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
135 |
'Got the expected header row value from import_patrons with duplicate userid'); |
|
|
136 |
|
141 |
|
137 |
is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid'); |
142 |
is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid'); |
138 |
is($result_3->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid'); |
143 |
is($result_3->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid'); |
Lines 140-151
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from impo
Link Here
|
140 |
|
145 |
|
141 |
# Given ... a new input and mocked C4::Context |
146 |
# Given ... a new input and mocked C4::Context |
142 |
my $context = Test::MockModule->new('C4::Context'); |
147 |
my $context = Test::MockModule->new('C4::Context'); |
143 |
$context->mock('preference', sub { my ($mod, $meth) = @_; if ( $meth eq 'ExtendedPatronAttributes' ) { return 1; } }); |
148 |
$context->mock('preference', sub { my ($mod, $meth) = @_; |
|
|
149 |
if ( $meth eq 'ExtendedPatronAttributes' ) { return 1; } |
150 |
if ( $meth eq 'dateformat' ) { return 'us'; } |
151 |
}); |
144 |
|
152 |
|
145 |
my $new_input_line = '1001,Donna,Sullivan,Mrs,Henry,DS,59,Court,Burrows,Reading,Salt Lake City,Pennsylvania,19605,United States,hsullivan1@purevolume.com,3-(864)009-3006,7-(291)885-8423,1-(879)095-5038,19/09/1970,LPL,PT,04/03/2015,01/07/2015,hsullivan1,8j6P6Dmap'; |
153 |
my $new_input_line = '1001,Donna,Sullivan,Mrs,Henry,DS,59,Court,Burrows,Reading,Salt Lake City,Pennsylvania,19605,United States,hsullivan1@purevolume.com,3-(864)009-3006,7-(291)885-8423,1-(879)095-5038,09/19/1970,LPL,PT,03/04/2015,07/01/2015,hsullivan1,8j6P6Dmap'; |
146 |
my $filename_4 = make_csv($temp_dir, $csv_headers, $new_input_line); |
154 |
my $filename_4 = make_csv($temp_dir, $csv_headers, $new_input_line); |
147 |
open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!"; |
155 |
open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!"; |
148 |
my $params_4 = { file => $handle_4, matchpoint => 'cardnumber', }; |
156 |
my $params_4 = { file => $handle_4, matchpoint => 'SHOW_BCODE', }; |
149 |
|
157 |
|
150 |
# When ... |
158 |
# When ... |
151 |
my $result_4 = $patrons_import->import_patrons($params_4); |
159 |
my $result_4 = $patrons_import->import_patrons($params_4); |
Lines 156-163
is(scalar @{$result_4->{errors}}, 0, 'Got the expected 0 size error array from i
Link Here
|
156 |
|
164 |
|
157 |
is($result_4->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with extended user'); |
165 |
is($result_4->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with extended user'); |
158 |
is($result_4->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with extended user'); |
166 |
is($result_4->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with extended user'); |
159 |
is($result_4->{feedback}->[0]->{value}, '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', |
167 |
is($result_4->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with extended user'); |
160 |
'Got the expected header row value from import_patrons with extended user'); |
|
|
161 |
|
168 |
|
162 |
is($result_4->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with extended user'); |
169 |
is($result_4->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with extended user'); |
163 |
is($result_4->{feedback}->[1]->{name}, 'attribute string', 'Got the expected attribute string from import_patrons with extended user'); |
170 |
is($result_4->{feedback}->[1]->{name}, 'attribute string', 'Got the expected attribute string from import_patrons with extended user'); |
Lines 174-182
is($result_4->{overwritten}, 0, 'Got the expected 0 overwritten result from impo
Link Here
|
174 |
$context->unmock('preference'); |
181 |
$context->unmock('preference'); |
175 |
|
182 |
|
176 |
# Given ... 3 new inputs. One with no branch code, one with unexpected branch code. |
183 |
# Given ... 3 new inputs. One with no branch code, one with unexpected branch code. |
177 |
my $input_no_branch = '1002,Johnny,Reynolds,Mr,Patricia,JR,12,Hill,Kennedy,Saint Louis,Colorado Springs,Missouri,63131,United States,preynolds2@washington.edu,7-(925)314-9514,0-(315)973-8956,4-(510)556-2323,18/09/1967,,PT,07/05/2015,01/07/2015,preynolds2,K3HiDzl'; |
184 |
my $input_no_branch = '1002,Johnny,Reynolds,Mr,Patricia,JR,12,Hill,Kennedy,Saint Louis,Colorado Springs,Missouri,63131,United States,preynolds2@washington.edu,7-(925)314-9514,0-(315)973-8956,4-(510)556-2323,09/18/1967,,PT,05/07/2015,07/01/2015,preynolds2,K3HiDzl'; |
178 |
my $input_good_branch = '1003,Linda,Richardson,Mr,Kimberly,LR,90,Place,Bayside,Atlanta,Erie,Georgia,31190,United States,krichardson3@pcworld.com,8-(035)185-0387,4-(796)518-3676,3-(644)960-3789,13/04/1954,RPL,PT,06/06/2015,01/07/2015,krichardson3,P3EO0MVRPXbM'; |
185 |
my $input_good_branch = '1003,Linda,Richardson,Mr,Kimberly,LR,90,Place,Bayside,Atlanta,Erie,Georgia,31190,United States,krichardson3@pcworld.com,8-(035)185-0387,4-(796)518-3676,3-(644)960-3789,04/13/1954,RPL,PT,06/06/2015,07/01/2015,krichardson3,P3EO0MVRPXbM'; |
179 |
my $input_na_branch = '1005,Ruth,Greene,Mr,Michael,RG,3,Avenue,Grim,Peoria,Jacksonville,Illinois,61614,United States,mgreene5@seesaa.net,3-(941)565-5752,1-(483)885-8138,4-(979)577-6908,09/02/1957,ZZZ,ST,02/04/2015,01/07/2015,mgreene5,or4ORT6JH'; |
186 |
my $input_na_branch = '1005,Ruth,Greene,Mr,Michael,RG,3,Avenue,Grim,Peoria,Jacksonville,Illinois,61614,United States,mgreene5@seesaa.net,3-(941)565-5752,1-(483)885-8138,4-(979)577-6908,02/09/1957,ZZZ,ST,04/02/2015,07/01/2015,mgreene5,or4ORT6JH'; |
180 |
|
187 |
|
181 |
my $filename_5 = make_csv($temp_dir, $csv_headers, $input_no_branch, $input_good_branch, $input_na_branch); |
188 |
my $filename_5 = make_csv($temp_dir, $csv_headers, $input_no_branch, $input_good_branch, $input_na_branch); |
182 |
open(my $handle_5, "<", $filename_5) or die "cannot open < $filename_5: $!"; |
189 |
open(my $handle_5, "<", $filename_5) or die "cannot open < $filename_5: $!"; |
Lines 204-211
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZZ', 'Got the
Link Here
|
204 |
|
211 |
|
205 |
is($result_5->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
212 |
is($result_5->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
206 |
is($result_5->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for branch tests'); |
213 |
is($result_5->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for branch tests'); |
207 |
is($result_5->{feedback}->[0]->{value}, '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', |
214 |
is($result_5->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for branch tests'); |
208 |
'Got the expected header row value from import_patrons for branch tests'); |
|
|
209 |
|
215 |
|
210 |
is($result_5->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
216 |
is($result_5->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
211 |
is($result_5->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for branch tests'); |
217 |
is($result_5->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for branch tests'); |
Lines 216-224
is($result_5->{invalid}, 2, 'Got the expected 2 invalid result from import patro
Link Here
|
216 |
is($result_5->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for branch tests'); |
222 |
is($result_5->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for branch tests'); |
217 |
|
223 |
|
218 |
# Given ... 3 new inputs. One with no category code, one with unexpected category code. |
224 |
# Given ... 3 new inputs. One with no category code, one with unexpected category code. |
219 |
my $input_no_category = '1006,Christina,Olson,Rev,Kimberly,CO,8,Avenue,Northridge,Lexington,Wilmington,Kentucky,40510,United States,kolson6@dropbox.com,7-(810)636-6048,1-(052)012-8984,8-(567)232-7818,26/03/1952,FFL,,07/09/2014,01/07/2015,kolson6,x5D3qGbLlptx'; |
225 |
my $input_no_category = '1006,Christina,Olson,Rev,Kimberly,CO,8,Avenue,Northridge,Lexington,Wilmington,Kentucky,40510,United States,kolson6@dropbox.com,7-(810)636-6048,1-(052)012-8984,8-(567)232-7818,03/26/1952,FFL,,09/07/2014,01/07/2015,kolson6,x5D3qGbLlptx'; |
220 |
my $input_good_category = '1007,Peter,Peters,Mrs,Lawrence,PP,6,Trail,South,Oklahoma City,Topeka,Oklahoma,73135,United States,lpeters7@bandcamp.com,5-(992)205-9318,0-(732)586-9365,3-(448)146-7936,16/08/1983,PVL,T,24/03/2015,01/07/2015,lpeters7,Z19BrQ4'; |
226 |
my $input_good_category = '1007,Peter,Peters,Mrs,Lawrence,PP,6,Trail,South,Oklahoma City,Topeka,Oklahoma,73135,United States,lpeters7@bandcamp.com,5-(992)205-9318,0-(732)586-9365,3-(448)146-7936,08/16/1983,PVL,T,03/24/2015,07/01/2015,lpeters7,Z19BrQ4'; |
221 |
my $input_na_category = '1008,Emily,Richards,Ms,Judy,ER,73,Way,Kedzie,Fort Wayne,Phoenix,Indiana,46825,United States,jrichards8@arstechnica.com,5-(266)658-8957,3-(550)500-9107,7-(816)675-9822,09/08/1984,FFL,ZZ,09/11/2014,01/07/2015,jrichards8,D5PvU6H2R'; |
227 |
my $input_na_category = '1008,Emily,Richards,Ms,Judy,ER,73,Way,Kedzie,Fort Wayne,Phoenix,Indiana,46825,United States,jrichards8@arstechnica.com,5-(266)658-8957,3-(550)500-9107,7-(816)675-9822,08/09/1984,FFL,ZZ,11/09/2014,07/01/2015,jrichards8,D5PvU6H2R'; |
222 |
|
228 |
|
223 |
my $filename_6 = make_csv($temp_dir, $csv_headers, $input_no_category, $input_good_category, $input_na_category); |
229 |
my $filename_6 = make_csv($temp_dir, $csv_headers, $input_no_category, $input_good_category, $input_na_category); |
224 |
open(my $handle_6, "<", $filename_6) or die "cannot open < $filename_6: $!"; |
230 |
open(my $handle_6, "<", $filename_6) or die "cannot open < $filename_6: $!"; |
Lines 246-253
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZ', 'Got the e
Link Here
|
246 |
|
252 |
|
247 |
is($result_6->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
253 |
is($result_6->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
248 |
is($result_6->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for category tests'); |
254 |
is($result_6->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for category tests'); |
249 |
is($result_6->{feedback}->[0]->{value}, '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', |
255 |
is($result_6->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for category tests'); |
250 |
'Got the expected header row value from import_patrons for category tests'); |
|
|
251 |
|
256 |
|
252 |
is($result_6->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
257 |
is($result_6->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
253 |
is($result_6->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for category tests'); |
258 |
is($result_6->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for category tests'); |
Lines 258-284
is($result_6->{invalid}, 2, 'Got the expected 2 invalid result from import patro
Link Here
|
258 |
is($result_6->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for category tests'); |
263 |
is($result_6->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for category tests'); |
259 |
|
264 |
|
260 |
# Given ... 2 new inputs. One without dateofbirth, dateenrolled and dateexpiry values. |
265 |
# Given ... 2 new inputs. One without dateofbirth, dateenrolled and dateexpiry values. |
261 |
my $input_complete = '1009,Christina,Harris,Dr,Philip,CH,99,Street,Grayhawk,Baton Rouge,Dallas,Louisiana,70810,United States,pharris9@hp.com,9-(317)603-5513,7-(005)062-7593,8-(349)134-1627,19/06/1969,IPT,PT,09/04/2015,01/07/2015,pharris9,NcAhcvvnB'; |
266 |
my $input_complete = '1009,Christina,Harris,Dr,Philip,CH,99,Street,Grayhawk,Baton Rouge,Dallas,Louisiana,70810,United States,pharris9@hp.com,9-(317)603-5513,7-(005)062-7593,8-(349)134-1627,06/19/1969,IPT,PT,04/09/2015,07/01/2015,pharris9,NcAhcvvnB'; |
262 |
my $input_no_date = '1010,Ralph,Warren,Ms,Linda,RW,6,Way,Barby,Orlando,Albany,Florida,32803,United States,lwarrena@multiply.com,7-(579)753-7752,6-(847)086-7566,9-(122)729-8226,,LPL,T,,,lwarrena,tJ56RD4uV'; |
267 |
my $input_no_date = '1010,Ralph,Warren,Ms,Linda,RW,6,Way,Barby,Orlando,Albany,Florida,32803,United States,lwarrena@multiply.com,7-(579)753-7752,6-(847)086-7566,9-(122)729-8226,26/01/2001,LPL,T,25/01/2001,24/01/2001,lwarrena,tJ56RD4uV'; |
263 |
|
268 |
|
264 |
my $filename_7 = make_csv($temp_dir, $csv_headers, $input_complete, $input_no_date); |
269 |
my $filename_7 = make_csv($temp_dir, $csv_headers, $input_complete, $input_no_date); |
265 |
open(my $handle_7, "<", $filename_7) or die "cannot open < $filename_7: $!"; |
270 |
open(my $handle_7, "<", $filename_7) or die "cannot open < $filename_7: $!"; |
266 |
my $params_7 = { file => $handle_7, matchpoint => 'cardnumber', }; |
271 |
my $params_7 = { file => $handle_7, matchpoint => 'cardnumber', }; |
267 |
|
272 |
|
268 |
# Need upgrade to Moo |
273 |
# When ... |
|
|
274 |
my $result_7 = $patrons_import->import_patrons($params_7); |
275 |
|
276 |
# Then ... |
277 |
is($result_7->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for dates tests'); |
278 |
is(scalar @{$result_7->{errors}}, 1, 'Got the expected 1 error array size from import_patrons for dates tests'); |
279 |
is(scalar @{$result_7->{errors}->[0]->{missing_criticals}}, 3, 'Got the expected 3 missing critical errors from import_patrons for dates tests'); |
280 |
|
281 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{bad_date}, 1, 'Got the expected 1 bad_date error from import patrons for dates tests'); |
282 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for dates tests'); |
283 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{key}, 'dateofbirth', 'Got the expected dateofbirth key from import patrons for dates tests'); |
284 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{line}, 3, 'Got the expected 2 line number error from import patrons for dates tests'); |
285 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_date."\r\n", 'Got the expected lineraw error from import patrons for dates tests'); |
286 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{surname}, 'Ralph', 'Got the expected surname error from import patrons for dates tests'); |
287 |
|
288 |
is($result_7->{errors}->[0]->{missing_criticals}->[1]->{key}, 'dateenrolled', 'Got the expected dateenrolled key from import patrons for dates tests'); |
289 |
is($result_7->{errors}->[0]->{missing_criticals}->[2]->{key}, 'dateexpiry', 'Got the expected dateexpiry key from import patrons for dates tests'); |
290 |
|
291 |
is(scalar @{$result_7->{feedback}}, 2, 'Got the expected 2 feedback from import patrons for dates tests'); |
292 |
is($result_7->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests'); |
293 |
is($result_7->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for dates tests'); |
294 |
is($result_7->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for dates tests'); |
295 |
|
296 |
is($result_7->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests'); |
297 |
is($result_7->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported from import_patrons for dates tests'); |
298 |
like($result_7->{feedback}->[1]->{value}, qr/^Christina \/ \d+/, 'Got the expected lastimported value from import_patrons for dates tests'); |
299 |
|
300 |
is($result_7->{imported}, 1, 'Got the expected 1 imported result from import patrons for dates tests'); |
301 |
is($result_7->{invalid}, 1, 'Got the expected 1 invalid result from import patrons for dates tests'); |
302 |
is($result_7->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for dates tests'); |
303 |
|
304 |
subtest 'test_prepare_columns' => sub { |
305 |
plan tests => 16; |
306 |
|
307 |
# Given ... no header row |
308 |
my $headerrow_0; |
309 |
my %csvkeycol_0; |
310 |
my @errors_0; |
311 |
|
312 |
# When ... |
313 |
my @csvcolumns_0 = $patrons_import->prepare_columns({headerrow => undef, keycol => \%csvkeycol_0, errors => \@errors_0, }); |
314 |
|
315 |
# Then ... |
316 |
is(scalar @csvcolumns_0, 0, 'Got the expected empty column array from prepare columns with no header row'); |
317 |
|
318 |
is(scalar @errors_0, 1, 'Got the expected 1 entry in error array from prepare columns with no header row'); |
319 |
is($errors_0[0]->{badheader}, 1, 'Got the expected 1 badheader from prepare columns with no header row'); |
320 |
is($errors_0[0]->{line}, 1, 'Got the expected 1 line from prepare columns with no header row'); |
321 |
is($errors_0[0]->{lineraw}, undef, 'Got the expected undef lineraw from prepare columns with no header row'); |
322 |
|
323 |
# Given ... a good header row with plenty of whitespaces |
324 |
my $headerrow_1 = 'a, b , c, , d'; |
325 |
my %csvkeycol_1; |
326 |
my @errors_1; |
327 |
|
328 |
# When ... |
329 |
my @csvcolumns_1 = $patrons_import->prepare_columns({headerrow => $headerrow_1, keycol => \%csvkeycol_1, errors => \@errors_1, }); |
330 |
|
331 |
# Then ... |
332 |
is(scalar @csvcolumns_1, 5, 'Got the expected 5 column array from prepare columns'); |
333 |
is($csvcolumns_1[0], 'a', 'Got the expected a header from prepare columns'); |
334 |
is($csvcolumns_1[1], 'b', 'Got the expected b header from prepare columns'); |
335 |
is($csvcolumns_1[2], 'c', 'Got the expected c header from prepare columns'); |
336 |
is($csvcolumns_1[3], '', 'Got the expected empty header from prepare columns'); |
337 |
is($csvcolumns_1[4], 'd', 'Got the expected d header from prepare columns'); |
338 |
|
339 |
is($csvkeycol_1{a}, 0, 'Got the expected 0 value for key a from prepare columns hash'); |
340 |
is($csvkeycol_1{b}, 1, 'Got the expected 1 value for key b from prepare columns hash'); |
341 |
is($csvkeycol_1{c}, 2, 'Got the expected 2 value for key c from prepare columns hash'); |
342 |
is($csvkeycol_1{''}, 3, 'Got the expected 3 value for empty string key from prepare columns hash'); |
343 |
is($csvkeycol_1{d}, 4, 'Got the expected 4 value for key d from prepare columns hash'); |
344 |
}; |
345 |
|
346 |
subtest 'test_set_column_keys' => sub { |
347 |
plan tests => 5; |
348 |
|
349 |
# Given ... nothing at all |
350 |
# When ... Then ... |
351 |
my $attr_type_0 = $patrons_import->set_attribute_types(undef); |
352 |
is($attr_type_0, undef, 'Got the expected undef attribute type from set attribute types with nothing'); |
353 |
|
354 |
# Given ... extended but not matchpoint |
355 |
my $params_1 = { extended => 1, matchpoint => undef, }; |
356 |
|
357 |
# When ... Then ... |
358 |
my $attr_type_1 = $patrons_import->set_attribute_types($params_1); |
359 |
is($attr_type_1, undef, 'Got the expected undef attribute type from set attribute types with no matchpoint'); |
360 |
|
361 |
# Given ... extended and unexpected matchpoint |
362 |
my $params_2 = { extended => 1, matchpoint => 'unexpected', }; |
363 |
|
364 |
# When ... Then ... |
365 |
my $attr_type_2 = $patrons_import->set_attribute_types($params_2); |
366 |
is($attr_type_2, undef, 'Got the expected undef attribute type from set attribute types with unexpected matchpoint'); |
367 |
|
368 |
# Given ... |
369 |
my $code_3 = 'SHOW_BCODE'; |
370 |
my $params_3 = { extended => 1, matchpoint => $code_3, }; |
371 |
|
372 |
# When ... |
373 |
my $attr_type_3 = $patrons_import->set_attribute_types($params_3); |
374 |
|
375 |
# Then ... |
376 |
isa_ok($attr_type_3, 'C4::Members::AttributeTypes'); |
377 |
is($attr_type_3->{code}, $code_3, 'Got the expected code attribute type from set attribute types'); |
378 |
}; |
379 |
|
269 |
subtest 'test_set_column_keys' => sub { |
380 |
subtest 'test_set_column_keys' => sub { |
270 |
plan tests => 2; |
381 |
plan tests => 2; |
271 |
|
382 |
|
272 |
# Given ... nothing at all |
383 |
# Given ... nothing at all |
273 |
# When ... Then ... |
384 |
# When ... Then ... |
274 |
my @columnkeys_0 = Koha::Patrons::Import::set_column_keys(undef); |
385 |
my @columnkeys_0 = $patrons_import->set_column_keys(undef); |
275 |
is(scalar @columnkeys_0, 66, 'Got the expected array size from set column keys with undef extended'); |
386 |
is(scalar @columnkeys_0, 66, 'Got the expected array size from set column keys with undef extended'); |
276 |
|
387 |
|
277 |
# Given ... extended. |
388 |
# Given ... extended. |
278 |
my $extended = 1; |
389 |
my $extended = 1; |
279 |
|
390 |
|
280 |
# When ... Then ... |
391 |
# When ... Then ... |
281 |
my @columnkeys_1 = Koha::Patrons::Import::set_column_keys($extended); |
392 |
my @columnkeys_1 = $patrons_import->set_column_keys($extended); |
282 |
is(scalar @columnkeys_1, 67, 'Got the expected array size from set column keys with extended'); |
393 |
is(scalar @columnkeys_1, 67, 'Got the expected array size from set column keys with extended'); |
283 |
}; |
394 |
}; |
284 |
|
395 |
|
Lines 287-300
subtest 'test_set_patron_attributes' => sub {
Link Here
|
287 |
|
398 |
|
288 |
# Given ... nothing at all |
399 |
# Given ... nothing at all |
289 |
# When ... Then ... |
400 |
# When ... Then ... |
290 |
my $result_0 = Koha::Patrons::Import::set_patron_attributes(undef, undef, undef); |
401 |
my $result_0 = $patrons_import->set_patron_attributes(undef, undef, undef); |
291 |
is($result_0, undef, 'Got the expected undef from set patron attributes with nothing'); |
402 |
is($result_0, undef, 'Got the expected undef from set patron attributes with nothing'); |
292 |
|
403 |
|
293 |
# Given ... not extended. |
404 |
# Given ... not extended. |
294 |
my $extended_1 = 0; |
405 |
my $extended_1 = 0; |
295 |
|
406 |
|
296 |
# When ... Then ... |
407 |
# When ... Then ... |
297 |
my $result_1 = Koha::Patrons::Import::set_patron_attributes($extended_1, undef, undef); |
408 |
my $result_1 = $patrons_import->set_patron_attributes($extended_1, undef, undef); |
298 |
is($result_1, undef, 'Got the expected undef from set patron attributes with not extended'); |
409 |
is($result_1, undef, 'Got the expected undef from set patron attributes with not extended'); |
299 |
|
410 |
|
300 |
# Given ... NO patrons attributes |
411 |
# Given ... NO patrons attributes |
Lines 303-309
subtest 'test_set_patron_attributes' => sub {
Link Here
|
303 |
my @feedback_2; |
414 |
my @feedback_2; |
304 |
|
415 |
|
305 |
# When ... |
416 |
# When ... |
306 |
my $result_2 = Koha::Patrons::Import::set_patron_attributes($extended_2, $patron_attributes_2, \@feedback_2); |
417 |
my $result_2 = $patrons_import->set_patron_attributes($extended_2, $patron_attributes_2, \@feedback_2); |
307 |
|
418 |
|
308 |
# Then ... |
419 |
# Then ... |
309 |
is($result_2, undef, 'Got the expected undef from set patron attributes with no patrons attributes'); |
420 |
is($result_2, undef, 'Got the expected undef from set patron attributes with no patrons attributes'); |
Lines 314-320
subtest 'test_set_patron_attributes' => sub {
Link Here
|
314 |
my @feedback_3; |
425 |
my @feedback_3; |
315 |
|
426 |
|
316 |
# When ... |
427 |
# When ... |
317 |
my $result_3 = Koha::Patrons::Import::set_patron_attributes($extended_2, $patron_attributes_3, \@feedback_3); |
428 |
my $result_3 = $patrons_import->set_patron_attributes($extended_2, $patron_attributes_3, \@feedback_3); |
318 |
|
429 |
|
319 |
# Then ... |
430 |
# Then ... |
320 |
ok($result_3, 'Got some data back from set patron attributes'); |
431 |
ok($result_3, 'Got some data back from set patron attributes'); |
Lines 339-345
subtest 'test_check_branch_code' => sub {
Link Here
|
339 |
my @missing_criticals = (); |
450 |
my @missing_criticals = (); |
340 |
|
451 |
|
341 |
# When ... |
452 |
# When ... |
342 |
Koha::Patrons::Import::check_branch_code(undef, $borrowerline, $line_number, \@missing_criticals); |
453 |
$patrons_import->check_branch_code(undef, $borrowerline, $line_number, \@missing_criticals); |
343 |
|
454 |
|
344 |
# Then ... |
455 |
# Then ... |
345 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no branch code'); |
456 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no branch code'); |
Lines 355-361
subtest 'test_check_branch_code' => sub {
Link Here
|
355 |
my @missing_criticals_1 = (); |
466 |
my @missing_criticals_1 = (); |
356 |
|
467 |
|
357 |
# When ... |
468 |
# When ... |
358 |
Koha::Patrons::Import::check_branch_code($branchcode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
469 |
$patrons_import->check_branch_code($branchcode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
359 |
|
470 |
|
360 |
# Then ... |
471 |
# Then ... |
361 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected branch code'); |
472 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected branch code'); |
Lines 373-379
subtest 'test_check_branch_code' => sub {
Link Here
|
373 |
my @missing_criticals_2 = (); |
484 |
my @missing_criticals_2 = (); |
374 |
|
485 |
|
375 |
# When ... |
486 |
# When ... |
376 |
Koha::Patrons::Import::check_branch_code($branchcode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
487 |
$patrons_import->check_branch_code($branchcode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
377 |
|
488 |
|
378 |
# Then ... |
489 |
# Then ... |
379 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
490 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
Lines 388-394
subtest 'test_check_borrower_category' => sub {
Link Here
|
388 |
my @missing_criticals = (); |
499 |
my @missing_criticals = (); |
389 |
|
500 |
|
390 |
# When ... |
501 |
# When ... |
391 |
Koha::Patrons::Import::check_borrower_category(undef, $borrowerline, $line_number, \@missing_criticals); |
502 |
$patrons_import->check_borrower_category(undef, $borrowerline, $line_number, \@missing_criticals); |
392 |
|
503 |
|
393 |
# Then ... |
504 |
# Then ... |
394 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no category code'); |
505 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no category code'); |
Lines 404-410
subtest 'test_check_borrower_category' => sub {
Link Here
|
404 |
my @missing_criticals_1 = (); |
515 |
my @missing_criticals_1 = (); |
405 |
|
516 |
|
406 |
# When ... |
517 |
# When ... |
407 |
Koha::Patrons::Import::check_borrower_category($categorycode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
518 |
$patrons_import->check_borrower_category($categorycode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
408 |
|
519 |
|
409 |
# Then ... |
520 |
# Then ... |
410 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected category code'); |
521 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected category code'); |
Lines 422-432
subtest 'test_check_borrower_category' => sub {
Link Here
|
422 |
my @missing_criticals_2 = (); |
533 |
my @missing_criticals_2 = (); |
423 |
|
534 |
|
424 |
# When ... |
535 |
# When ... |
425 |
Koha::Patrons::Import::check_borrower_category($categorycode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
536 |
$patrons_import->check_borrower_category($categorycode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
426 |
|
537 |
|
427 |
# Then ... |
538 |
# Then ... |
428 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
539 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
429 |
}; |
540 |
}; |
|
|
541 |
|
542 |
subtest 'test_format_dates' => sub { |
543 |
plan tests => 22; |
544 |
|
545 |
# Given ... no borrower data. |
546 |
my $borrowerline = 'another line'; |
547 |
my $line_number = 987; |
548 |
my @missing_criticals = (); |
549 |
my %borrower; |
550 |
my $params = {borrower => \%borrower, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals, }; |
551 |
|
552 |
# When ... |
553 |
$patrons_import->format_dates($params); |
554 |
|
555 |
# Then ... |
556 |
ok( not(%borrower), 'Got the expected no borrower from format_dates with no dates'); |
557 |
is(scalar @missing_criticals, 0, 'Got the expected missing critical array size of 0 from format_dates with no dates'); |
558 |
|
559 |
# Given ... some good dates |
560 |
my @missing_criticals_1 = (); |
561 |
my $dateofbirth_1 = '2016-05-03'; |
562 |
my $dateenrolled_1 = '2016-05-04'; |
563 |
my $dateexpiry_1 = '2016-05-06'; |
564 |
my $borrower_1 = { dateofbirth => $dateofbirth_1, dateenrolled => $dateenrolled_1, dateexpiry => $dateexpiry_1, }; |
565 |
my $params_1 = {borrower => $borrower_1, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals_1, }; |
566 |
|
567 |
# When ... |
568 |
$patrons_import->format_dates($params_1); |
569 |
|
570 |
# Then ... |
571 |
is($borrower_1->{dateofbirth}, $dateofbirth_1, 'Got the expected date of birth from format_dates with good dates'); |
572 |
is($borrower_1->{dateenrolled}, $dateenrolled_1, 'Got the expected date of birth from format_dates with good dates'); |
573 |
is($borrower_1->{dateexpiry}, $dateexpiry_1, 'Got the expected date of birth from format_dates with good dates'); |
574 |
is(scalar @missing_criticals_1, 0, 'Got the expected missing critical array size of 0 from check_branch_code with good dates'); |
575 |
|
576 |
# Given ... some very bad dates |
577 |
my @missing_criticals_2 = (); |
578 |
my $dateofbirth_2 = '03-2016-05'; |
579 |
my $dateenrolled_2 = '04-2016-05'; |
580 |
my $dateexpiry_2 = '06-2016-05'; |
581 |
my $borrower_2 = { dateofbirth => $dateofbirth_2, dateenrolled => $dateenrolled_2, dateexpiry => $dateexpiry_2, }; |
582 |
my $params_2 = {borrower => $borrower_2, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals_2, }; |
583 |
|
584 |
# When ... |
585 |
$patrons_import->format_dates($params_2); |
586 |
|
587 |
# Then ... |
588 |
is($borrower_2->{dateofbirth}, '', 'Got the expected empty date of birth from format_dates with bad dates'); |
589 |
is($borrower_2->{dateenrolled}, '', 'Got the expected emptydate of birth from format_dates with bad dates'); |
590 |
is($borrower_2->{dateexpiry}, '', 'Got the expected empty date of birth from format_dates with bad dates'); |
591 |
|
592 |
is(scalar @missing_criticals_2, 3, 'Got the expected missing critical array size of 3 from check_branch_code with bad dates'); |
593 |
is($missing_criticals_2[0]->{bad_date}, 1, 'Got the expected first bad date flag from check_branch_code with bad dates'); |
594 |
is($missing_criticals_2[0]->{key}, 'dateofbirth', 'Got the expected dateofbirth key from check_branch_code with bad dates'); |
595 |
is($missing_criticals_2[0]->{line}, $line_number, 'Got the expected first line from check_branch_code with bad dates'); |
596 |
is($missing_criticals_2[0]->{lineraw}, $borrowerline, 'Got the expected first lineraw from check_branch_code with bad dates'); |
597 |
|
598 |
is($missing_criticals_2[1]->{bad_date}, 1, 'Got the expected second bad date flag from check_branch_code with bad dates'); |
599 |
is($missing_criticals_2[1]->{key}, 'dateenrolled', 'Got the expected dateenrolled key from check_branch_code with bad dates'); |
600 |
is($missing_criticals_2[1]->{line}, $line_number, 'Got the expected second line from check_branch_code with bad dates'); |
601 |
is($missing_criticals_2[1]->{lineraw}, $borrowerline, 'Got the expected second lineraw from check_branch_code with bad dates'); |
602 |
|
603 |
is($missing_criticals_2[2]->{bad_date}, 1, 'Got the expected third bad date flag from check_branch_code with bad dates'); |
604 |
is($missing_criticals_2[2]->{key}, 'dateexpiry', 'Got the expected dateexpiry key from check_branch_code with bad dates'); |
605 |
is($missing_criticals_2[2]->{line}, $line_number, 'Got the expected third line from check_branch_code with bad dates'); |
606 |
is($missing_criticals_2[2]->{lineraw}, $borrowerline, 'Got the expected third lineraw from check_branch_code with bad dates'); |
607 |
}; |
608 |
|
430 |
# ###### Test utility ########### |
609 |
# ###### Test utility ########### |
431 |
sub make_csv { |
610 |
sub make_csv { |
432 |
my ($temp_dir, @lines) = @_; |
611 |
my ($temp_dir, @lines) = @_; |
433 |
- |
|
|