Lines 31-37
use Koha::Patron::Relationships;
Link Here
|
31 |
use Koha::DateUtils qw(dt_from_string); |
31 |
use Koha::DateUtils qw(dt_from_string); |
32 |
|
32 |
|
33 |
use File::Temp qw(tempfile tempdir); |
33 |
use File::Temp qw(tempfile tempdir); |
34 |
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1); |
34 |
my $temp_dir = tempdir( 'Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1 ); |
35 |
|
35 |
|
36 |
use t::lib::Mocks; |
36 |
use t::lib::Mocks; |
37 |
use t::lib::TestBuilder; |
37 |
use t::lib::TestBuilder; |
Lines 50-80
subtest 'test_methods' => sub {
Link Here
|
50 |
plan tests => 1; |
50 |
plan tests => 1; |
51 |
|
51 |
|
52 |
# Given ... we can reach the method(s) |
52 |
# Given ... we can reach the method(s) |
53 |
my @methods = ('import_patrons', |
53 |
my @methods = ( |
54 |
'set_attribute_types', |
54 |
'import_patrons', |
55 |
'prepare_columns', |
55 |
'set_attribute_types', |
56 |
'set_column_keys', |
56 |
'prepare_columns', |
57 |
'generate_patron_attributes', |
57 |
'set_column_keys', |
58 |
'check_branch_code', |
58 |
'generate_patron_attributes', |
59 |
'format_dates', |
59 |
'check_branch_code', |
60 |
); |
60 |
'format_dates', |
61 |
can_ok('Koha::Patrons::Import', @methods); |
61 |
); |
|
|
62 |
can_ok( 'Koha::Patrons::Import', @methods ); |
62 |
}; |
63 |
}; |
63 |
|
64 |
|
64 |
subtest 'test_attributes' => sub { |
65 |
subtest 'test_attributes' => sub { |
65 |
plan tests => 1; |
66 |
plan tests => 1; |
66 |
|
67 |
|
67 |
my @attributes = ('today_iso', 'text_csv'); |
68 |
my @attributes = ( 'today_iso', 'text_csv' ); |
68 |
can_ok('Koha::Patrons::Import', @attributes); |
69 |
can_ok( 'Koha::Patrons::Import', @attributes ); |
69 |
}; |
70 |
}; |
70 |
|
71 |
|
71 |
# Tests for Koha::Patrons::Import::import_patrons() |
72 |
# Tests for Koha::Patrons::Import::import_patrons() |
72 |
# Given ... nothing much. When ... Then ... |
73 |
# Given ... nothing much. When ... Then ... |
73 |
my $result; |
74 |
my $result; |
74 |
warning_is { $result = $patrons_import->import_patrons(undef) } |
75 |
warning_is { $result = $patrons_import->import_patrons(undef) } |
75 |
{ carped => 'No file handle passed in!' }, |
76 |
{ carped => 'No file handle passed in!' }, |
76 |
" Koha::Patrons::Import->import_patrons carps if no file handle is passed"; |
77 |
" Koha::Patrons::Import->import_patrons carps if no file handle is passed"; |
77 |
is($result, undef, 'Got the expected undef from import_patrons with nothing much'); |
78 |
is( $result, undef, 'Got the expected undef from import_patrons with nothing much' ); |
78 |
|
79 |
|
79 |
# Given ... some params but no file handle. |
80 |
# Given ... some params but no file handle. |
80 |
my $params_0 = { some_stuff => 'random stuff', }; |
81 |
my $params_0 = { some_stuff => 'random stuff', }; |
Lines 82-459
my $params_0 = { some_stuff => 'random stuff', };
Link Here
|
82 |
# When ... Then ... |
83 |
# When ... Then ... |
83 |
my $result_0; |
84 |
my $result_0; |
84 |
warning_is { $result_0 = $patrons_import->import_patrons($params_0) } |
85 |
warning_is { $result_0 = $patrons_import->import_patrons($params_0) } |
85 |
{ carped => 'No file handle passed in!' }, |
86 |
{ carped => 'No file handle passed in!' }, |
86 |
" Koha::Patrons::Import->import_patrons carps if no file handle is passed"; |
87 |
" Koha::Patrons::Import->import_patrons carps if no file handle is passed"; |
87 |
is($result_0, undef, 'Got the expected undef from import_patrons with no file handle'); |
88 |
is( $result_0, undef, 'Got the expected undef from import_patrons with no file handle' ); |
88 |
|
89 |
|
89 |
# Given ... a file handle to file with headers only. |
90 |
# Given ... a file handle to file with headers only. |
90 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 0); |
91 |
t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 0 ); |
91 |
t::lib::Mocks::mock_preference('dateformat', 'us'); |
92 |
t::lib::Mocks::mock_preference( 'dateformat', 'us' ); |
92 |
|
93 |
|
93 |
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'; |
94 |
my $csv_headers = |
94 |
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'; |
95 |
'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'; |
95 |
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'; |
96 |
my $res_header = |
96 |
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'; |
97 |
'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'; |
97 |
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'; |
98 |
my $csv_one_line = |
98 |
|
99 |
'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'; |
99 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
100 |
my $csv_one_line_a = |
100 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
101 |
'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'; |
|
|
102 |
my $csv_one_line_b = |
103 |
'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'; |
104 |
|
105 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_one_line ); |
106 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
101 |
my $params_1 = { file => $handle_1, }; |
107 |
my $params_1 = { file => $handle_1, }; |
102 |
|
108 |
|
103 |
# When ... |
109 |
# When ... |
104 |
my $result_1 = $patrons_import->import_patrons($params_1); |
110 |
my $result_1 = $patrons_import->import_patrons($params_1); |
105 |
|
111 |
|
106 |
# Then ... |
112 |
# Then ... |
107 |
is($result_1->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with no matchpoint defined'); |
113 |
is( $result_1->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with no matchpoint defined' ); |
108 |
is(scalar @{$result_1->{errors}}, 0, 'Got the expected 0 size error array from import_patrons with no matchpoint defined'); |
114 |
is( |
109 |
|
115 |
scalar @{ $result_1->{errors} }, 0, |
110 |
is($result_1->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with no matchpoint defined'); |
116 |
'Got the expected 0 size error array from import_patrons with no matchpoint defined' |
111 |
is($result_1->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with no matchpoint defined'); |
117 |
); |
112 |
is($result_1->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with no matchpoint defined'); |
118 |
|
113 |
|
119 |
is( |
114 |
is($result_1->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with no matchpoint defined'); |
120 |
$result_1->{feedback}->[0]->{feedback}, 1, |
115 |
is($result_1->{feedback}->[1]->{name}, 'lastimported', 'Got the expected last imported name from import_patrons with no matchpoint defined'); |
121 |
'Got the expected 1 feedback from import_patrons with no matchpoint defined' |
116 |
like($result_1->{feedback}->[1]->{value}, qr/^Nancy \/ \d+/, 'Got the expected second header row value from import_patrons with no matchpoint defined'); |
122 |
); |
117 |
|
123 |
is( |
118 |
is($result_1->{imported}, 1, 'Got the expected 1 imported result from import_patrons with no matchpoint defined'); |
124 |
$result_1->{feedback}->[0]->{name}, 'headerrow', |
119 |
is($result_1->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with no matchpoint defined'); |
125 |
'Got the expected header row name from import_patrons with no matchpoint defined' |
120 |
is($result_1->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with no matchpoint defined'); |
126 |
); |
|
|
127 |
is( |
128 |
$result_1->{feedback}->[0]->{value}, $res_header, |
129 |
'Got the expected header row value from import_patrons with no matchpoint defined' |
130 |
); |
131 |
|
132 |
is( |
133 |
$result_1->{feedback}->[1]->{feedback}, 1, |
134 |
'Got the expected second feedback from import_patrons with no matchpoint defined' |
135 |
); |
136 |
is( |
137 |
$result_1->{feedback}->[1]->{name}, 'lastimported', |
138 |
'Got the expected last imported name from import_patrons with no matchpoint defined' |
139 |
); |
140 |
like( |
141 |
$result_1->{feedback}->[1]->{value}, qr/^Nancy \/ \d+/, |
142 |
'Got the expected second header row value from import_patrons with no matchpoint defined' |
143 |
); |
144 |
|
145 |
is( $result_1->{imported}, 1, 'Got the expected 1 imported result from import_patrons with no matchpoint defined' ); |
146 |
is( $result_1->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with no matchpoint defined' ); |
147 |
is( |
148 |
$result_1->{overwritten}, 0, |
149 |
'Got the expected 0 overwritten result from import_patrons with no matchpoint defined' |
150 |
); |
121 |
|
151 |
|
122 |
# Given ... a valid file handle, a bad matchpoint resulting in invalid card number |
152 |
# Given ... a valid file handle, a bad matchpoint resulting in invalid card number |
123 |
my $filename_2 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
153 |
my $filename_2 = make_csv( $temp_dir, $csv_headers, $csv_one_line ); |
124 |
open(my $handle_2, "<", $filename_2) or die "cannot open < $filename_2: $!"; |
154 |
open( my $handle_2, "<", $filename_2 ) or die "cannot open < $filename_2: $!"; |
125 |
my $params_2 = { file => $handle_2, matchpoint => 'SHOW_BCODE', }; |
155 |
my $params_2 = { file => $handle_2, matchpoint => 'SHOW_BCODE', }; |
126 |
|
156 |
|
127 |
# When ... |
157 |
# When ... |
128 |
my $result_2 = $patrons_import->import_patrons($params_2); |
158 |
my $result_2 = $patrons_import->import_patrons($params_2); |
129 |
|
159 |
|
130 |
# Then ... |
160 |
# Then ... |
131 |
is($result_2->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with invalid card number'); |
161 |
is( $result_2->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with invalid card number' ); |
132 |
is($result_2->{errors}->[0]->{borrowernumber}, undef, 'Got the expected undef borrower number from import patrons with invalid card number'); |
162 |
is( |
133 |
is($result_2->{errors}->[0]->{cardnumber}, 1000, 'Got the expected 1000 card number from import patrons with invalid card number'); |
163 |
$result_2->{errors}->[0]->{borrowernumber}, undef, |
134 |
is($result_2->{errors}->[0]->{invalid_cardnumber}, 1, 'Got the expected invalid card number from import patrons with invalid card number'); |
164 |
'Got the expected undef borrower number from import patrons with invalid card number' |
135 |
|
165 |
); |
136 |
is($result_2->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with invalid card number'); |
166 |
is( |
137 |
is($result_2->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with invalid card number'); |
167 |
$result_2->{errors}->[0]->{cardnumber}, 1000, |
138 |
is($result_2->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with invalid card number'); |
168 |
'Got the expected 1000 card number from import patrons with invalid card number' |
139 |
|
169 |
); |
140 |
is($result_2->{imported}, 0, 'Got the expected 0 imported result from import_patrons with invalid card number'); |
170 |
is( |
141 |
is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number'); |
171 |
$result_2->{errors}->[0]->{invalid_cardnumber}, 1, |
142 |
is($result_2->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with invalid card number'); |
172 |
'Got the expected invalid card number from import patrons with invalid card number' |
|
|
173 |
); |
174 |
|
175 |
is( |
176 |
$result_2->{feedback}->[0]->{feedback}, 1, |
177 |
'Got the expected 1 feedback from import_patrons with invalid card number' |
178 |
); |
179 |
is( |
180 |
$result_2->{feedback}->[0]->{name}, 'headerrow', |
181 |
'Got the expected header row name from import_patrons with invalid card number' |
182 |
); |
183 |
is( |
184 |
$result_2->{feedback}->[0]->{value}, $res_header, |
185 |
'Got the expected header row value from import_patrons with invalid card number' |
186 |
); |
187 |
|
188 |
is( $result_2->{imported}, 0, 'Got the expected 0 imported result from import_patrons with invalid card number' ); |
189 |
is( $result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with invalid card number' ); |
190 |
is( $result_2->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with invalid card number' ); |
143 |
|
191 |
|
144 |
# Given ... valid file handle, good matchpoint that matches should not overwrite when not set. |
192 |
# Given ... valid file handle, good matchpoint that matches should not overwrite when not set. |
145 |
my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_one_line); |
193 |
my $filename_3 = make_csv( $temp_dir, $csv_headers, $csv_one_line ); |
146 |
open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!"; |
194 |
open( my $handle_3, "<", $filename_3 ) or die "cannot open < $filename_3: $!"; |
147 |
my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', }; |
195 |
my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', }; |
148 |
|
196 |
|
149 |
# When ... |
197 |
# When ... |
150 |
my $result_3 = $patrons_import->import_patrons($params_3); |
198 |
my $result_3 = $patrons_import->import_patrons($params_3); |
151 |
|
199 |
|
152 |
# Then ... |
200 |
# Then ... |
153 |
is($result_3->{already_in_db}, 1, 'Got the expected 1 already_in_db from import_patrons with duplicate userid'); |
201 |
is( $result_3->{already_in_db}, 1, 'Got the expected 1 already_in_db from import_patrons with duplicate userid' ); |
154 |
is($result_3->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
202 |
is( |
155 |
is($result_3->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
203 |
$result_3->{errors}->[0]->{duplicate_userid}, undef, |
156 |
|
204 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
157 |
is($result_3->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched but not overwritten'); |
205 |
); |
158 |
is($result_3->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
206 |
is( |
159 |
is($result_3->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
207 |
$result_3->{errors}->[0]->{userid}, undef, |
160 |
|
208 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
161 |
is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons'); |
209 |
); |
162 |
is($result_3->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
210 |
|
163 |
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons that matched'); |
211 |
is( |
|
|
212 |
$result_3->{feedback}->[0]->{feedback}, 1, |
213 |
'Got 1 expected feedback from import_patrons that matched but not overwritten' |
214 |
); |
215 |
is( |
216 |
$result_3->{feedback}->[0]->{name}, 'headerrow', |
217 |
'Got the expected header row name from import_patrons with duplicate userid' |
218 |
); |
219 |
is( |
220 |
$result_3->{feedback}->[0]->{value}, $res_header, |
221 |
'Got the expected header row value from import_patrons with duplicate userid' |
222 |
); |
223 |
|
224 |
is( $result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons' ); |
225 |
is( $result_3->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons' ); |
226 |
is( $result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons that matched' ); |
164 |
|
227 |
|
165 |
# Given ... valid file handle, good matchpoint that matches should overwrite when set. |
228 |
# Given ... valid file handle, good matchpoint that matches should overwrite when set. |
166 |
my $filename_3a = make_csv($temp_dir, $csv_headers, $csv_one_line); |
229 |
my $filename_3a = make_csv( $temp_dir, $csv_headers, $csv_one_line ); |
167 |
open(my $handle_3a, "<", $filename_3a) or die "cannot open < $filename_3: $!"; |
230 |
open( my $handle_3a, "<", $filename_3a ) or die "cannot open < $filename_3: $!"; |
168 |
my $params_3a = { file => $handle_3a, matchpoint => 'cardnumber', overwrite_cardnumber => 1}; |
231 |
my $params_3a = { file => $handle_3a, matchpoint => 'cardnumber', overwrite_cardnumber => 1 }; |
169 |
|
232 |
|
170 |
# When ... |
233 |
# When ... |
171 |
my $result_3a; |
234 |
my $result_3a; |
172 |
warning_is { $result_3a = $patrons_import->import_patrons($params_3a) } |
235 |
warning_is { $result_3a = $patrons_import->import_patrons($params_3a) } |
173 |
undef, |
236 |
undef, |
174 |
"No warning raised by import_patrons"; |
237 |
"No warning raised by import_patrons"; |
175 |
|
238 |
|
176 |
# Then ... |
239 |
# Then ... |
177 |
is($result_3a->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons when matched and overwrite set'); |
240 |
is( |
178 |
is($result_3a->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
241 |
$result_3a->{already_in_db}, 0, |
179 |
is($result_3a->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
242 |
'Got the expected 0 already_in_db from import_patrons when matched and overwrite set' |
180 |
|
243 |
); |
181 |
is($result_3a->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched and overwritten'); |
244 |
is( |
182 |
is($result_3a->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
245 |
$result_3a->{errors}->[0]->{duplicate_userid}, undef, |
183 |
is($result_3a->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
246 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
184 |
|
247 |
); |
185 |
is($result_3a->{imported}, 0, 'Got the expected 0 imported result from import_patrons'); |
248 |
is( |
186 |
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
249 |
$result_3a->{errors}->[0]->{userid}, undef, |
187 |
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); |
250 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
188 |
|
251 |
); |
189 |
my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' }); |
252 |
|
|
|
253 |
is( |
254 |
$result_3a->{feedback}->[0]->{feedback}, 1, |
255 |
'Got 1 expected feedback from import_patrons that matched and overwritten' |
256 |
); |
257 |
is( |
258 |
$result_3a->{feedback}->[0]->{name}, 'headerrow', |
259 |
'Got the expected header row name from import_patrons with duplicate userid' |
260 |
); |
261 |
is( |
262 |
$result_3a->{feedback}->[0]->{value}, $res_header, |
263 |
'Got the expected header row value from import_patrons with duplicate userid' |
264 |
); |
265 |
|
266 |
is( $result_3a->{imported}, 0, 'Got the expected 0 imported result from import_patrons' ); |
267 |
is( $result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons' ); |
268 |
is( $result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched' ); |
269 |
|
270 |
my $patron_3 = Koha::Patrons->find( { cardnumber => '1000' } ); |
190 |
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" ); |
271 |
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" ); |
191 |
|
272 |
|
192 |
# Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from |
273 |
# Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from |
193 |
# overwrite but firstname is not |
274 |
# overwrite but firstname is not |
194 |
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b); |
275 |
my $filename_3c = make_csv( $temp_dir, $csv_headers, $csv_one_line_b ); |
195 |
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!"; |
276 |
open( my $handle_3c, "<", $filename_3c ) or die "cannot open < $filename_3: $!"; |
196 |
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_today => 1 }; |
277 |
my $params_3c = { |
|
|
278 |
file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => ['firstname'], |
279 |
update_dateexpiry => 1, update_dateexpiry_from_today => 1 |
280 |
}; |
197 |
|
281 |
|
198 |
# When ... |
282 |
# When ... |
199 |
my $result_3c; |
283 |
my $result_3c; |
200 |
warning_is { $result_3c = $patrons_import->import_patrons($params_3c) } |
284 |
warning_is { $result_3c = $patrons_import->import_patrons($params_3c) } |
201 |
undef, |
285 |
undef, |
202 |
"No warning raised by import_patrons"; |
286 |
"No warning raised by import_patrons"; |
203 |
|
287 |
|
204 |
# Then ... |
288 |
# Then ... |
205 |
is($result_3c->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons when matched and overwrite set'); |
289 |
is( |
206 |
is($result_3c->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
290 |
$result_3c->{already_in_db}, 0, |
207 |
is($result_3c->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); |
291 |
'Got the expected 0 already_in_db from import_patrons when matched and overwrite set' |
208 |
|
292 |
); |
209 |
is($result_3c->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched and overwritten'); |
293 |
is( |
210 |
is($result_3c->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
294 |
$result_3c->{errors}->[0]->{duplicate_userid}, undef, |
211 |
is($result_3c->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
295 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
212 |
|
296 |
); |
213 |
is($result_3c->{imported}, 0, 'Got the expected 0 imported result from import_patrons'); |
297 |
is( |
214 |
is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); |
298 |
$result_3c->{errors}->[0]->{userid}, undef, |
215 |
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); |
299 |
'No duplicate userid error from import patrons with duplicate userid (it is our own)' |
216 |
|
300 |
); |
217 |
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' }); |
301 |
|
218 |
is( $patron_3c->dateexpiry, dt_from_string->add( months => 99, end_of_month => 'limit' )->ymd, "Expiration date is correct with update_dateexpiry = true" ); |
302 |
is( |
219 |
|
303 |
$result_3c->{feedback}->[0]->{feedback}, 1, |
220 |
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" ); |
304 |
'Got 1 expected feedback from import_patrons that matched and overwritten' |
|
|
305 |
); |
306 |
is( |
307 |
$result_3c->{feedback}->[0]->{name}, 'headerrow', |
308 |
'Got the expected header row name from import_patrons with duplicate userid' |
309 |
); |
310 |
is( |
311 |
$result_3c->{feedback}->[0]->{value}, $res_header, |
312 |
'Got the expected header row value from import_patrons with duplicate userid' |
313 |
); |
314 |
|
315 |
is( $result_3c->{imported}, 0, 'Got the expected 0 imported result from import_patrons' ); |
316 |
is( $result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons' ); |
317 |
is( $result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched' ); |
318 |
|
319 |
my $patron_3c = Koha::Patrons->find( { cardnumber => '1000' } ); |
320 |
is( |
321 |
$patron_3c->dateexpiry, dt_from_string->add( months => 99, end_of_month => 'limit' )->ymd, |
322 |
"Expiration date is correct with update_dateexpiry = true" |
323 |
); |
324 |
|
325 |
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" ); |
221 |
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" ); |
326 |
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" ); |
222 |
|
327 |
|
223 |
# test update_dateexpiry_from_current |
328 |
# test update_dateexpiry_from_current |
224 |
my $filename_3d = make_csv($temp_dir, $csv_headers, $csv_one_line_b); |
329 |
my $filename_3d = make_csv( $temp_dir, $csv_headers, $csv_one_line_b ); |
225 |
open(my $handle_3d, "<", $filename_3d) or die "cannot open < $filename_3: $!"; |
330 |
open( my $handle_3d, "<", $filename_3d ) or die "cannot open < $filename_3: $!"; |
226 |
$patron_3c->dateexpiry('1980-01-01')->store(); |
331 |
$patron_3c->dateexpiry('1980-01-01')->store(); |
227 |
my $params_3d = { file => $handle_3d, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_existing => 1 }; |
332 |
my $params_3d = { |
|
|
333 |
file => $handle_3d, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => ['firstname'], |
334 |
update_dateexpiry => 1, update_dateexpiry_from_existing => 1 |
335 |
}; |
228 |
warning_is { $patrons_import->import_patrons($params_3d) } |
336 |
warning_is { $patrons_import->import_patrons($params_3d) } |
229 |
undef, |
337 |
undef, |
230 |
"No warning raised by import_patrons"; |
338 |
"No warning raised by import_patrons"; |
231 |
$patron_3c = Koha::Patrons->find({ cardnumber => '1000' }); |
339 |
$patron_3c = Koha::Patrons->find( { cardnumber => '1000' } ); |
232 |
is( $patron_3c->dateexpiry, '1988-04-01', "Expiration date is correct with update_dateexpiry_from_existing => 1" ); |
340 |
is( $patron_3c->dateexpiry, '1988-04-01', "Expiration date is correct with update_dateexpiry_from_existing => 1" ); |
|
|
341 |
|
233 |
# /test update_dateexpiry_from_current |
342 |
# /test update_dateexpiry_from_current |
234 |
|
343 |
|
235 |
# Given ... valid file handle, good matchpoint that does not match and conflicting userid. |
344 |
# Given ... valid file handle, good matchpoint that does not match and conflicting userid. |
236 |
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a); |
345 |
my $filename_3b = make_csv( $temp_dir, $csv_headers, $csv_one_line_a ); |
237 |
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!"; |
346 |
open( my $handle_3b, "<", $filename_3b ) or die "cannot open < $filename_3: $!"; |
238 |
my $params_3b = { file => $handle_3b, matchpoint => 'cardnumber', }; |
347 |
my $params_3b = { file => $handle_3b, matchpoint => 'cardnumber', }; |
239 |
|
348 |
|
240 |
# When ... |
349 |
# When ... |
241 |
my $result_3b = $patrons_import->import_patrons($params_3b); |
350 |
my $result_3b = $patrons_import->import_patrons($params_3b); |
242 |
|
351 |
|
243 |
# Then ... |
352 |
# Then ... |
244 |
is($result_3b->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with duplicate userid'); |
353 |
is( $result_3b->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with duplicate userid' ); |
245 |
is($result_3b->{errors}->[0]->{duplicate_userid}, 1, 'Got the expected duplicate userid error from import patrons with duplicate userid'); |
354 |
is( |
246 |
is($result_3b->{errors}->[0]->{userid}, 'jjenkins0', 'Got the expected userid error from import patrons with duplicate userid'); |
355 |
$result_3b->{errors}->[0]->{duplicate_userid}, 1, |
247 |
|
356 |
'Got the expected duplicate userid error from import patrons with duplicate userid' |
248 |
is($result_3b->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with duplicate userid'); |
357 |
); |
249 |
is($result_3b->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); |
358 |
is( |
250 |
is($result_3b->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); |
359 |
$result_3b->{errors}->[0]->{userid}, 'jjenkins0', |
251 |
|
360 |
'Got the expected userid error from import patrons with duplicate userid' |
252 |
is($result_3b->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid'); |
361 |
); |
253 |
is($result_3b->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid'); |
362 |
|
254 |
is($result_3b->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid'); |
363 |
is( |
|
|
364 |
$result_3b->{feedback}->[0]->{feedback}, 1, |
365 |
'Got the expected 1 feedback from import_patrons with duplicate userid' |
366 |
); |
367 |
is( |
368 |
$result_3b->{feedback}->[0]->{name}, 'headerrow', |
369 |
'Got the expected header row name from import_patrons with duplicate userid' |
370 |
); |
371 |
is( |
372 |
$result_3b->{feedback}->[0]->{value}, $res_header, |
373 |
'Got the expected header row value from import_patrons with duplicate userid' |
374 |
); |
375 |
|
376 |
is( $result_3b->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid' ); |
377 |
is( $result_3b->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid' ); |
378 |
is( $result_3b->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid' ); |
255 |
|
379 |
|
256 |
# Given ... a new input and mocked C4::Context |
380 |
# Given ... a new input and mocked C4::Context |
257 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
381 |
t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 1 ); |
258 |
my $attribute = $builder->build({ source => "BorrowerAttributeType"}); |
382 |
my $attribute = $builder->build( { source => "BorrowerAttributeType" } ); |
259 |
|
383 |
|
260 |
my $csv_headers_a = '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,patron_attributes'; |
384 |
my $csv_headers_a = |
261 |
my $res_header_a = '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, patron_attributes'; |
385 |
'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,patron_attributes'; |
262 |
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,'.$attribute->{code}.':1'; |
386 |
my $res_header_a = |
263 |
my $filename_4 = make_csv($temp_dir, $csv_headers_a, $new_input_line); |
387 |
'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, patron_attributes'; |
264 |
open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!"; |
388 |
my $new_input_line = |
|
|
389 |
'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,' |
390 |
. $attribute->{code} . ':1'; |
391 |
my $filename_4 = make_csv( $temp_dir, $csv_headers_a, $new_input_line ); |
392 |
open( my $handle_4, "<", $filename_4 ) or die "cannot open < $filename_4: $!"; |
265 |
my $params_4 = { file => $handle_4, matchpoint => $attribute->{code}, }; |
393 |
my $params_4 = { file => $handle_4, matchpoint => $attribute->{code}, }; |
266 |
|
394 |
|
267 |
# When ... |
395 |
# When ... |
268 |
my $result_4 = $patrons_import->import_patrons($params_4); |
396 |
my $result_4 = $patrons_import->import_patrons($params_4); |
269 |
|
397 |
|
270 |
# Then ... |
398 |
# Then ... |
271 |
is($result_4->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with extended user'); |
399 |
is( $result_4->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons with extended user' ); |
272 |
is(scalar @{$result_4->{errors}}, 0, 'Got the expected 0 size error array from import_patrons with extended user'); |
400 |
is( scalar @{ $result_4->{errors} }, 0, 'Got the expected 0 size error array from import_patrons with extended user' ); |
273 |
|
401 |
|
274 |
is($result_4->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with extended user'); |
402 |
is( $result_4->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with extended user' ); |
275 |
is($result_4->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with extended user'); |
403 |
is( |
276 |
is($result_4->{feedback}->[0]->{value}, $res_header_a, 'Got the expected header row value from import_patrons with extended user'); |
404 |
$result_4->{feedback}->[0]->{name}, 'headerrow', |
277 |
|
405 |
'Got the expected header row name from import_patrons with extended user' |
278 |
is($result_4->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with extended user'); |
406 |
); |
279 |
is($result_4->{feedback}->[1]->{name}, 'attribute string', 'Got the expected attribute string from import_patrons with extended user'); |
407 |
is( |
280 |
is($result_4->{feedback}->[1]->{value}, $attribute->{code}.':1', 'Got the expected second feedback value from import_patrons with extended user'); |
408 |
$result_4->{feedback}->[0]->{value}, $res_header_a, |
281 |
|
409 |
'Got the expected header row value from import_patrons with extended user' |
282 |
is($result_4->{feedback}->[2]->{feedback}, 1, 'Got the expected third feedback from import_patrons with extended user'); |
410 |
); |
283 |
is($result_4->{feedback}->[2]->{name}, 'lastimported', 'Got the expected last imported name from import_patrons with extended user'); |
411 |
|
284 |
like($result_4->{feedback}->[2]->{value}, qr/^Donna \/ \d+/, 'Got the expected third feedback value from import_patrons with extended user'); |
412 |
is( |
285 |
|
413 |
$result_4->{feedback}->[1]->{feedback}, 1, |
286 |
is($result_4->{imported}, 1, 'Got the expected 1 imported result from import_patrons with extended user'); |
414 |
'Got the expected second feedback from import_patrons with extended user' |
287 |
is($result_4->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with extended user'); |
415 |
); |
288 |
is($result_4->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with extended user'); |
416 |
is( |
289 |
|
417 |
$result_4->{feedback}->[1]->{name}, 'attribute string', |
290 |
seek $handle_4,0,0; #Reset to verify finding a matched patron works |
418 |
'Got the expected attribute string from import_patrons with extended user' |
|
|
419 |
); |
420 |
is( |
421 |
$result_4->{feedback}->[1]->{value}, $attribute->{code} . ':1', |
422 |
'Got the expected second feedback value from import_patrons with extended user' |
423 |
); |
424 |
|
425 |
is( |
426 |
$result_4->{feedback}->[2]->{feedback}, 1, |
427 |
'Got the expected third feedback from import_patrons with extended user' |
428 |
); |
429 |
is( |
430 |
$result_4->{feedback}->[2]->{name}, 'lastimported', |
431 |
'Got the expected last imported name from import_patrons with extended user' |
432 |
); |
433 |
like( |
434 |
$result_4->{feedback}->[2]->{value}, qr/^Donna \/ \d+/, |
435 |
'Got the expected third feedback value from import_patrons with extended user' |
436 |
); |
437 |
|
438 |
is( $result_4->{imported}, 1, 'Got the expected 1 imported result from import_patrons with extended user' ); |
439 |
is( $result_4->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with extended user' ); |
440 |
is( $result_4->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with extended user' ); |
441 |
|
442 |
seek $handle_4, 0, 0; #Reset to verify finding a matched patron works |
291 |
my $result_4a = $patrons_import->import_patrons($params_4); |
443 |
my $result_4a = $patrons_import->import_patrons($params_4); |
292 |
is($result_4a->{already_in_db}, 1, 'Got the expected 1 already_in_db from import_patrons with extended user matched'); |
444 |
is( $result_4a->{already_in_db}, 1, 'Got the expected 1 already_in_db from import_patrons with extended user matched' ); |
293 |
is(scalar @{$result_4->{errors}}, 0, 'Got the expected 0 size error array from import_patrons with extended user matched'); |
445 |
is( |
294 |
|
446 |
scalar @{ $result_4->{errors} }, 0, |
295 |
is($result_4a->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons with extended user matched'); |
447 |
'Got the expected 0 size error array from import_patrons with extended user matched' |
296 |
is($result_4a->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with extended user matched'); |
448 |
); |
297 |
is($result_4a->{feedback}->[0]->{value}, $res_header_a, 'Got the expected header row value from import_patrons with extended user matched'); |
449 |
|
298 |
|
450 |
is( |
299 |
is($result_4a->{feedback}->[1]->{feedback}, 1, 'Got the expected second feedback from import_patrons with extended user matched'); |
451 |
$result_4a->{feedback}->[0]->{feedback}, 1, |
300 |
is($result_4a->{feedback}->[1]->{name}, 'attribute string', 'Got the expected attribute string from import_patrons with extended user matched'); |
452 |
'Got the expected 1 feedback from import_patrons with extended user matched' |
301 |
is($result_4a->{feedback}->[1]->{value}, $attribute->{code}.':1', 'Got the expected second feedback value from import_patrons with extended user matched'); |
453 |
); |
|
|
454 |
is( |
455 |
$result_4a->{feedback}->[0]->{name}, 'headerrow', |
456 |
'Got the expected header row name from import_patrons with extended user matched' |
457 |
); |
458 |
is( |
459 |
$result_4a->{feedback}->[0]->{value}, $res_header_a, |
460 |
'Got the expected header row value from import_patrons with extended user matched' |
461 |
); |
462 |
|
463 |
is( |
464 |
$result_4a->{feedback}->[1]->{feedback}, 1, |
465 |
'Got the expected second feedback from import_patrons with extended user matched' |
466 |
); |
467 |
is( |
468 |
$result_4a->{feedback}->[1]->{name}, 'attribute string', |
469 |
'Got the expected attribute string from import_patrons with extended user matched' |
470 |
); |
471 |
is( |
472 |
$result_4a->{feedback}->[1]->{value}, $attribute->{code} . ':1', |
473 |
'Got the expected second feedback value from import_patrons with extended user matched' |
474 |
); |
475 |
|
476 |
is( |
477 |
$result_4a->{feedback}->[2]->{already_in_db}, '1', |
478 |
'Got the expected already_in_db from import_patrons with extended user matched' |
479 |
); |
480 |
like( |
481 |
$result_4a->{feedback}->[2]->{value}, qr/^Donna \/ \d+/, |
482 |
'Got the expected third feedback value from import_patrons with extended user matched' |
483 |
); |
484 |
|
485 |
is( $result_4a->{imported}, 0, 'Got the expected 0 imported result from import_patrons with extended user matched' ); |
486 |
is( $result_4a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with extended user matched' ); |
487 |
is( |
488 |
$result_4a->{overwritten}, 0, |
489 |
'Got the expected 0 overwritten result from import_patrons with extended user matched' |
490 |
); |
491 |
|
492 |
t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 0 ); |
493 |
|
494 |
my $surname = 'Chloé❤'; |
302 |
|
495 |
|
303 |
is($result_4a->{feedback}->[2]->{already_in_db}, '1', 'Got the expected already_in_db from import_patrons with extended user matched'); |
|
|
304 |
like($result_4a->{feedback}->[2]->{value}, qr/^Donna \/ \d+/, 'Got the expected third feedback value from import_patrons with extended user matched'); |
305 |
|
306 |
is($result_4a->{imported}, 0, 'Got the expected 0 imported result from import_patrons with extended user matched'); |
307 |
is($result_4a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with extended user matched'); |
308 |
is($result_4a->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with extended user matched'); |
309 |
|
310 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 0); |
311 |
|
312 |
my $surname ='Chloé❤'; |
313 |
# Given ... 3 new inputs. One with no branch code, one with unexpected branch code. |
496 |
# Given ... 3 new inputs. One with no branch code, one with unexpected branch code. |
314 |
my $input_no_branch = qq|1002,$surname,Reynolds,Mr,Patricia,JR,12,Hill,Kennedy,Saint Louis,Colorado Springs,Missouri,63131,United States,preynolds2i\@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|; |
497 |
my $input_no_branch = |
315 |
my $input_good_branch = qq|1003,$surname,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|; |
498 |
qq|1002,$surname,Reynolds,Mr,Patricia,JR,12,Hill,Kennedy,Saint Louis,Colorado Springs,Missouri,63131,United States,preynolds2i\@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|; |
316 |
my $input_na_branch = qq|1005,$surname,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|; |
499 |
my $input_good_branch = |
317 |
|
500 |
qq|1003,$surname,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|; |
318 |
my $filename_5 = make_csv($temp_dir, $csv_headers, encode_utf8($input_no_branch), encode_utf8($input_good_branch), encode_utf8($input_na_branch)); |
501 |
my $input_na_branch = |
319 |
open(my $handle_5, "<", $filename_5) or die "cannot open < $filename_5: $!"; |
502 |
qq|1005,$surname,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|; |
|
|
503 |
|
504 |
my $filename_5 = make_csv( |
505 |
$temp_dir, $csv_headers, encode_utf8($input_no_branch), encode_utf8($input_good_branch), |
506 |
encode_utf8($input_na_branch) |
507 |
); |
508 |
open( my $handle_5, "<", $filename_5 ) or die "cannot open < $filename_5: $!"; |
320 |
my $params_5 = { file => $handle_5, matchpoint => 'cardnumber', }; |
509 |
my $params_5 = { file => $handle_5, matchpoint => 'cardnumber', }; |
321 |
|
510 |
|
322 |
# When ... |
511 |
# When ... |
323 |
my $result_5 = $patrons_import->import_patrons($params_5); |
512 |
my $result_5 = $patrons_import->import_patrons($params_5); |
324 |
|
513 |
|
325 |
# Then ... |
514 |
# Then ... |
326 |
is($result_5->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for branch tests'); |
515 |
is( $result_5->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for branch tests' ); |
327 |
|
516 |
|
328 |
is($result_5->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for branch tests'); |
517 |
is( |
329 |
is($result_5->{errors}->[0]->{missing_criticals}->[0]->{key}, 'branchcode', 'Got the expected branch code key from import patrons for branch tests'); |
518 |
$result_5->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', |
330 |
is($result_5->{errors}->[0]->{missing_criticals}->[0]->{line}, 2, 'Got the expected 2 line number error from import patrons for branch tests'); |
519 |
'Got the expected undef borrower number error from import patrons for branch tests' |
331 |
is($result_5->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_branch."\r\n", 'Got the expected lineraw error from import patrons for branch tests'); |
520 |
); |
332 |
is($result_5->{errors}->[0]->{missing_criticals}->[0]->{surname}, $surname, 'Got the expected surname error from import patrons for branch tests'); |
521 |
is( |
333 |
|
522 |
$result_5->{errors}->[0]->{missing_criticals}->[0]->{key}, 'branchcode', |
334 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for branch tests'); |
523 |
'Got the expected branch code key from import patrons for branch tests' |
335 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{branch_map}, 1, 'Got the expected 1 branchmap error from import patrons for branch tests'); |
524 |
); |
336 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{key}, 'branchcode', 'Got the expected branch code key from import patrons for branch tests'); |
525 |
is( |
337 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{line}, 4, 'Got the expected 4 line number error from import patrons for branch tests'); |
526 |
$result_5->{errors}->[0]->{missing_criticals}->[0]->{line}, 2, |
338 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{lineraw}, $input_na_branch."\r\n", 'Got the expected lineraw error from import patrons for branch tests'); |
527 |
'Got the expected 2 line number error from import patrons for branch tests' |
339 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{surname}, $surname, 'Got the expected surname error from import patrons for branch tests'); |
528 |
); |
340 |
is($result_5->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZZ', 'Got the expected ZZZ value error from import patrons for branch tests'); |
529 |
is( |
341 |
|
530 |
$result_5->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_branch . "\r\n", |
342 |
is($result_5->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
531 |
'Got the expected lineraw error from import patrons for branch tests' |
343 |
is($result_5->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for branch tests'); |
532 |
); |
344 |
is($result_5->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for branch tests'); |
533 |
is( |
345 |
|
534 |
$result_5->{errors}->[0]->{missing_criticals}->[0]->{surname}, $surname, |
346 |
is($result_5->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests'); |
535 |
'Got the expected surname error from import patrons for branch tests' |
347 |
is($result_5->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for branch tests'); |
536 |
); |
348 |
like($result_5->{feedback}->[1]->{value}, qr/^$surname \/ \d+/, 'Got the expected last imported value from import_patrons with for branch tests'); |
537 |
|
349 |
|
538 |
is( |
350 |
is($result_5->{imported}, 1, 'Got the expected 1 imported result from import patrons for branch tests'); |
539 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', |
351 |
is($result_5->{invalid}, 2, 'Got the expected 2 invalid result from import patrons for branch tests'); |
540 |
'Got the expected undef borrower number error from import patrons for branch tests' |
352 |
is($result_5->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for branch tests'); |
541 |
); |
|
|
542 |
is( |
543 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{branch_map}, 1, |
544 |
'Got the expected 1 branchmap error from import patrons for branch tests' |
545 |
); |
546 |
is( |
547 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{key}, 'branchcode', |
548 |
'Got the expected branch code key from import patrons for branch tests' |
549 |
); |
550 |
is( |
551 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{line}, 4, |
552 |
'Got the expected 4 line number error from import patrons for branch tests' |
553 |
); |
554 |
is( |
555 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{lineraw}, $input_na_branch . "\r\n", |
556 |
'Got the expected lineraw error from import patrons for branch tests' |
557 |
); |
558 |
is( |
559 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{surname}, $surname, |
560 |
'Got the expected surname error from import patrons for branch tests' |
561 |
); |
562 |
is( |
563 |
$result_5->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZZ', |
564 |
'Got the expected ZZZ value error from import patrons for branch tests' |
565 |
); |
566 |
|
567 |
is( $result_5->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests' ); |
568 |
is( |
569 |
$result_5->{feedback}->[0]->{name}, 'headerrow', |
570 |
'Got the expected header row name from import_patrons for branch tests' |
571 |
); |
572 |
is( |
573 |
$result_5->{feedback}->[0]->{value}, $res_header, |
574 |
'Got the expected header row value from import_patrons for branch tests' |
575 |
); |
576 |
|
577 |
is( $result_5->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for branch tests' ); |
578 |
is( |
579 |
$result_5->{feedback}->[1]->{name}, 'lastimported', |
580 |
'Got the expected lastimported name from import_patrons for branch tests' |
581 |
); |
582 |
like( |
583 |
$result_5->{feedback}->[1]->{value}, qr/^$surname \/ \d+/, |
584 |
'Got the expected last imported value from import_patrons with for branch tests' |
585 |
); |
586 |
|
587 |
is( $result_5->{imported}, 1, 'Got the expected 1 imported result from import patrons for branch tests' ); |
588 |
is( $result_5->{invalid}, 2, 'Got the expected 2 invalid result from import patrons for branch tests' ); |
589 |
is( $result_5->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for branch tests' ); |
353 |
|
590 |
|
354 |
# Given ... 3 new inputs. One with no category code, one with unexpected category code. |
591 |
# Given ... 3 new inputs. One with no category code, one with unexpected category code. |
355 |
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'; |
592 |
my $input_no_category = |
356 |
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'; |
593 |
'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'; |
357 |
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'; |
594 |
my $input_good_category = |
358 |
|
595 |
'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'; |
359 |
my $filename_6 = make_csv($temp_dir, $csv_headers, $input_no_category, $input_good_category, $input_na_category); |
596 |
my $input_na_category = |
360 |
open(my $handle_6, "<", $filename_6) or die "cannot open < $filename_6: $!"; |
597 |
'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'; |
|
|
598 |
|
599 |
my $filename_6 = make_csv( $temp_dir, $csv_headers, $input_no_category, $input_good_category, $input_na_category ); |
600 |
open( my $handle_6, "<", $filename_6 ) or die "cannot open < $filename_6: $!"; |
361 |
my $params_6 = { file => $handle_6, matchpoint => 'cardnumber', }; |
601 |
my $params_6 = { file => $handle_6, matchpoint => 'cardnumber', }; |
362 |
|
602 |
|
363 |
# When ... |
603 |
# When ... |
364 |
my $result_6 = $patrons_import->import_patrons($params_6); |
604 |
my $result_6 = $patrons_import->import_patrons($params_6); |
365 |
|
605 |
|
366 |
# Then ... |
606 |
# Then ... |
367 |
is($result_6->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for category tests'); |
607 |
is( $result_6->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for category tests' ); |
368 |
|
608 |
|
369 |
is($result_6->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for category tests'); |
609 |
is( |
370 |
is($result_6->{errors}->[0]->{missing_criticals}->[0]->{key}, 'categorycode', 'Got the expected category code key from import patrons for category tests'); |
610 |
$result_6->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', |
371 |
is($result_6->{errors}->[0]->{missing_criticals}->[0]->{line}, 2, 'Got the expected 2 line number error from import patrons for category tests'); |
611 |
'Got the expected undef borrower number error from import patrons for category tests' |
372 |
is($result_6->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_category."\r\n", 'Got the expected lineraw error from import patrons for category tests'); |
612 |
); |
373 |
is($result_6->{errors}->[0]->{missing_criticals}->[0]->{surname}, 'Christina', 'Got the expected surname error from import patrons for category tests'); |
613 |
is( |
374 |
|
614 |
$result_6->{errors}->[0]->{missing_criticals}->[0]->{key}, 'categorycode', |
375 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for category tests'); |
615 |
'Got the expected category code key from import patrons for category tests' |
376 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{category_map}, 1, 'Got the expected 1 category_map error from import patrons for category tests'); |
616 |
); |
377 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{key}, 'categorycode', 'Got the expected category code key from import patrons for category tests'); |
617 |
is( |
378 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{line}, 4, 'Got the expected 4 line number error from import patrons for category tests'); |
618 |
$result_6->{errors}->[0]->{missing_criticals}->[0]->{line}, 2, |
379 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{lineraw}, $input_na_category."\r\n", 'Got the expected lineraw error from import patrons for category tests'); |
619 |
'Got the expected 2 line number error from import patrons for category tests' |
380 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{surname}, 'Emily', 'Got the expected surname error from import patrons for category tests'); |
620 |
); |
381 |
is($result_6->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZ', 'Got the expected ZZ value error from import patrons for category tests'); |
621 |
is( |
382 |
|
622 |
$result_6->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_category . "\r\n", |
383 |
is($result_6->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
623 |
'Got the expected lineraw error from import patrons for category tests' |
384 |
is($result_6->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for category tests'); |
624 |
); |
385 |
is($result_6->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for category tests'); |
625 |
is( |
386 |
|
626 |
$result_6->{errors}->[0]->{missing_criticals}->[0]->{surname}, 'Christina', |
387 |
is($result_6->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests'); |
627 |
'Got the expected surname error from import patrons for category tests' |
388 |
is($result_6->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported name from import_patrons for category tests'); |
628 |
); |
389 |
like($result_6->{feedback}->[1]->{value}, qr/^Peter \/ \d+/, 'Got the expected last imported value from import_patrons with for category tests'); |
629 |
|
390 |
|
630 |
is( |
391 |
is($result_6->{imported}, 1, 'Got the expected 1 imported result from import patrons for category tests'); |
631 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', |
392 |
is($result_6->{invalid}, 2, 'Got the expected 2 invalid result from import patrons for category tests'); |
632 |
'Got the expected undef borrower number error from import patrons for category tests' |
393 |
is($result_6->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for category tests'); |
633 |
); |
|
|
634 |
is( |
635 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{category_map}, 1, |
636 |
'Got the expected 1 category_map error from import patrons for category tests' |
637 |
); |
638 |
is( |
639 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{key}, 'categorycode', |
640 |
'Got the expected category code key from import patrons for category tests' |
641 |
); |
642 |
is( |
643 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{line}, 4, |
644 |
'Got the expected 4 line number error from import patrons for category tests' |
645 |
); |
646 |
is( |
647 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{lineraw}, $input_na_category . "\r\n", |
648 |
'Got the expected lineraw error from import patrons for category tests' |
649 |
); |
650 |
is( |
651 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{surname}, 'Emily', |
652 |
'Got the expected surname error from import patrons for category tests' |
653 |
); |
654 |
is( |
655 |
$result_6->{errors}->[1]->{missing_criticals}->[0]->{value}, 'ZZ', |
656 |
'Got the expected ZZ value error from import patrons for category tests' |
657 |
); |
658 |
|
659 |
is( $result_6->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests' ); |
660 |
is( |
661 |
$result_6->{feedback}->[0]->{name}, 'headerrow', |
662 |
'Got the expected header row name from import_patrons for category tests' |
663 |
); |
664 |
is( |
665 |
$result_6->{feedback}->[0]->{value}, $res_header, |
666 |
'Got the expected header row value from import_patrons for category tests' |
667 |
); |
668 |
|
669 |
is( $result_6->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for category tests' ); |
670 |
is( |
671 |
$result_6->{feedback}->[1]->{name}, 'lastimported', |
672 |
'Got the expected lastimported name from import_patrons for category tests' |
673 |
); |
674 |
like( |
675 |
$result_6->{feedback}->[1]->{value}, qr/^Peter \/ \d+/, |
676 |
'Got the expected last imported value from import_patrons with for category tests' |
677 |
); |
678 |
|
679 |
is( $result_6->{imported}, 1, 'Got the expected 1 imported result from import patrons for category tests' ); |
680 |
is( $result_6->{invalid}, 2, 'Got the expected 2 invalid result from import patrons for category tests' ); |
681 |
is( $result_6->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for category tests' ); |
394 |
|
682 |
|
395 |
# Given ... 2 new inputs. One without dateofbirth, dateenrolled and dateexpiry values. |
683 |
# Given ... 2 new inputs. One without dateofbirth, dateenrolled and dateexpiry values. |
396 |
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'; |
684 |
my $input_complete = |
397 |
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'; |
685 |
'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'; |
|
|
686 |
my $input_no_date = |
687 |
'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'; |
398 |
|
688 |
|
399 |
my $filename_7 = make_csv($temp_dir, $csv_headers, $input_complete, $input_no_date); |
689 |
my $filename_7 = make_csv( $temp_dir, $csv_headers, $input_complete, $input_no_date ); |
400 |
open(my $handle_7, "<", $filename_7) or die "cannot open < $filename_7: $!"; |
690 |
open( my $handle_7, "<", $filename_7 ) or die "cannot open < $filename_7: $!"; |
401 |
my $params_7 = { file => $handle_7, matchpoint => 'cardnumber', }; |
691 |
my $params_7 = { file => $handle_7, matchpoint => 'cardnumber', }; |
402 |
|
692 |
|
403 |
# When ... |
693 |
# When ... |
404 |
my $result_7 = $patrons_import->import_patrons($params_7); |
694 |
my $result_7 = $patrons_import->import_patrons($params_7); |
405 |
|
695 |
|
406 |
# Then ... |
696 |
# Then ... |
407 |
is($result_7->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for dates tests'); |
697 |
is( $result_7->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons for dates tests' ); |
408 |
is(scalar @{$result_7->{errors}}, 1, 'Got the expected 1 error array size from import_patrons for dates tests'); |
698 |
is( scalar @{ $result_7->{errors} }, 1, 'Got the expected 1 error array size from import_patrons for dates tests' ); |
409 |
is(scalar @{$result_7->{errors}->[0]->{missing_criticals}}, 3, 'Got the expected 3 missing critical errors from import_patrons for dates tests'); |
699 |
is( |
410 |
|
700 |
scalar @{ $result_7->{errors}->[0]->{missing_criticals} }, 3, |
411 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{bad_date}, 1, 'Got the expected 1 bad_date error from import patrons for dates tests'); |
701 |
'Got the expected 3 missing critical errors from import_patrons for dates tests' |
412 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', 'Got the expected undef borrower number error from import patrons for dates tests'); |
702 |
); |
413 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{key}, 'dateofbirth', 'Got the expected dateofbirth key from import patrons for dates tests'); |
703 |
|
414 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{line}, 3, 'Got the expected 2 line number error from import patrons for dates tests'); |
704 |
is( |
415 |
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'); |
705 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{bad_date}, 1, |
416 |
is($result_7->{errors}->[0]->{missing_criticals}->[0]->{surname}, 'Ralph', 'Got the expected surname error from import patrons for dates tests'); |
706 |
'Got the expected 1 bad_date error from import patrons for dates tests' |
417 |
|
707 |
); |
418 |
is($result_7->{errors}->[0]->{missing_criticals}->[1]->{key}, 'dateenrolled', 'Got the expected dateenrolled key from import patrons for dates tests'); |
708 |
is( |
419 |
is($result_7->{errors}->[0]->{missing_criticals}->[2]->{key}, 'dateexpiry', 'Got the expected dateexpiry key from import patrons for dates tests'); |
709 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{borrowernumber}, 'UNDEF', |
420 |
|
710 |
'Got the expected undef borrower number error from import patrons for dates tests' |
421 |
is(scalar @{$result_7->{feedback}}, 2, 'Got the expected 2 feedback from import patrons for dates tests'); |
711 |
); |
422 |
is($result_7->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests'); |
712 |
is( |
423 |
is($result_7->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons for dates tests'); |
713 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{key}, 'dateofbirth', |
424 |
is($result_7->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons for dates tests'); |
714 |
'Got the expected dateofbirth key from import patrons for dates tests' |
425 |
|
715 |
); |
426 |
is($result_7->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests'); |
716 |
is( |
427 |
is($result_7->{feedback}->[1]->{name}, 'lastimported', 'Got the expected lastimported from import_patrons for dates tests'); |
717 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{line}, 3, |
428 |
like($result_7->{feedback}->[1]->{value}, qr/^Christina \/ \d+/, 'Got the expected lastimported value from import_patrons for dates tests'); |
718 |
'Got the expected 2 line number error from import patrons for dates tests' |
429 |
|
719 |
); |
430 |
is($result_7->{imported}, 1, 'Got the expected 1 imported result from import patrons for dates tests'); |
720 |
is( |
431 |
is($result_7->{invalid}, 1, 'Got the expected 1 invalid result from import patrons for dates tests'); |
721 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{lineraw}, $input_no_date . "\r\n", |
432 |
is($result_7->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for dates tests'); |
722 |
'Got the expected lineraw error from import patrons for dates tests' |
|
|
723 |
); |
724 |
is( |
725 |
$result_7->{errors}->[0]->{missing_criticals}->[0]->{surname}, 'Ralph', |
726 |
'Got the expected surname error from import patrons for dates tests' |
727 |
); |
728 |
|
729 |
is( |
730 |
$result_7->{errors}->[0]->{missing_criticals}->[1]->{key}, 'dateenrolled', |
731 |
'Got the expected dateenrolled key from import patrons for dates tests' |
732 |
); |
733 |
is( |
734 |
$result_7->{errors}->[0]->{missing_criticals}->[2]->{key}, 'dateexpiry', |
735 |
'Got the expected dateexpiry key from import patrons for dates tests' |
736 |
); |
737 |
|
738 |
is( scalar @{ $result_7->{feedback} }, 2, 'Got the expected 2 feedback from import patrons for dates tests' ); |
739 |
is( $result_7->{feedback}->[0]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests' ); |
740 |
is( |
741 |
$result_7->{feedback}->[0]->{name}, 'headerrow', |
742 |
'Got the expected header row name from import_patrons for dates tests' |
743 |
); |
744 |
is( |
745 |
$result_7->{feedback}->[0]->{value}, $res_header, |
746 |
'Got the expected header row value from import_patrons for dates tests' |
747 |
); |
748 |
|
749 |
is( $result_7->{feedback}->[1]->{feedback}, 1, 'Got the expected 1 feedback from import_patrons for dates tests' ); |
750 |
is( |
751 |
$result_7->{feedback}->[1]->{name}, 'lastimported', |
752 |
'Got the expected lastimported from import_patrons for dates tests' |
753 |
); |
754 |
like( |
755 |
$result_7->{feedback}->[1]->{value}, qr/^Christina \/ \d+/, |
756 |
'Got the expected lastimported value from import_patrons for dates tests' |
757 |
); |
758 |
|
759 |
is( $result_7->{imported}, 1, 'Got the expected 1 imported result from import patrons for dates tests' ); |
760 |
is( $result_7->{invalid}, 1, 'Got the expected 1 invalid result from import patrons for dates tests' ); |
761 |
is( $result_7->{overwritten}, 0, 'Got the expected 0 overwritten result from import patrons for dates tests' ); |
433 |
|
762 |
|
434 |
subtest 'test_import_without_cardnumber' => sub { |
763 |
subtest 'test_import_without_cardnumber' => sub { |
435 |
plan tests => 2; |
764 |
plan tests => 2; |
436 |
|
765 |
|
437 |
#Remove possible existing user with a "" as cardnumber |
766 |
#Remove possible existing user with a "" as cardnumber |
438 |
my $blank_card = Koha::Patrons->find({ cardnumber => '' }); |
767 |
my $blank_card = Koha::Patrons->find( { cardnumber => '' } ); |
439 |
$blank_card->delete if $blank_card; |
768 |
$blank_card->delete if $blank_card; |
440 |
|
769 |
|
441 |
my $branchcode = $builder->build({ source => "Branch"})->{branchcode}; |
770 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
442 |
my $categorycode = $builder->build({ source => "Category"})->{categorycode}; |
771 |
my $categorycode = $builder->build( { source => "Category" } )->{categorycode}; |
443 |
my $csv_headers = 'surname, branchcode, categorycode'; |
772 |
my $csv_headers = 'surname, branchcode, categorycode'; |
444 |
my $res_headers = 'surname, branchcode, categorycode'; |
773 |
my $res_headers = 'surname, branchcode, categorycode'; |
445 |
my $csv_nocard_1 = "Squarepants,$branchcode,$categorycode"; |
774 |
my $csv_nocard_1 = "Squarepants,$branchcode,$categorycode"; |
446 |
my $csv_nocard_2 = "Star,$branchcode,$categorycode"; |
775 |
my $csv_nocard_2 = "Star,$branchcode,$categorycode"; |
447 |
|
776 |
|
448 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_nocard_1, $csv_nocard_2); |
777 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_nocard_1, $csv_nocard_2 ); |
449 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
778 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
450 |
my $params_1 = { file => $handle_1, }; |
779 |
my $params_1 = { file => $handle_1, }; |
451 |
|
780 |
|
452 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
781 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
453 |
|
782 |
|
454 |
my $result = $patrons_import->import_patrons($params_1, $defaults); |
783 |
my $result = $patrons_import->import_patrons( $params_1, $defaults ); |
455 |
like($result->{feedback}->[1]->{value}, qr/^Squarepants \/ \d+/, 'First borrower imported as expected'); |
784 |
like( $result->{feedback}->[1]->{value}, qr/^Squarepants \/ \d+/, 'First borrower imported as expected' ); |
456 |
like($result->{feedback}->[2]->{value}, qr/^Star \/ \d+/, 'Second borrower imported as expected'); |
785 |
like( $result->{feedback}->[2]->{value}, qr/^Star \/ \d+/, 'Second borrower imported as expected' ); |
457 |
|
786 |
|
458 |
}; |
787 |
}; |
459 |
|
788 |
|
Lines 461-485
subtest 'test_import_with_cardnumber_0' => sub {
Link Here
|
461 |
plan tests => 2; |
790 |
plan tests => 2; |
462 |
|
791 |
|
463 |
#Remove possible existing user with a "" as cardnumber |
792 |
#Remove possible existing user with a "" as cardnumber |
464 |
my $zero_card = Koha::Patrons->find({ cardnumber => 0 }); |
793 |
my $zero_card = Koha::Patrons->find( { cardnumber => 0 } ); |
465 |
$zero_card->delete if $zero_card; |
794 |
$zero_card->delete if $zero_card; |
466 |
|
795 |
|
467 |
my $branchcode = $builder->build({ source => "Branch"})->{branchcode}; |
796 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
468 |
my $categorycode = $builder->build({ source => "Category"})->{categorycode}; |
797 |
my $categorycode = $builder->build( { source => "Category" } )->{categorycode}; |
469 |
my $csv_headers = 'cardnumber,surname, branchcode, categorycode'; |
798 |
my $csv_headers = 'cardnumber,surname, branchcode, categorycode'; |
470 |
my $res_headers = 'cardnumber,surname, branchcode, categorycode'; |
799 |
my $res_headers = 'cardnumber,surname, branchcode, categorycode'; |
471 |
my $csv_nocard_1 = "0,Squarepants,$branchcode,$categorycode"; |
800 |
my $csv_nocard_1 = "0,Squarepants,$branchcode,$categorycode"; |
472 |
|
801 |
|
473 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_nocard_1); |
802 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_nocard_1 ); |
474 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
803 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
475 |
my $params_1 = { file => $handle_1, }; |
804 |
my $params_1 = { file => $handle_1, }; |
476 |
|
805 |
|
477 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
806 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
478 |
|
807 |
|
479 |
my $result = $patrons_import->import_patrons($params_1, $defaults); |
808 |
my $result = $patrons_import->import_patrons( $params_1, $defaults ); |
480 |
like($result->{feedback}->[1]->{value}, qr/^Squarepants \/ \d+/, 'First borrower imported as expected'); |
809 |
like( $result->{feedback}->[1]->{value}, qr/^Squarepants \/ \d+/, 'First borrower imported as expected' ); |
481 |
$zero_card = Koha::Patrons->find({ cardnumber => 0 }); |
810 |
$zero_card = Koha::Patrons->find( { cardnumber => 0 } ); |
482 |
is($zero_card->surname.$zero_card->branchcode.$zero_card->categorycode,'Squarepants'.$branchcode.$categorycode,"Patron with cardnumber 0 is the imported patron"); |
811 |
is( |
|
|
812 |
$zero_card->surname . $zero_card->branchcode . $zero_card->categorycode, |
813 |
'Squarepants' . $branchcode . $categorycode, "Patron with cardnumber 0 is the imported patron" |
814 |
); |
483 |
|
815 |
|
484 |
}; |
816 |
}; |
485 |
|
817 |
|
Lines 488-494
subtest 'Import patron with guarantor' => sub {
Link Here
|
488 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'guarantor' ); |
820 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'guarantor' ); |
489 |
|
821 |
|
490 |
my $category = $builder->build( { source => 'Category' } )->{categorycode}; |
822 |
my $category = $builder->build( { source => 'Category' } )->{categorycode}; |
491 |
my $branch = $builder->build( { source => 'Branch' } )->{branchcode}; |
823 |
my $branch = $builder->build( { source => 'Branch' } )->{branchcode}; |
492 |
my $guarantor = Koha::Patron->new( |
824 |
my $guarantor = Koha::Patron->new( |
493 |
{ |
825 |
{ |
494 |
surname => 'Guarantor', |
826 |
surname => 'Guarantor', |
Lines 498-513
subtest 'Import patron with guarantor' => sub {
Link Here
|
498 |
)->store(); |
830 |
)->store(); |
499 |
my $guarantor_id = $guarantor->id; |
831 |
my $guarantor_id = $guarantor->id; |
500 |
|
832 |
|
501 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
833 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
502 |
my $categorycode = $builder->build( { source => "Category" } )->{categorycode}; |
834 |
my $categorycode = $builder->build( { source => "Category" } )->{categorycode}; |
503 |
my $csv_headers = 'cardnumber,surname, branchcode, categorycode, guarantor_id, guarantor_relationship'; |
835 |
my $csv_headers = 'cardnumber,surname, branchcode, categorycode, guarantor_id, guarantor_relationship'; |
504 |
my $csv = "kylemhall,Hall,$branchcode,$categorycode,$guarantor_id,guarantor"; |
836 |
my $csv = "kylemhall,Hall,$branchcode,$categorycode,$guarantor_id,guarantor"; |
505 |
|
837 |
|
506 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv ); |
838 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv ); |
507 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
839 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
508 |
my $params_1 = { file => $handle_1, }; |
840 |
my $params_1 = { file => $handle_1, }; |
509 |
|
841 |
|
510 |
my $result = $patrons_import->import_patrons( $params_1 ); |
842 |
my $result = $patrons_import->import_patrons($params_1); |
511 |
like( $result->{feedback}->[1]->{value}, qr/^Hall \/ \d+/, 'First borrower imported as expected' ); |
843 |
like( $result->{feedback}->[1]->{value}, qr/^Hall \/ \d+/, 'First borrower imported as expected' ); |
512 |
my $patron = Koha::Patrons->find( { cardnumber => 'kylemhall' } ); |
844 |
my $patron = Koha::Patrons->find( { cardnumber => 'kylemhall' } ); |
513 |
is( $patron->surname, "Hall", "Patron was created" ); |
845 |
is( $patron->surname, "Hall", "Patron was created" ); |
Lines 521-589
subtest 'test_import_with_password_overwrite' => sub {
Link Here
|
521 |
plan tests => 8; |
853 |
plan tests => 8; |
522 |
|
854 |
|
523 |
#Remove possible existing user to avoid clashes |
855 |
#Remove possible existing user to avoid clashes |
524 |
my $ernest = Koha::Patrons->find({ userid => 'ErnestP' }); |
856 |
my $ernest = Koha::Patrons->find( { userid => 'ErnestP' } ); |
525 |
$ernest->delete if $ernest; |
857 |
$ernest->delete if $ernest; |
526 |
|
858 |
|
527 |
#Setup our info |
859 |
#Setup our info |
528 |
my $branchcode = $builder->build({ source => "Branch"})->{branchcode}; |
860 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
529 |
my $categorycode = $builder->build({ source => "Category", value => { category_type => 'A' } })->{categorycode}; |
861 |
my $categorycode = $builder->build( { source => "Category", value => { category_type => 'A' } } )->{categorycode}; |
530 |
my $staff_categorycode = $builder->build({ source => "Category", value => { category_type => 'S' } })->{categorycode}; |
862 |
my $staff_categorycode = |
531 |
my $csv_headers = 'surname,userid,branchcode,categorycode,password'; |
863 |
$builder->build( { source => "Category", value => { category_type => 'S' } } )->{categorycode}; |
532 |
my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest11"; |
864 |
my $csv_headers = 'surname,userid,branchcode,categorycode,password'; |
|
|
865 |
my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest11"; |
533 |
my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1234"; |
866 |
my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1234"; |
534 |
my $csv_blank_password = "Worel,ErnestP,$branchcode,$categorycode,"; |
867 |
my $csv_blank_password = "Worel,ErnestP,$branchcode,$categorycode,"; |
535 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
868 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
536 |
my $csv_staff_password_change = "Worrell,ErnestP,$branchcode,$staff_categorycode,Vern1234"; |
869 |
my $csv_staff_password_change = "Worrell,ErnestP,$branchcode,$staff_categorycode,Vern1234"; |
537 |
|
870 |
|
538 |
#Make the test files for importing |
871 |
#Make the test files for importing |
539 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_password); |
872 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_password ); |
540 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
873 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
541 |
my $params_1 = { file => $handle_1, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1}; |
874 |
my $params_1 = { file => $handle_1, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1 }; |
542 |
my $filename_2 = make_csv($temp_dir, $csv_headers, $csv_password_change); |
875 |
my $filename_2 = make_csv( $temp_dir, $csv_headers, $csv_password_change ); |
543 |
open(my $handle_2, "<", $filename_2) or die "cannot open < $filename_2: $!"; |
876 |
open( my $handle_2, "<", $filename_2 ) or die "cannot open < $filename_2: $!"; |
544 |
my $params_2 = { file => $handle_2, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1}; |
877 |
my $params_2 = { file => $handle_2, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1 }; |
545 |
|
|
|
546 |
my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_blank_password); |
547 |
open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!"; |
548 |
my $params_3 = { file => $handle_3, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1}; |
549 |
|
878 |
|
550 |
my $filename_4 = make_csv($temp_dir, $csv_headers, $csv_staff_password_change); |
879 |
my $filename_3 = make_csv( $temp_dir, $csv_headers, $csv_blank_password ); |
551 |
open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!"; |
880 |
open( my $handle_3, "<", $filename_3 ) or die "cannot open < $filename_3: $!"; |
552 |
my $params_4 = { file => $handle_4, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1}; |
881 |
my $params_3 = { file => $handle_3, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1 }; |
553 |
|
882 |
|
|
|
883 |
my $filename_4 = make_csv( $temp_dir, $csv_headers, $csv_staff_password_change ); |
884 |
open( my $handle_4, "<", $filename_4 ) or die "cannot open < $filename_4: $!"; |
885 |
my $params_4 = { file => $handle_4, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1 }; |
554 |
|
886 |
|
555 |
my $result = $patrons_import->import_patrons($params_1, $defaults); |
887 |
my $result = $patrons_import->import_patrons( $params_1, $defaults ); |
556 |
like($result->{feedback}->[1]->{value}, qr/^Worrell \/ \d+/, 'First borrower imported as expected'); |
888 |
like( $result->{feedback}->[1]->{value}, qr/^Worrell \/ \d+/, 'First borrower imported as expected' ); |
557 |
$ernest = Koha::Patrons->find({ userid => 'ErnestP' }); |
889 |
$ernest = Koha::Patrons->find( { userid => 'ErnestP' } ); |
558 |
isnt($ernest->password,'Ernest',"New patron is imported, password is encrypted"); |
890 |
isnt( $ernest->password, 'Ernest', "New patron is imported, password is encrypted" ); |
559 |
|
891 |
|
560 |
#Save info to double check |
892 |
#Save info to double check |
561 |
my $orig_pass = $ernest->password; |
893 |
my $orig_pass = $ernest->password; |
562 |
|
894 |
|
563 |
$result = $patrons_import->import_patrons($params_2, $defaults); |
895 |
$result = $patrons_import->import_patrons( $params_2, $defaults ); |
564 |
$ernest = Koha::Patrons->find({ userid => 'ErnestP' }); |
896 |
$ernest = Koha::Patrons->find( { userid => 'ErnestP' } ); |
565 |
isnt($ernest->password,$orig_pass,"New patron is overwritten, password is overwritten"); |
897 |
isnt( $ernest->password, $orig_pass, "New patron is overwritten, password is overwritten" ); |
566 |
isnt($ernest->password,'Vern',"Password is overwritten and is encrypted from value provided"); |
898 |
isnt( $ernest->password, 'Vern', "Password is overwritten and is encrypted from value provided" ); |
567 |
|
899 |
|
568 |
#Save info to check not changed |
900 |
#Save info to check not changed |
569 |
$orig_pass = $ernest->password; |
901 |
$orig_pass = $ernest->password; |
570 |
|
902 |
|
571 |
$result = $patrons_import->import_patrons($params_3, $defaults); |
903 |
$result = $patrons_import->import_patrons( $params_3, $defaults ); |
572 |
$ernest = Koha::Patrons->find({ userid => 'ErnestP' }); |
904 |
$ernest = Koha::Patrons->find( { userid => 'ErnestP' } ); |
573 |
is($ernest->surname,'Worel',"Patron is overwritten, surname changed"); |
905 |
is( $ernest->surname, 'Worel', "Patron is overwritten, surname changed" ); |
574 |
is($ernest->password,$orig_pass,"Patron was overwritten but password is not overwritten if blank"); |
906 |
is( $ernest->password, $orig_pass, "Patron was overwritten but password is not overwritten if blank" ); |
575 |
|
907 |
|
576 |
$ernest->category($staff_categorycode); |
908 |
$ernest->category($staff_categorycode); |
577 |
$ernest->store; |
909 |
$ernest->store; |
578 |
|
910 |
|
579 |
$result = $patrons_import->import_patrons($params_4, $defaults); |
911 |
$result = $patrons_import->import_patrons( $params_4, $defaults ); |
580 |
$ernest = Koha::Patrons->find({ userid => 'ErnestP' }); |
912 |
$ernest = Koha::Patrons->find( { userid => 'ErnestP' } ); |
581 |
is($ernest->surname,'Worrell',"Patron is overwritten, surname changed"); |
913 |
is( $ernest->surname, 'Worrell', "Patron is overwritten, surname changed" ); |
582 |
is($ernest->password,$orig_pass,"Patron is imported, password is not changed for staff"); |
914 |
is( $ernest->password, $orig_pass, "Patron is imported, password is not changed for staff" ); |
583 |
|
915 |
|
584 |
}; |
916 |
}; |
585 |
|
917 |
|
586 |
|
|
|
587 |
subtest 'test_prepare_columns' => sub { |
918 |
subtest 'test_prepare_columns' => sub { |
588 |
plan tests => 16; |
919 |
plan tests => 16; |
589 |
|
920 |
|
Lines 592-606
subtest 'test_prepare_columns' => sub {
Link Here
|
592 |
my @errors_0; |
923 |
my @errors_0; |
593 |
|
924 |
|
594 |
# When ... |
925 |
# When ... |
595 |
my @csvcolumns_0 = $patrons_import->prepare_columns({headerrow => undef, keycol => \%csvkeycol_0, errors => \@errors_0, }); |
926 |
my @csvcolumns_0 = |
|
|
927 |
$patrons_import->prepare_columns( { headerrow => undef, keycol => \%csvkeycol_0, errors => \@errors_0, } ); |
596 |
|
928 |
|
597 |
# Then ... |
929 |
# Then ... |
598 |
is(scalar @csvcolumns_0, 0, 'Got the expected empty column array from prepare columns with no header row'); |
930 |
is( scalar @csvcolumns_0, 0, 'Got the expected empty column array from prepare columns with no header row' ); |
599 |
|
931 |
|
600 |
is(scalar @errors_0, 1, 'Got the expected 1 entry in error array from prepare columns with no header row'); |
932 |
is( scalar @errors_0, 1, 'Got the expected 1 entry in error array from prepare columns with no header row' ); |
601 |
is($errors_0[0]->{badheader}, 1, 'Got the expected 1 badheader from prepare columns with no header row'); |
933 |
is( $errors_0[0]->{badheader}, 1, 'Got the expected 1 badheader from prepare columns with no header row' ); |
602 |
is($errors_0[0]->{line}, 1, 'Got the expected 1 line from prepare columns with no header row'); |
934 |
is( $errors_0[0]->{line}, 1, 'Got the expected 1 line from prepare columns with no header row' ); |
603 |
is($errors_0[0]->{lineraw}, undef, 'Got the expected undef lineraw from prepare columns with no header row'); |
935 |
is( $errors_0[0]->{lineraw}, undef, 'Got the expected undef lineraw from prepare columns with no header row' ); |
604 |
|
936 |
|
605 |
# Given ... a good header row with plenty of whitespaces |
937 |
# Given ... a good header row with plenty of whitespaces |
606 |
my $headerrow_1 = 'a, b , c, , d'; |
938 |
my $headerrow_1 = 'a, b , c, , d'; |
Lines 608-628
subtest 'test_prepare_columns' => sub {
Link Here
|
608 |
my @errors_1; |
940 |
my @errors_1; |
609 |
|
941 |
|
610 |
# When ... |
942 |
# When ... |
611 |
my @csvcolumns_1 = $patrons_import->prepare_columns({headerrow => $headerrow_1, keycol => \%csvkeycol_1, errors => \@errors_1, }); |
943 |
my @csvcolumns_1 = $patrons_import->prepare_columns( |
|
|
944 |
{ headerrow => $headerrow_1, keycol => \%csvkeycol_1, errors => \@errors_1, } ); |
612 |
|
945 |
|
613 |
# Then ... |
946 |
# Then ... |
614 |
is(scalar @csvcolumns_1, 5, 'Got the expected 5 column array from prepare columns'); |
947 |
is( scalar @csvcolumns_1, 5, 'Got the expected 5 column array from prepare columns' ); |
615 |
is($csvcolumns_1[0], 'a', 'Got the expected a header from prepare columns'); |
948 |
is( $csvcolumns_1[0], 'a', 'Got the expected a header from prepare columns' ); |
616 |
is($csvcolumns_1[1], 'b', 'Got the expected b header from prepare columns'); |
949 |
is( $csvcolumns_1[1], 'b', 'Got the expected b header from prepare columns' ); |
617 |
is($csvcolumns_1[2], 'c', 'Got the expected c header from prepare columns'); |
950 |
is( $csvcolumns_1[2], 'c', 'Got the expected c header from prepare columns' ); |
618 |
is($csvcolumns_1[3], '', 'Got the expected empty header from prepare columns'); |
951 |
is( $csvcolumns_1[3], '', 'Got the expected empty header from prepare columns' ); |
619 |
is($csvcolumns_1[4], 'd', 'Got the expected d header from prepare columns'); |
952 |
is( $csvcolumns_1[4], 'd', 'Got the expected d header from prepare columns' ); |
620 |
|
953 |
|
621 |
is($csvkeycol_1{a}, 0, 'Got the expected 0 value for key a from prepare columns hash'); |
954 |
is( $csvkeycol_1{a}, 0, 'Got the expected 0 value for key a from prepare columns hash' ); |
622 |
is($csvkeycol_1{b}, 1, 'Got the expected 1 value for key b from prepare columns hash'); |
955 |
is( $csvkeycol_1{b}, 1, 'Got the expected 1 value for key b from prepare columns hash' ); |
623 |
is($csvkeycol_1{c}, 2, 'Got the expected 2 value for key c from prepare columns hash'); |
956 |
is( $csvkeycol_1{c}, 2, 'Got the expected 2 value for key c from prepare columns hash' ); |
624 |
is($csvkeycol_1{''}, 3, 'Got the expected 3 value for empty string key from prepare columns hash'); |
957 |
is( $csvkeycol_1{''}, 3, 'Got the expected 3 value for empty string key from prepare columns hash' ); |
625 |
is($csvkeycol_1{d}, 4, 'Got the expected 4 value for key d from prepare columns hash'); |
958 |
is( $csvkeycol_1{d}, 4, 'Got the expected 4 value for key d from prepare columns hash' ); |
626 |
}; |
959 |
}; |
627 |
|
960 |
|
628 |
subtest 'test_set_column_keys' => sub { |
961 |
subtest 'test_set_column_keys' => sub { |
Lines 631-651
subtest 'test_set_column_keys' => sub {
Link Here
|
631 |
# Given ... nothing at all |
964 |
# Given ... nothing at all |
632 |
# When ... Then ... |
965 |
# When ... Then ... |
633 |
my $attr_type_0 = $patrons_import->set_attribute_types(undef); |
966 |
my $attr_type_0 = $patrons_import->set_attribute_types(undef); |
634 |
is($attr_type_0, undef, 'Got the expected undef attribute type from set attribute types with nothing'); |
967 |
is( $attr_type_0, undef, 'Got the expected undef attribute type from set attribute types with nothing' ); |
635 |
|
968 |
|
636 |
# Given ... extended but not matchpoint |
969 |
# Given ... extended but not matchpoint |
637 |
my $params_1 = { extended => 1, matchpoint => undef, }; |
970 |
my $params_1 = { extended => 1, matchpoint => undef, }; |
638 |
|
971 |
|
639 |
# When ... Then ... |
972 |
# When ... Then ... |
640 |
my $attr_type_1 = $patrons_import->set_attribute_types($params_1); |
973 |
my $attr_type_1 = $patrons_import->set_attribute_types($params_1); |
641 |
is($attr_type_1, undef, 'Got the expected undef attribute type from set attribute types with no matchpoint'); |
974 |
is( $attr_type_1, undef, 'Got the expected undef attribute type from set attribute types with no matchpoint' ); |
642 |
|
975 |
|
643 |
# Given ... extended and unexpected matchpoint |
976 |
# Given ... extended and unexpected matchpoint |
644 |
my $params_2 = { extended => 1, matchpoint => 'unexpected', }; |
977 |
my $params_2 = { extended => 1, matchpoint => 'unexpected', }; |
645 |
|
978 |
|
646 |
# When ... Then ... |
979 |
# When ... Then ... |
647 |
my $attr_type_2 = $patrons_import->set_attribute_types($params_2); |
980 |
my $attr_type_2 = $patrons_import->set_attribute_types($params_2); |
648 |
is($attr_type_2, undef, 'Got the expected undef attribute type from set attribute types with unexpected matchpoint'); |
981 |
is( |
|
|
982 |
$attr_type_2, undef, |
983 |
'Got the expected undef attribute type from set attribute types with unexpected matchpoint' |
984 |
); |
649 |
|
985 |
|
650 |
# Given ... |
986 |
# Given ... |
651 |
my $code_3 = 'SHOW_BCODE'; |
987 |
my $code_3 = 'SHOW_BCODE'; |
Lines 655-681
subtest 'test_set_column_keys' => sub {
Link Here
|
655 |
my $attr_type_3 = $patrons_import->set_attribute_types($params_3); |
991 |
my $attr_type_3 = $patrons_import->set_attribute_types($params_3); |
656 |
|
992 |
|
657 |
# Then ... |
993 |
# Then ... |
658 |
isa_ok($attr_type_3, 'Koha::Patron::Attribute::Type'); |
994 |
isa_ok( $attr_type_3, 'Koha::Patron::Attribute::Type' ); |
659 |
is($attr_type_3->code, $code_3, 'Got the expected code attribute type from set attribute types'); |
995 |
is( $attr_type_3->code, $code_3, 'Got the expected code attribute type from set attribute types' ); |
660 |
}; |
996 |
}; |
661 |
|
997 |
|
662 |
subtest 'test_set_column_keys' => sub { |
998 |
subtest 'test_set_column_keys' => sub { |
663 |
plan tests => 2; |
999 |
plan tests => 2; |
664 |
|
1000 |
|
665 |
my @columns = Koha::Patrons->columns; |
1001 |
my @columns = Koha::Patrons->columns; |
|
|
1002 |
|
666 |
# Given ... nothing at all |
1003 |
# Given ... nothing at all |
667 |
# When ... Then ... |
1004 |
# When ... Then ... |
668 |
my @columnkeys_0 = $patrons_import->set_column_keys(undef); |
1005 |
my @columnkeys_0 = $patrons_import->set_column_keys(undef); |
|
|
1006 |
|
669 |
# -1 because we do not want the borrowernumber column |
1007 |
# -1 because we do not want the borrowernumber column |
670 |
# +2 for guarantor id and guarantor relationship |
1008 |
# +2 for guarantor id and guarantor relationship |
671 |
is(scalar @columnkeys_0, @columns - 1 + 2, 'Got the expected array size from set column keys with undef extended'); |
1009 |
is( |
|
|
1010 |
scalar @columnkeys_0, @columns - 1 + 2, |
1011 |
'Got the expected array size from set column keys with undef extended' |
1012 |
); |
672 |
|
1013 |
|
673 |
# Given ... extended. |
1014 |
# Given ... extended. |
674 |
my $extended = 1; |
1015 |
my $extended = 1; |
675 |
|
1016 |
|
676 |
# When ... Then ... |
1017 |
# When ... Then ... |
677 |
my @columnkeys_1 = $patrons_import->set_column_keys($extended); |
1018 |
my @columnkeys_1 = $patrons_import->set_column_keys($extended); |
678 |
is(scalar @columnkeys_1, @columns - 1 + 2 + $extended, 'Got the expected array size from set column keys with extended'); |
1019 |
is( |
|
|
1020 |
scalar @columnkeys_1, @columns - 1 + 2 + $extended, |
1021 |
'Got the expected array size from set column keys with extended' |
1022 |
); |
679 |
}; |
1023 |
}; |
680 |
|
1024 |
|
681 |
subtest 'test_generate_patron_attributes' => sub { |
1025 |
subtest 'test_generate_patron_attributes' => sub { |
Lines 683-697
subtest 'test_generate_patron_attributes' => sub {
Link Here
|
683 |
|
1027 |
|
684 |
# Given ... nothing at all |
1028 |
# Given ... nothing at all |
685 |
# When ... Then ... |
1029 |
# When ... Then ... |
686 |
my $result_0 = $patrons_import->generate_patron_attributes(undef, undef, undef); |
1030 |
my $result_0 = $patrons_import->generate_patron_attributes( undef, undef, undef ); |
687 |
is($result_0, undef, 'Got the expected undef from set patron attributes with nothing'); |
1031 |
is( $result_0, undef, 'Got the expected undef from set patron attributes with nothing' ); |
688 |
|
1032 |
|
689 |
# Given ... not extended. |
1033 |
# Given ... not extended. |
690 |
my $extended_1 = 0; |
1034 |
my $extended_1 = 0; |
691 |
|
1035 |
|
692 |
# When ... Then ... |
1036 |
# When ... Then ... |
693 |
my $result_1 = $patrons_import->generate_patron_attributes($extended_1, undef, undef); |
1037 |
my $result_1 = $patrons_import->generate_patron_attributes( $extended_1, undef, undef ); |
694 |
is($result_1, undef, 'Got the expected undef from set patron attributes with not extended'); |
1038 |
is( $result_1, undef, 'Got the expected undef from set patron attributes with not extended' ); |
695 |
|
1039 |
|
696 |
# Given ... NO patrons attributes |
1040 |
# Given ... NO patrons attributes |
697 |
my $extended_2 = 1; |
1041 |
my $extended_2 = 1; |
Lines 699-729
subtest 'test_generate_patron_attributes' => sub {
Link Here
|
699 |
my @feedback_2; |
1043 |
my @feedback_2; |
700 |
|
1044 |
|
701 |
# When ... |
1045 |
# When ... |
702 |
my $result_2 = $patrons_import->generate_patron_attributes($extended_2, $patron_attributes_2, \@feedback_2); |
1046 |
my $result_2 = $patrons_import->generate_patron_attributes( $extended_2, $patron_attributes_2, \@feedback_2 ); |
703 |
|
1047 |
|
704 |
# Then ... |
1048 |
# Then ... |
705 |
is($result_2, undef, 'Got the expected undef from set patron attributes with no patrons attributes'); |
1049 |
is( $result_2, undef, 'Got the expected undef from set patron attributes with no patrons attributes' ); |
706 |
is(scalar @feedback_2, 0, 'Got the expected 0 size feedback array from set patron attributes with no patrons attributes'); |
1050 |
is( |
|
|
1051 |
scalar @feedback_2, 0, |
1052 |
'Got the expected 0 size feedback array from set patron attributes with no patrons attributes' |
1053 |
); |
707 |
|
1054 |
|
708 |
# Given ... some patrons attributes |
1055 |
# Given ... some patrons attributes |
709 |
my $patron_attributes_3 = "homeroom:1150605,grade:01"; |
1056 |
my $patron_attributes_3 = "homeroom:1150605,grade:01"; |
710 |
my @feedback_3; |
1057 |
my @feedback_3; |
711 |
|
1058 |
|
712 |
# When ... |
1059 |
# When ... |
713 |
my $result_3 = $patrons_import->generate_patron_attributes($extended_2, $patron_attributes_3, \@feedback_3); |
1060 |
my $result_3 = $patrons_import->generate_patron_attributes( $extended_2, $patron_attributes_3, \@feedback_3 ); |
714 |
|
1061 |
|
715 |
# Then ... |
1062 |
# Then ... |
716 |
ok($result_3, 'Got some data back from set patron attributes'); |
1063 |
ok( $result_3, 'Got some data back from set patron attributes' ); |
717 |
is($result_3->[0]->{code}, 'grade', 'Got the expected first code from set patron attributes'); |
1064 |
is( $result_3->[0]->{code}, 'grade', 'Got the expected first code from set patron attributes' ); |
718 |
is($result_3->[0]->{attribute}, '01', 'Got the expected first value from set patron attributes'); |
1065 |
is( $result_3->[0]->{attribute}, '01', 'Got the expected first value from set patron attributes' ); |
719 |
|
1066 |
|
720 |
is($result_3->[1]->{code}, 'homeroom', 'Got the expected second code from set patron attributes'); |
1067 |
is( $result_3->[1]->{code}, 'homeroom', 'Got the expected second code from set patron attributes' ); |
721 |
is($result_3->[1]->{attribute}, 1150605, 'Got the expected second value from set patron attributes'); |
1068 |
is( $result_3->[1]->{attribute}, 1150605, 'Got the expected second value from set patron attributes' ); |
722 |
|
1069 |
|
723 |
is(scalar @feedback_3, 1, 'Got the expected 1 array size from set patron attributes with extended user'); |
1070 |
is( scalar @feedback_3, 1, 'Got the expected 1 array size from set patron attributes with extended user' ); |
724 |
is($feedback_3[0]->{feedback}, 1, 'Got the expected second feedback from set patron attributes with extended user'); |
1071 |
is( |
725 |
is($feedback_3[0]->{name}, 'attribute string', 'Got the expected attribute string from set patron attributes with extended user'); |
1072 |
$feedback_3[0]->{feedback}, 1, |
726 |
is($feedback_3[0]->{value}, 'homeroom:1150605,grade:01', 'Got the expected feedback value from set patron attributes with extended user'); |
1073 |
'Got the expected second feedback from set patron attributes with extended user' |
|
|
1074 |
); |
1075 |
is( |
1076 |
$feedback_3[0]->{name}, 'attribute string', |
1077 |
'Got the expected attribute string from set patron attributes with extended user' |
1078 |
); |
1079 |
is( |
1080 |
$feedback_3[0]->{value}, 'homeroom:1150605,grade:01', |
1081 |
'Got the expected feedback value from set patron attributes with extended user' |
1082 |
); |
727 |
}; |
1083 |
}; |
728 |
|
1084 |
|
729 |
subtest 'test_check_branch_code' => sub { |
1085 |
subtest 'test_check_branch_code' => sub { |
Lines 735-778
subtest 'test_check_branch_code' => sub {
Link Here
|
735 |
my @missing_criticals = (); |
1091 |
my @missing_criticals = (); |
736 |
|
1092 |
|
737 |
# When ... |
1093 |
# When ... |
738 |
$patrons_import->check_branch_code(undef, $borrowerline, $line_number, \@missing_criticals); |
1094 |
$patrons_import->check_branch_code( undef, $borrowerline, $line_number, \@missing_criticals ); |
739 |
|
1095 |
|
740 |
# Then ... |
1096 |
# Then ... |
741 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no branch code'); |
1097 |
is( |
|
|
1098 |
scalar @missing_criticals, 1, |
1099 |
'Got the expected missing critical array size of 1 from check_branch_code with no branch code' |
1100 |
); |
742 |
|
1101 |
|
743 |
is($missing_criticals[0]->{key}, 'branchcode', 'Got the expected branchcode key from check_branch_code with no branch code'); |
1102 |
is( |
744 |
is($missing_criticals[0]->{line}, $line_number, 'Got the expected line number from check_branch_code with no branch code'); |
1103 |
$missing_criticals[0]->{key}, 'branchcode', |
745 |
is($missing_criticals[0]->{lineraw}, $borrowerline, 'Got the expected lineraw value from check_branch_code with no branch code'); |
1104 |
'Got the expected branchcode key from check_branch_code with no branch code' |
|
|
1105 |
); |
1106 |
is( |
1107 |
$missing_criticals[0]->{line}, $line_number, |
1108 |
'Got the expected line number from check_branch_code with no branch code' |
1109 |
); |
1110 |
is( |
1111 |
$missing_criticals[0]->{lineraw}, $borrowerline, |
1112 |
'Got the expected lineraw value from check_branch_code with no branch code' |
1113 |
); |
746 |
|
1114 |
|
747 |
# Given ... unknown branch code |
1115 |
# Given ... unknown branch code |
748 |
my $branchcode_1 = 'unexpected'; |
1116 |
my $branchcode_1 = 'unexpected'; |
749 |
my $borrowerline_1 = 'some, line,'.$branchcode_1; |
1117 |
my $borrowerline_1 = 'some, line,' . $branchcode_1; |
750 |
my $line_number_1 = 79; |
1118 |
my $line_number_1 = 79; |
751 |
my @missing_criticals_1 = (); |
1119 |
my @missing_criticals_1 = (); |
752 |
|
1120 |
|
753 |
# When ... |
1121 |
# When ... |
754 |
$patrons_import->check_branch_code($branchcode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
1122 |
$patrons_import->check_branch_code( $branchcode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1 ); |
755 |
|
1123 |
|
756 |
# Then ... |
1124 |
# Then ... |
757 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected branch code'); |
1125 |
is( |
|
|
1126 |
scalar @missing_criticals_1, 1, |
1127 |
'Got the expected missing critical array size of 1 from check_branch_code with unexpected branch code' |
1128 |
); |
758 |
|
1129 |
|
759 |
is($missing_criticals_1[0]->{branch_map}, 1, 'Got the expected 1 branch_map from check_branch_code with unexpected branch code'); |
1130 |
is( |
760 |
is($missing_criticals_1[0]->{key}, 'branchcode', 'Got the expected branchcode key from check_branch_code with unexpected branch code'); |
1131 |
$missing_criticals_1[0]->{branch_map}, 1, |
761 |
is($missing_criticals_1[0]->{line}, $line_number_1, 'Got the expected line number from check_branch_code with unexpected branch code'); |
1132 |
'Got the expected 1 branch_map from check_branch_code with unexpected branch code' |
762 |
is($missing_criticals_1[0]->{lineraw}, $borrowerline_1, 'Got the expected lineraw value from check_branch_code with unexpected branch code'); |
1133 |
); |
763 |
is($missing_criticals_1[0]->{value}, $branchcode_1, 'Got the expected value from check_branch_code with unexpected branch code'); |
1134 |
is( |
|
|
1135 |
$missing_criticals_1[0]->{key}, 'branchcode', |
1136 |
'Got the expected branchcode key from check_branch_code with unexpected branch code' |
1137 |
); |
1138 |
is( |
1139 |
$missing_criticals_1[0]->{line}, $line_number_1, |
1140 |
'Got the expected line number from check_branch_code with unexpected branch code' |
1141 |
); |
1142 |
is( |
1143 |
$missing_criticals_1[0]->{lineraw}, $borrowerline_1, |
1144 |
'Got the expected lineraw value from check_branch_code with unexpected branch code' |
1145 |
); |
1146 |
is( |
1147 |
$missing_criticals_1[0]->{value}, $branchcode_1, |
1148 |
'Got the expected value from check_branch_code with unexpected branch code' |
1149 |
); |
764 |
|
1150 |
|
765 |
# Given ... a known branch code. Relies on database sample data |
1151 |
# Given ... a known branch code. Relies on database sample data |
766 |
my $branchcode_2 = 'FFL'; |
1152 |
my $branchcode_2 = 'FFL'; |
767 |
my $borrowerline_2 = 'some, line,'.$branchcode_2; |
1153 |
my $borrowerline_2 = 'some, line,' . $branchcode_2; |
768 |
my $line_number_2 = 80; |
1154 |
my $line_number_2 = 80; |
769 |
my @missing_criticals_2 = (); |
1155 |
my @missing_criticals_2 = (); |
770 |
|
1156 |
|
771 |
# When ... |
1157 |
# When ... |
772 |
$patrons_import->check_branch_code($branchcode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
1158 |
$patrons_import->check_branch_code( $branchcode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2 ); |
773 |
|
1159 |
|
774 |
# Then ... |
1160 |
# Then ... |
775 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
1161 |
is( scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code' ); |
776 |
}; |
1162 |
}; |
777 |
|
1163 |
|
778 |
subtest 'test_check_borrower_category' => sub { |
1164 |
subtest 'test_check_borrower_category' => sub { |
Lines 784-827
subtest 'test_check_borrower_category' => sub {
Link Here
|
784 |
my @missing_criticals = (); |
1170 |
my @missing_criticals = (); |
785 |
|
1171 |
|
786 |
# When ... |
1172 |
# When ... |
787 |
$patrons_import->check_borrower_category(undef, $borrowerline, $line_number, \@missing_criticals); |
1173 |
$patrons_import->check_borrower_category( undef, $borrowerline, $line_number, \@missing_criticals ); |
788 |
|
1174 |
|
789 |
# Then ... |
1175 |
# Then ... |
790 |
is(scalar @missing_criticals, 1, 'Got the expected missing critical array size of 1 from check_branch_code with no category code'); |
1176 |
is( |
|
|
1177 |
scalar @missing_criticals, 1, |
1178 |
'Got the expected missing critical array size of 1 from check_branch_code with no category code' |
1179 |
); |
791 |
|
1180 |
|
792 |
is($missing_criticals[0]->{key}, 'categorycode', 'Got the expected categorycode key from check_branch_code with no category code'); |
1181 |
is( |
793 |
is($missing_criticals[0]->{line}, $line_number, 'Got the expected line number from check_branch_code with no category code'); |
1182 |
$missing_criticals[0]->{key}, 'categorycode', |
794 |
is($missing_criticals[0]->{lineraw}, $borrowerline, 'Got the expected lineraw value from check_branch_code with no category code'); |
1183 |
'Got the expected categorycode key from check_branch_code with no category code' |
|
|
1184 |
); |
1185 |
is( |
1186 |
$missing_criticals[0]->{line}, $line_number, |
1187 |
'Got the expected line number from check_branch_code with no category code' |
1188 |
); |
1189 |
is( |
1190 |
$missing_criticals[0]->{lineraw}, $borrowerline, |
1191 |
'Got the expected lineraw value from check_branch_code with no category code' |
1192 |
); |
795 |
|
1193 |
|
796 |
# Given ... unknown category code |
1194 |
# Given ... unknown category code |
797 |
my $categorycode_1 = 'unexpected'; |
1195 |
my $categorycode_1 = 'unexpected'; |
798 |
my $borrowerline_1 = 'some, line, line, '.$categorycode_1; |
1196 |
my $borrowerline_1 = 'some, line, line, ' . $categorycode_1; |
799 |
my $line_number_1 = 791; |
1197 |
my $line_number_1 = 791; |
800 |
my @missing_criticals_1 = (); |
1198 |
my @missing_criticals_1 = (); |
801 |
|
1199 |
|
802 |
# When ... |
1200 |
# When ... |
803 |
$patrons_import->check_borrower_category($categorycode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1); |
1201 |
$patrons_import->check_borrower_category( $categorycode_1, $borrowerline_1, $line_number_1, \@missing_criticals_1 ); |
804 |
|
1202 |
|
805 |
# Then ... |
1203 |
# Then ... |
806 |
is(scalar @missing_criticals_1, 1, 'Got the expected missing critical array size of 1 from check_branch_code with unexpected category code'); |
1204 |
is( |
|
|
1205 |
scalar @missing_criticals_1, 1, |
1206 |
'Got the expected missing critical array size of 1 from check_branch_code with unexpected category code' |
1207 |
); |
807 |
|
1208 |
|
808 |
is($missing_criticals_1[0]->{category_map}, 1, 'Got the expected 1 category_map from check_branch_code with unexpected category code'); |
1209 |
is( |
809 |
is($missing_criticals_1[0]->{key}, 'categorycode', 'Got the expected branchcode key from check_branch_code with unexpected category code'); |
1210 |
$missing_criticals_1[0]->{category_map}, 1, |
810 |
is($missing_criticals_1[0]->{line}, $line_number_1, 'Got the expected line number from check_branch_code with unexpected category code'); |
1211 |
'Got the expected 1 category_map from check_branch_code with unexpected category code' |
811 |
is($missing_criticals_1[0]->{lineraw}, $borrowerline_1, 'Got the expected lineraw value from check_branch_code with unexpected category code'); |
1212 |
); |
812 |
is($missing_criticals_1[0]->{value}, $categorycode_1, 'Got the expected value from check_branch_code with unexpected category code'); |
1213 |
is( |
|
|
1214 |
$missing_criticals_1[0]->{key}, 'categorycode', |
1215 |
'Got the expected branchcode key from check_branch_code with unexpected category code' |
1216 |
); |
1217 |
is( |
1218 |
$missing_criticals_1[0]->{line}, $line_number_1, |
1219 |
'Got the expected line number from check_branch_code with unexpected category code' |
1220 |
); |
1221 |
is( |
1222 |
$missing_criticals_1[0]->{lineraw}, $borrowerline_1, |
1223 |
'Got the expected lineraw value from check_branch_code with unexpected category code' |
1224 |
); |
1225 |
is( |
1226 |
$missing_criticals_1[0]->{value}, $categorycode_1, |
1227 |
'Got the expected value from check_branch_code with unexpected category code' |
1228 |
); |
813 |
|
1229 |
|
814 |
# Given ... a known category code. Relies on database sample data. |
1230 |
# Given ... a known category code. Relies on database sample data. |
815 |
my $categorycode_2 = 'T'; |
1231 |
my $categorycode_2 = 'T'; |
816 |
my $borrowerline_2 = 'some, line,'.$categorycode_2; |
1232 |
my $borrowerline_2 = 'some, line,' . $categorycode_2; |
817 |
my $line_number_2 = 801; |
1233 |
my $line_number_2 = 801; |
818 |
my @missing_criticals_2 = (); |
1234 |
my @missing_criticals_2 = (); |
819 |
|
1235 |
|
820 |
# When ... |
1236 |
# When ... |
821 |
$patrons_import->check_borrower_category($categorycode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2); |
1237 |
$patrons_import->check_borrower_category( $categorycode_2, $borrowerline_2, $line_number_2, \@missing_criticals_2 ); |
822 |
|
1238 |
|
823 |
# Then ... |
1239 |
# Then ... |
824 |
is(scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code'); |
1240 |
is( scalar @missing_criticals_2, 0, 'Got the expected missing critical array size of 0 from check_branch_code' ); |
825 |
}; |
1241 |
}; |
826 |
|
1242 |
|
827 |
subtest 'test_format_dates' => sub { |
1243 |
subtest 'test_format_dates' => sub { |
Lines 832-906
subtest 'test_format_dates' => sub {
Link Here
|
832 |
my $line_number = 987; |
1248 |
my $line_number = 987; |
833 |
my @missing_criticals = (); |
1249 |
my @missing_criticals = (); |
834 |
my %borrower; |
1250 |
my %borrower; |
835 |
my $params = {borrower => \%borrower, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals, }; |
1251 |
my $params = { |
|
|
1252 |
borrower => \%borrower, lineraw => $borrowerline, line => $line_number, |
1253 |
missing_criticals => \@missing_criticals, |
1254 |
}; |
836 |
|
1255 |
|
837 |
# When ... |
1256 |
# When ... |
838 |
$patrons_import->format_dates($params); |
1257 |
$patrons_import->format_dates($params); |
839 |
|
1258 |
|
840 |
# Then ... |
1259 |
# Then ... |
841 |
ok( not(%borrower), 'Got the expected no borrower from format_dates with no dates'); |
1260 |
ok( not(%borrower), 'Got the expected no borrower from format_dates with no dates' ); |
842 |
is(scalar @missing_criticals, 0, 'Got the expected missing critical array size of 0 from format_dates with no dates'); |
1261 |
is( |
|
|
1262 |
scalar @missing_criticals, 0, |
1263 |
'Got the expected missing critical array size of 0 from format_dates with no dates' |
1264 |
); |
843 |
|
1265 |
|
844 |
# Given ... some good dates |
1266 |
# Given ... some good dates |
845 |
my @missing_criticals_1 = (); |
1267 |
my @missing_criticals_1 = (); |
846 |
my $dateofbirth_1 = '2016-05-03'; |
1268 |
my $dateofbirth_1 = '2016-05-03'; |
847 |
my $dateenrolled_1 = '2016-05-04'; |
1269 |
my $dateenrolled_1 = '2016-05-04'; |
848 |
my $dateexpiry_1 = '2016-05-06'; |
1270 |
my $dateexpiry_1 = '2016-05-06'; |
849 |
my $borrower_1 = { dateofbirth => $dateofbirth_1, dateenrolled => $dateenrolled_1, dateexpiry => $dateexpiry_1, }; |
1271 |
my $borrower_1 = { dateofbirth => $dateofbirth_1, dateenrolled => $dateenrolled_1, dateexpiry => $dateexpiry_1, }; |
850 |
my $params_1 = {borrower => $borrower_1, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals_1, }; |
1272 |
my $params_1 = { |
|
|
1273 |
borrower => $borrower_1, lineraw => $borrowerline, line => $line_number, |
1274 |
missing_criticals => \@missing_criticals_1, |
1275 |
}; |
851 |
|
1276 |
|
852 |
# When ... |
1277 |
# When ... |
853 |
$patrons_import->format_dates($params_1); |
1278 |
$patrons_import->format_dates($params_1); |
854 |
|
1279 |
|
855 |
# Then ... |
1280 |
# Then ... |
856 |
is($borrower_1->{dateofbirth}, $dateofbirth_1, 'Got the expected date of birth from format_dates with good dates'); |
1281 |
is( |
857 |
is($borrower_1->{dateenrolled}, $dateenrolled_1, 'Got the expected date of birth from format_dates with good dates'); |
1282 |
$borrower_1->{dateofbirth}, $dateofbirth_1, |
858 |
is($borrower_1->{dateexpiry}, $dateexpiry_1, 'Got the expected date of birth from format_dates with good dates'); |
1283 |
'Got the expected date of birth from format_dates with good dates' |
859 |
is(scalar @missing_criticals_1, 0, 'Got the expected missing critical array size of 0 from check_branch_code with good dates'); |
1284 |
); |
|
|
1285 |
is( |
1286 |
$borrower_1->{dateenrolled}, $dateenrolled_1, |
1287 |
'Got the expected date of birth from format_dates with good dates' |
1288 |
); |
1289 |
is( $borrower_1->{dateexpiry}, $dateexpiry_1, 'Got the expected date of birth from format_dates with good dates' ); |
1290 |
is( |
1291 |
scalar @missing_criticals_1, 0, |
1292 |
'Got the expected missing critical array size of 0 from check_branch_code with good dates' |
1293 |
); |
860 |
|
1294 |
|
861 |
# Given ... some very bad dates |
1295 |
# Given ... some very bad dates |
862 |
my @missing_criticals_2 = (); |
1296 |
my @missing_criticals_2 = (); |
863 |
my $dateofbirth_2 = '03-2016-05'; |
1297 |
my $dateofbirth_2 = '03-2016-05'; |
864 |
my $dateenrolled_2 = '04-2016-05'; |
1298 |
my $dateenrolled_2 = '04-2016-05'; |
865 |
my $dateexpiry_2 = '06-2016-05'; |
1299 |
my $dateexpiry_2 = '06-2016-05'; |
866 |
my $borrower_2 = { dateofbirth => $dateofbirth_2, dateenrolled => $dateenrolled_2, dateexpiry => $dateexpiry_2, }; |
1300 |
my $borrower_2 = { dateofbirth => $dateofbirth_2, dateenrolled => $dateenrolled_2, dateexpiry => $dateexpiry_2, }; |
867 |
my $params_2 = {borrower => $borrower_2, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals_2, }; |
1301 |
my $params_2 = { |
|
|
1302 |
borrower => $borrower_2, lineraw => $borrowerline, line => $line_number, |
1303 |
missing_criticals => \@missing_criticals_2, |
1304 |
}; |
868 |
|
1305 |
|
869 |
# When ... |
1306 |
# When ... |
870 |
$patrons_import->format_dates($params_2); |
1307 |
$patrons_import->format_dates($params_2); |
871 |
|
1308 |
|
872 |
# Then ... |
1309 |
# Then ... |
873 |
is($borrower_2->{dateofbirth}, '', 'Got the expected empty date of birth from format_dates with bad dates'); |
1310 |
is( $borrower_2->{dateofbirth}, '', 'Got the expected empty date of birth from format_dates with bad dates' ); |
874 |
is($borrower_2->{dateenrolled}, '', 'Got the expected emptydate of birth from format_dates with bad dates'); |
1311 |
is( $borrower_2->{dateenrolled}, '', 'Got the expected emptydate of birth from format_dates with bad dates' ); |
875 |
is($borrower_2->{dateexpiry}, '', 'Got the expected empty date of birth from format_dates with bad dates'); |
1312 |
is( $borrower_2->{dateexpiry}, '', 'Got the expected empty date of birth from format_dates with bad dates' ); |
876 |
|
1313 |
|
877 |
is(scalar @missing_criticals_2, 3, 'Got the expected missing critical array size of 3 from check_branch_code with bad dates'); |
1314 |
is( |
878 |
is($missing_criticals_2[0]->{bad_date}, 1, 'Got the expected first bad date flag from check_branch_code with bad dates'); |
1315 |
scalar @missing_criticals_2, 3, |
879 |
is($missing_criticals_2[0]->{key}, 'dateofbirth', 'Got the expected dateofbirth key from check_branch_code with bad dates'); |
1316 |
'Got the expected missing critical array size of 3 from check_branch_code with bad dates' |
880 |
is($missing_criticals_2[0]->{line}, $line_number, 'Got the expected first line from check_branch_code with bad dates'); |
1317 |
); |
881 |
is($missing_criticals_2[0]->{lineraw}, $borrowerline, 'Got the expected first lineraw from check_branch_code with bad dates'); |
1318 |
is( |
882 |
|
1319 |
$missing_criticals_2[0]->{bad_date}, 1, |
883 |
is($missing_criticals_2[1]->{bad_date}, 1, 'Got the expected second bad date flag from check_branch_code with bad dates'); |
1320 |
'Got the expected first bad date flag from check_branch_code with bad dates' |
884 |
is($missing_criticals_2[1]->{key}, 'dateenrolled', 'Got the expected dateenrolled key from check_branch_code with bad dates'); |
1321 |
); |
885 |
is($missing_criticals_2[1]->{line}, $line_number, 'Got the expected second line from check_branch_code with bad dates'); |
1322 |
is( |
886 |
is($missing_criticals_2[1]->{lineraw}, $borrowerline, 'Got the expected second lineraw from check_branch_code with bad dates'); |
1323 |
$missing_criticals_2[0]->{key}, 'dateofbirth', |
887 |
|
1324 |
'Got the expected dateofbirth key from check_branch_code with bad dates' |
888 |
is($missing_criticals_2[2]->{bad_date}, 1, 'Got the expected third bad date flag from check_branch_code with bad dates'); |
1325 |
); |
889 |
is($missing_criticals_2[2]->{key}, 'dateexpiry', 'Got the expected dateexpiry key from check_branch_code with bad dates'); |
1326 |
is( |
890 |
is($missing_criticals_2[2]->{line}, $line_number, 'Got the expected third line from check_branch_code with bad dates'); |
1327 |
$missing_criticals_2[0]->{line}, $line_number, |
891 |
is($missing_criticals_2[2]->{lineraw}, $borrowerline, 'Got the expected third lineraw from check_branch_code with bad dates'); |
1328 |
'Got the expected first line from check_branch_code with bad dates' |
|
|
1329 |
); |
1330 |
is( |
1331 |
$missing_criticals_2[0]->{lineraw}, $borrowerline, |
1332 |
'Got the expected first lineraw from check_branch_code with bad dates' |
1333 |
); |
1334 |
|
1335 |
is( |
1336 |
$missing_criticals_2[1]->{bad_date}, 1, |
1337 |
'Got the expected second bad date flag from check_branch_code with bad dates' |
1338 |
); |
1339 |
is( |
1340 |
$missing_criticals_2[1]->{key}, 'dateenrolled', |
1341 |
'Got the expected dateenrolled key from check_branch_code with bad dates' |
1342 |
); |
1343 |
is( |
1344 |
$missing_criticals_2[1]->{line}, $line_number, |
1345 |
'Got the expected second line from check_branch_code with bad dates' |
1346 |
); |
1347 |
is( |
1348 |
$missing_criticals_2[1]->{lineraw}, $borrowerline, |
1349 |
'Got the expected second lineraw from check_branch_code with bad dates' |
1350 |
); |
1351 |
|
1352 |
is( |
1353 |
$missing_criticals_2[2]->{bad_date}, 1, |
1354 |
'Got the expected third bad date flag from check_branch_code with bad dates' |
1355 |
); |
1356 |
is( |
1357 |
$missing_criticals_2[2]->{key}, 'dateexpiry', |
1358 |
'Got the expected dateexpiry key from check_branch_code with bad dates' |
1359 |
); |
1360 |
is( |
1361 |
$missing_criticals_2[2]->{line}, $line_number, |
1362 |
'Got the expected third line from check_branch_code with bad dates' |
1363 |
); |
1364 |
is( |
1365 |
$missing_criticals_2[2]->{lineraw}, $borrowerline, |
1366 |
'Got the expected third lineraw from check_branch_code with bad dates' |
1367 |
); |
892 |
}; |
1368 |
}; |
893 |
|
1369 |
|
894 |
subtest 'patron_attributes' => sub { |
1370 |
subtest 'patron_attributes' => sub { |
895 |
|
1371 |
|
896 |
plan tests => 17; |
1372 |
plan tests => 17; |
897 |
|
1373 |
|
898 |
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); |
1374 |
t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 1 ); |
899 |
|
1375 |
|
900 |
my $unique_attribute_type = $builder->build_object( |
1376 |
my $unique_attribute_type = $builder->build_object( |
901 |
{ |
1377 |
{ |
902 |
class => 'Koha::Patron::Attribute::Types', |
1378 |
class => 'Koha::Patron::Attribute::Types', |
903 |
value => { unique_id=> 1, repeatable => 0 } |
1379 |
value => { unique_id => 1, repeatable => 0 } |
904 |
} |
1380 |
} |
905 |
); |
1381 |
); |
906 |
my $repeatable_attribute_type = $builder->build_object( |
1382 |
my $repeatable_attribute_type = $builder->build_object( |
Lines 929-960
subtest 'patron_attributes' => sub {
Link Here
|
929 |
sub build_csv { |
1405 |
sub build_csv { |
930 |
my ($attributes) = @_; |
1406 |
my ($attributes) = @_; |
931 |
|
1407 |
|
932 |
my $csv_headers = 'cardnumber,surname,firstname,branchcode,categorycode,patron_attributes'; |
1408 |
my $csv_headers = 'cardnumber,surname,firstname,branchcode,categorycode,patron_attributes'; |
933 |
my @attributes_str = map { my $code = $_; map { sprintf "%s:%s", $code, $_ } @{ $attributes->{$code} } } keys %$attributes; |
1409 |
my @attributes_str = map { |
|
|
1410 |
my $code = $_; |
1411 |
map { sprintf "%s:%s", $code, $_ } @{ $attributes->{$code} } |
1412 |
} keys %$attributes; |
934 |
my $attributes_str = join ',', @attributes_str; |
1413 |
my $attributes_str = join ',', @attributes_str; |
935 |
my $csv_line = sprintf '%s,John,D,MPL,PT,"%s"', $cardnumber, $attributes_str; |
1414 |
my $csv_line = sprintf '%s,John,D,MPL,PT,"%s"', $cardnumber, $attributes_str; |
936 |
my $filename = make_csv( $temp_dir, $csv_headers, $csv_line ); |
1415 |
my $filename = make_csv( $temp_dir, $csv_headers, $csv_line ); |
937 |
open( my $fh, "<:encoding(utf8)", $filename ) or die "cannot open $filename: $!"; |
1416 |
open( my $fh, "<:encoding(utf8)", $filename ) or die "cannot open $filename: $!"; |
938 |
return $fh; |
1417 |
return $fh; |
939 |
} |
1418 |
} |
940 |
|
1419 |
|
941 |
{ # Everything good, we create a patron with 3 attributes |
1420 |
{ # Everything good, we create a patron with 3 attributes |
942 |
my $attributes = { |
1421 |
my $attributes = { |
943 |
$unique_attribute_type->code => ['my unique attribute 1'], |
1422 |
$unique_attribute_type->code => ['my unique attribute 1'], |
944 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1423 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
945 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1424 |
$normal_attribute_type->code => ['my normal attribute 1'], |
946 |
}; |
1425 |
}; |
947 |
my $fh = build_csv({ %$attributes }); |
1426 |
my $fh = build_csv( {%$attributes} ); |
948 |
my $result = $patrons_import->import_patrons({file => $fh}); |
1427 |
my $result = $patrons_import->import_patrons( { file => $fh } ); |
949 |
|
1428 |
|
950 |
is( $result->{imported}, 1 ); |
1429 |
is( $result->{imported}, 1 ); |
951 |
|
1430 |
|
952 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
1431 |
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); |
953 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
1432 |
compare_patron_attributes( $patron->extended_attributes->unblessed, {%$attributes} ); |
954 |
$patron->delete; |
1433 |
$patron->delete; |
955 |
} |
1434 |
} |
956 |
|
1435 |
|
957 |
{ # UniqueIDConstraint |
1436 |
{ # UniqueIDConstraint |
958 |
$builder->build_object( |
1437 |
$builder->build_object( |
959 |
{ |
1438 |
{ |
960 |
class => 'Koha::Patron::Attributes', |
1439 |
class => 'Koha::Patron::Attributes', |
Lines 966-1018
subtest 'patron_attributes' => sub {
Link Here
|
966 |
$unique_attribute_type->code => ['unique'], |
1445 |
$unique_attribute_type->code => ['unique'], |
967 |
$normal_attribute_type->code => ['my normal attribute 1'] |
1446 |
$normal_attribute_type->code => ['my normal attribute 1'] |
968 |
}; |
1447 |
}; |
969 |
my $fh = build_csv({ %$attributes }); |
1448 |
my $fh = build_csv( {%$attributes} ); |
970 |
|
1449 |
|
971 |
my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); |
1450 |
my $result = $patrons_import->import_patrons( { file => $fh, matchpoint => 'cardnumber' } ); |
972 |
my $error = $result->{errors}->[0]; |
1451 |
my $error = $result->{errors}->[0]; |
973 |
is( $error->{patron_attribute_unique_id_constraint}, 1 ); |
1452 |
is( $error->{patron_attribute_unique_id_constraint}, 1 ); |
974 |
is( $error->{patron_id}, $cardnumber ); |
1453 |
is( $error->{patron_id}, $cardnumber ); |
975 |
is( $error->{attribute}->code, $unique_attribute_type->code ); |
1454 |
is( $error->{attribute}->code, $unique_attribute_type->code ); |
976 |
|
1455 |
|
977 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
1456 |
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); |
978 |
is( $patron, undef, 'Patron is not created' ); |
1457 |
is( $patron, undef, 'Patron is not created' ); |
979 |
} |
1458 |
} |
980 |
|
1459 |
|
981 |
{ #InvalidType |
1460 |
{ #InvalidType |
982 |
my $attributes = { |
1461 |
my $attributes = { |
983 |
$non_existent_attribute_type_code => ['my non-existent attribute'], |
1462 |
$non_existent_attribute_type_code => ['my non-existent attribute'], |
984 |
$normal_attribute_type->code => ['my attribute 1'], |
1463 |
$normal_attribute_type->code => ['my attribute 1'], |
985 |
}; |
1464 |
}; |
986 |
my $fh = build_csv({ %$attributes }); |
1465 |
my $fh = build_csv( {%$attributes} ); |
987 |
|
1466 |
|
988 |
my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); |
1467 |
my $result = $patrons_import->import_patrons( { file => $fh, matchpoint => 'cardnumber' } ); |
989 |
is( $result->{imported}, 0 ); |
1468 |
is( $result->{imported}, 0 ); |
990 |
|
1469 |
|
991 |
my $error = $result->{errors}->[0]; |
1470 |
my $error = $result->{errors}->[0]; |
992 |
is( $error->{patron_attribute_invalid_type}, 1 ); |
1471 |
is( $error->{patron_attribute_invalid_type}, 1 ); |
993 |
is( $error->{patron_id}, $cardnumber ); |
1472 |
is( $error->{patron_id}, $cardnumber ); |
994 |
is( $error->{attribute_type_code}, $non_existent_attribute_type_code ); |
1473 |
is( $error->{attribute_type_code}, $non_existent_attribute_type_code ); |
995 |
|
1474 |
|
996 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
1475 |
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); |
997 |
is( $patron, undef ); |
1476 |
is( $patron, undef ); |
998 |
|
1477 |
|
999 |
} |
1478 |
} |
1000 |
|
1479 |
|
1001 |
{ # NonRepeatable |
1480 |
{ # NonRepeatable |
1002 |
my $attributes = { |
1481 |
my $attributes = { |
1003 |
$repeatable_attribute_type->code => ['my repeatable attribute 1', 'my repeatable attribute 2'], |
1482 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1004 |
$normal_attribute_type->code => ['my normal attribute 1', 'my normal attribute 2'], |
1483 |
$normal_attribute_type->code => [ 'my normal attribute 1', 'my normal attribute 2' ], |
1005 |
}; |
1484 |
}; |
1006 |
my $fh = build_csv({ %$attributes }); |
1485 |
my $fh = build_csv( {%$attributes} ); |
1007 |
my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); |
1486 |
my $result = $patrons_import->import_patrons( { file => $fh, matchpoint => 'cardnumber' } ); |
1008 |
is( $result->{imported}, 0 ); |
1487 |
is( $result->{imported}, 0 ); |
1009 |
|
1488 |
|
1010 |
my $error = $result->{errors}->[0]; |
1489 |
my $error = $result->{errors}->[0]; |
1011 |
is( $error->{patron_attribute_non_repeatable}, 1 ); |
1490 |
is( $error->{patron_attribute_non_repeatable}, 1 ); |
1012 |
is( $error->{patron_id}, $cardnumber ); |
1491 |
is( $error->{patron_id}, $cardnumber ); |
1013 |
is( $error->{attribute}->code, $normal_attribute_type->code ); |
1492 |
is( $error->{attribute}->code, $normal_attribute_type->code ); |
1014 |
|
1493 |
|
1015 |
my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); |
1494 |
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); |
1016 |
is( $patron, undef ); |
1495 |
is( $patron, undef ); |
1017 |
} |
1496 |
} |
1018 |
|
1497 |
|
Lines 1027-1037
subtest 'patron_attributes' => sub {
Link Here
|
1027 |
); |
1506 |
); |
1028 |
|
1507 |
|
1029 |
my $attributes = { |
1508 |
my $attributes = { |
1030 |
$unique_attribute_type->code => ['my unique attribute 1'], |
1509 |
$unique_attribute_type->code => ['my unique attribute 1'], |
1031 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1510 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1032 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1511 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1033 |
}; |
1512 |
}; |
1034 |
my $fh = build_csv({ %$attributes }); |
1513 |
my $fh = build_csv( {%$attributes} ); |
1035 |
my $result = $patrons_import->import_patrons( |
1514 |
my $result = $patrons_import->import_patrons( |
1036 |
{ |
1515 |
{ |
1037 |
file => $fh, |
1516 |
file => $fh, |
Lines 1043-1055
subtest 'patron_attributes' => sub {
Link Here
|
1043 |
|
1522 |
|
1044 |
is( $result->{overwritten}, 1 ); |
1523 |
is( $result->{overwritten}, 1 ); |
1045 |
|
1524 |
|
1046 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
1525 |
compare_patron_attributes( $patron->extended_attributes->unblessed, {%$attributes} ); |
1047 |
|
1526 |
|
1048 |
# Adding a new non-repeatable attribute |
1527 |
# Adding a new non-repeatable attribute |
1049 |
my $new_attributes = { |
1528 |
my $new_attributes = { |
1050 |
$normal_attribute_type->code => ['my normal attribute 2'], |
1529 |
$normal_attribute_type->code => ['my normal attribute 2'], |
1051 |
}; |
1530 |
}; |
1052 |
$fh = build_csv({ %$new_attributes }); |
1531 |
$fh = build_csv( {%$new_attributes} ); |
1053 |
$result = $patrons_import->import_patrons( |
1532 |
$result = $patrons_import->import_patrons( |
1054 |
{ |
1533 |
{ |
1055 |
file => $fh, |
1534 |
file => $fh, |
Lines 1062-1071
subtest 'patron_attributes' => sub {
Link Here
|
1062 |
is( $result->{overwritten}, 1 ); |
1541 |
is( $result->{overwritten}, 1 ); |
1063 |
|
1542 |
|
1064 |
# The normal_attribute_type has been replaced with 'my normal attribute 2' |
1543 |
# The normal_attribute_type has been replaced with 'my normal attribute 2' |
1065 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } ); |
1544 |
compare_patron_attributes( $patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } ); |
1066 |
|
1545 |
|
1067 |
# UniqueIDConstraint |
1546 |
# UniqueIDConstraint |
1068 |
$patron->extended_attributes->delete; # reset |
1547 |
$patron->extended_attributes->delete; # reset |
1069 |
$builder->build_object( |
1548 |
$builder->build_object( |
1070 |
{ |
1549 |
{ |
1071 |
class => 'Koha::Patron::Attributes', |
1550 |
class => 'Koha::Patron::Attributes', |
Lines 1073-1083
subtest 'patron_attributes' => sub {
Link Here
|
1073 |
} |
1552 |
} |
1074 |
); |
1553 |
); |
1075 |
$attributes = { |
1554 |
$attributes = { |
1076 |
$unique_attribute_type->code => ['unique'], |
1555 |
$unique_attribute_type->code => ['unique'], |
1077 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1556 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1078 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1557 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1079 |
}; |
1558 |
}; |
1080 |
$fh = build_csv({ %$attributes }); |
1559 |
$fh = build_csv( {%$attributes} ); |
1081 |
$result = $patrons_import->import_patrons( |
1560 |
$result = $patrons_import->import_patrons( |
1082 |
{ |
1561 |
{ |
1083 |
file => $fh, |
1562 |
file => $fh, |
Lines 1090-1107
subtest 'patron_attributes' => sub {
Link Here
|
1090 |
is( $result->{overwritten}, 0 ); |
1569 |
is( $result->{overwritten}, 0 ); |
1091 |
my $error = $result->{errors}->[0]; |
1570 |
my $error = $result->{errors}->[0]; |
1092 |
is( $error->{patron_attribute_unique_id_constraint}, 1 ); |
1571 |
is( $error->{patron_attribute_unique_id_constraint}, 1 ); |
1093 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1572 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1094 |
is( $error->{attribute}->code, $unique_attribute_type->code ); |
1573 |
is( $error->{attribute}->code, $unique_attribute_type->code ); |
1095 |
|
|
|
1096 |
compare_patron_attributes($patron->extended_attributes->unblessed, {}, ); |
1097 |
|
1574 |
|
|
|
1575 |
compare_patron_attributes( $patron->extended_attributes->unblessed, {}, ); |
1098 |
|
1576 |
|
1099 |
#InvalidType |
1577 |
#InvalidType |
1100 |
$attributes = { |
1578 |
$attributes = { |
1101 |
$non_existent_attribute_type_code => ['my non-existent attribute'], |
1579 |
$non_existent_attribute_type_code => ['my non-existent attribute'], |
1102 |
$normal_attribute_type->code => ['my attribute 1'], |
1580 |
$normal_attribute_type->code => ['my attribute 1'], |
1103 |
}; |
1581 |
}; |
1104 |
$fh = build_csv({ %$attributes }); |
1582 |
$fh = build_csv( {%$attributes} ); |
1105 |
|
1583 |
|
1106 |
$result = $patrons_import->import_patrons( |
1584 |
$result = $patrons_import->import_patrons( |
1107 |
{ |
1585 |
{ |
Lines 1115-1129
subtest 'patron_attributes' => sub {
Link Here
|
1115 |
|
1593 |
|
1116 |
$error = $result->{errors}->[0]; |
1594 |
$error = $result->{errors}->[0]; |
1117 |
is( $error->{patron_attribute_invalid_type}, 1 ); |
1595 |
is( $error->{patron_attribute_invalid_type}, 1 ); |
1118 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1596 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1119 |
is( $error->{attribute_type_code}, $non_existent_attribute_type_code ); |
1597 |
is( $error->{attribute_type_code}, $non_existent_attribute_type_code ); |
1120 |
|
1598 |
|
1121 |
# NonRepeatable |
1599 |
# NonRepeatable |
1122 |
$attributes = { |
1600 |
$attributes = { |
1123 |
$repeatable_attribute_type->code => ['my repeatable attribute 1', 'my repeatable attribute 2'], |
1601 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], |
1124 |
$normal_attribute_type->code => ['my normal attribute 1', 'my normal attribute 2'], |
1602 |
$normal_attribute_type->code => [ 'my normal attribute 1', 'my normal attribute 2' ], |
1125 |
}; |
1603 |
}; |
1126 |
$fh = build_csv({ %$attributes }); |
1604 |
$fh = build_csv( {%$attributes} ); |
1127 |
$result = $patrons_import->import_patrons( |
1605 |
$result = $patrons_import->import_patrons( |
1128 |
{ |
1606 |
{ |
1129 |
file => $fh, |
1607 |
file => $fh, |
Lines 1136-1150
subtest 'patron_attributes' => sub {
Link Here
|
1136 |
|
1614 |
|
1137 |
$error = $result->{errors}->[0]; |
1615 |
$error = $result->{errors}->[0]; |
1138 |
is( $error->{patron_attribute_non_repeatable}, 1 ); |
1616 |
is( $error->{patron_attribute_non_repeatable}, 1 ); |
1139 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1617 |
is( $error->{borrowernumber}, $patron->borrowernumber ); |
1140 |
is( $error->{attribute}->code, $normal_attribute_type->code ); |
1618 |
is( $error->{attribute}->code, $normal_attribute_type->code ); |
1141 |
|
1619 |
|
1142 |
# Don't preserve existing attributes |
1620 |
# Don't preserve existing attributes |
1143 |
$attributes = { |
1621 |
$attributes = { |
1144 |
$repeatable_attribute_type->code => ['my repeatable attribute 3', 'my repeatable attribute 4'], |
1622 |
$repeatable_attribute_type->code => [ 'my repeatable attribute 3', 'my repeatable attribute 4' ], |
1145 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1623 |
$normal_attribute_type->code => ['my normal attribute 1'], |
1146 |
}; |
1624 |
}; |
1147 |
$fh = build_csv({ %$attributes }); |
1625 |
$fh = build_csv( {%$attributes} ); |
1148 |
$result = $patrons_import->import_patrons( |
1626 |
$result = $patrons_import->import_patrons( |
1149 |
{ |
1627 |
{ |
1150 |
file => $fh, |
1628 |
file => $fh, |
Lines 1155-1161
subtest 'patron_attributes' => sub {
Link Here
|
1155 |
); |
1633 |
); |
1156 |
is( $result->{overwritten}, 1 ); |
1634 |
is( $result->{overwritten}, 1 ); |
1157 |
|
1635 |
|
1158 |
compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); |
1636 |
compare_patron_attributes( $patron->extended_attributes->unblessed, {%$attributes} ); |
1159 |
|
1637 |
|
1160 |
}; |
1638 |
}; |
1161 |
|
1639 |
|
Lines 1166-1190
subtest 'welcome_email' => sub {
Link Here
|
1166 |
plan tests => 3; |
1644 |
plan tests => 3; |
1167 |
|
1645 |
|
1168 |
#Setup our info |
1646 |
#Setup our info |
1169 |
my $branchcode = $builder->build({ source => "Branch"})->{branchcode}; |
1647 |
my $branchcode = $builder->build( { source => "Branch" } )->{branchcode}; |
1170 |
my $categorycode = $builder->build({ source => "Category", value => { category_type => 'A' } })->{categorycode}; |
1648 |
my $categorycode = $builder->build( { source => "Category", value => { category_type => 'A' } } )->{categorycode}; |
1171 |
my $staff_categorycode = $builder->build({ source => "Category", value => { category_type => 'S' } })->{categorycode}; |
1649 |
my $staff_categorycode = |
1172 |
my $csv_headers = 'surname,userid,branchcode,categorycode,password,email'; |
1650 |
$builder->build( { source => "Category", value => { category_type => 'S' } } )->{categorycode}; |
1173 |
my $csv_new = "Spagobi,EldridgeS,$branchcode,$categorycode,H4ckR".',me@myemail.com'; |
1651 |
my $csv_headers = 'surname,userid,branchcode,categorycode,password,email'; |
1174 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
1652 |
my $csv_new = "Spagobi,EldridgeS,$branchcode,$categorycode,H4ckR" . ',me@myemail.com'; |
|
|
1653 |
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled |
1175 |
|
1654 |
|
1176 |
#Make the test files for importing |
1655 |
#Make the test files for importing |
1177 |
my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_new); |
1656 |
my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_new ); |
1178 |
open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; |
1657 |
open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; |
1179 |
|
1658 |
|
1180 |
my $params_1 = { file => $handle_1, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1, send_welcome => 1}; |
1659 |
my $params_1 = { |
|
|
1660 |
file => $handle_1, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1, |
1661 |
send_welcome => 1 |
1662 |
}; |
1181 |
|
1663 |
|
1182 |
my $result = $patrons_import->import_patrons($params_1, $defaults); |
1664 |
my $result = $patrons_import->import_patrons( $params_1, $defaults ); |
1183 |
is($result->{already_in_db}, 0, 'New borrower imported as expected'); |
1665 |
is( $result->{already_in_db}, 0, 'New borrower imported as expected' ); |
1184 |
is($result->{feedback}->[3]->{name}, 'welcome_sent', 'Email send reported'); |
1666 |
is( $result->{feedback}->[3]->{name}, 'welcome_sent', 'Email send reported' ); |
1185 |
my $eldridge = Koha::Patrons->find({ userid => 'EldridgeS'}); |
1667 |
my $eldridge = Koha::Patrons->find( { userid => 'EldridgeS' } ); |
1186 |
my $notices = Koha::Notice::Messages->search({ borrowernumber => $eldridge->borrowernumber }); |
1668 |
my $notices = Koha::Notice::Messages->search( { borrowernumber => $eldridge->borrowernumber } ); |
1187 |
is($notices->count, 1, 'Notice was queued'); |
1669 |
is( $notices->count, 1, 'Notice was queued' ); |
1188 |
}; |
1670 |
}; |
1189 |
|
1671 |
|
1190 |
subtest 'test update_dateexpiry when no dateexpiry in file' => sub { |
1672 |
subtest 'test update_dateexpiry when no dateexpiry in file' => sub { |
Lines 1246-1251
subtest 'test update_dateexpiry when no dateexpiry in file' => sub {
Link Here
|
1246 |
}; |
1728 |
}; |
1247 |
|
1729 |
|
1248 |
subtest 'prevent regression in update of dateexpiry with no date related flags' => sub { |
1730 |
subtest 'prevent regression in update of dateexpiry with no date related flags' => sub { |
|
|
1731 |
|
1249 |
# If the --update-expiration or --expiration-from-today flgas are not passed, the behaviour should be as foolows: |
1732 |
# If the --update-expiration or --expiration-from-today flgas are not passed, the behaviour should be as foolows: |
1250 |
# 1) dateexpiry column is blank - preserve existing patron expiry date |
1733 |
# 1) dateexpiry column is blank - preserve existing patron expiry date |
1251 |
# 2) dateexpiry column has a date value - update expiry date to match this new date |
1734 |
# 2) dateexpiry column has a date value - update expiry date to match this new date |
Lines 1253-1262
subtest 'prevent regression in update of dateexpiry with no date related flags'
Link Here
|
1253 |
|
1736 |
|
1254 |
my $csv_headers = 'cardnumber,surname,branchcode,categorycode,dateenrolled,dateexpiry'; |
1737 |
my $csv_headers = 'cardnumber,surname,branchcode,categorycode,dateenrolled,dateexpiry'; |
1255 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1738 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1256 |
$patron->dateexpiry( '2099-12-31' ); |
1739 |
$patron->dateexpiry('2099-12-31'); |
1257 |
$patron->dateenrolled( dt_from_string->add( months => '-24', end_of_month => 'limit' ) )->store; |
1740 |
$patron->dateenrolled( dt_from_string->add( months => '-24', end_of_month => 'limit' ) )->store; |
1258 |
my $csv_values = join( |
1741 |
my $csv_values = join( |
1259 |
',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, |
1742 |
',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, |
1260 |
$patron->dateenrolled, '' |
1743 |
$patron->dateenrolled, '' |
1261 |
); |
1744 |
); |
1262 |
|
1745 |
|
Lines 1272-1278
subtest 'prevent regression in update of dateexpiry with no date related flags'
Link Here
|
1272 |
); |
1755 |
); |
1273 |
|
1756 |
|
1274 |
$csv_values = join( |
1757 |
$csv_values = join( |
1275 |
',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, |
1758 |
',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, |
1276 |
$patron->dateenrolled, '2098-01-01' |
1759 |
$patron->dateenrolled, '2098-01-01' |
1277 |
); |
1760 |
); |
1278 |
|
1761 |
|
Lines 1288-1322
subtest 'prevent regression in update of dateexpiry with no date related flags'
Link Here
|
1288 |
); |
1771 |
); |
1289 |
}; |
1772 |
}; |
1290 |
|
1773 |
|
1291 |
|
|
|
1292 |
# got is { code => $code, attribute => $attribute } |
1774 |
# got is { code => $code, attribute => $attribute } |
1293 |
# expected is { $code => \@attributes } |
1775 |
# expected is { $code => \@attributes } |
1294 |
sub compare_patron_attributes { |
1776 |
sub compare_patron_attributes { |
1295 |
my ( $got, $expected ) = @_; |
1777 |
my ( $got, $expected ) = @_; |
1296 |
|
1778 |
|
1297 |
$got = [ map { { code => $_->{code}, attribute => $_->{attribute} } } @$got ]; |
1779 |
$got = [ map { { code => $_->{code}, attribute => $_->{attribute} } } @$got ]; |
1298 |
$expected = [ |
1780 |
$expected = [ |
1299 |
map { |
1781 |
map { |
1300 |
my $code = $_; |
1782 |
my $code = $_; |
1301 |
map { { code => $code, attribute => $_ } } @{ $expected->{$code} } |
1783 |
map { { code => $code, attribute => $_ } } @{ $expected->{$code} } |
1302 |
} keys %$expected |
1784 |
} keys %$expected |
1303 |
]; |
1785 |
]; |
1304 |
for my $v ( $got, $expected ) { |
1786 |
for my $v ( $got, $expected ) { |
1305 |
$v = [ |
1787 |
$v = [ sort { $a->{code} cmp $b->{code} || $a->{attribute} cmp $b->{attribute} } @$v ]; |
1306 |
sort { |
|
|
1307 |
$a->{code} cmp $b->{code} || $a->{attribute} cmp $b->{attribute} |
1308 |
} @$v |
1309 |
]; |
1310 |
} |
1788 |
} |
1311 |
is_deeply($got, $expected); |
1789 |
is_deeply( $got, $expected ); |
1312 |
} |
1790 |
} |
1313 |
|
1791 |
|
1314 |
# ###### Test utility ########### |
1792 |
# ###### Test utility ########### |
1315 |
sub make_csv { |
1793 |
sub make_csv { |
1316 |
my ($temp_dir, @lines) = @_; |
1794 |
my ( $temp_dir, @lines ) = @_; |
1317 |
|
1795 |
|
1318 |
my ($fh, $filename) = tempfile( DIR => $temp_dir) or die $!; |
1796 |
my ( $fh, $filename ) = tempfile( DIR => $temp_dir ) or die $!; |
1319 |
print $fh $_."\r\n" foreach @lines; |
1797 |
print $fh $_ . "\r\n" foreach @lines; |
1320 |
close $fh or die $!; |
1798 |
close $fh or die $!; |
1321 |
|
1799 |
|
1322 |
return $filename; |
1800 |
return $filename; |
1323 |
- |
|
|