Revision 09294068
Von Sven Schöling vor mehr als 13 Jahren hinzugefügt
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 31;
|
|
1 |
use Test::More tests => 36;
|
|
2 | 2 |
use SL::Dispatcher; |
3 | 3 |
use Data::Dumper; |
4 | 4 |
use utf8; |
... | ... | |
225 | 225 |
is_deeply $csv->errors, [ 'buchungsgruppen.1.description', undef, "Profile path error. Indexed relationship is not OneToMany around here: 'buchungsgruppen.1'", undef ,0 ], 'error indicates wrong header'; |
226 | 226 |
isa_ok( ($csv->errors)[0], 'SL::Helper::Csv::Error', 'Errors get objectified'); |
227 | 227 |
|
228 |
#### |
|
229 |
|
|
230 |
$csv = SL::Helper::Csv->new( |
|
231 |
file => \<<EOL, |
|
232 |
description;partnumber;sellprice;lastcost;wiener; |
|
233 |
Kaffee;;0.12;1,221.52;ja wiener |
|
234 |
Beer;1123245;0.12;1.5234;nein kein wieder |
|
235 |
EOL |
|
236 |
numberformat => '1,000.00', |
|
237 |
ignore_unknown_columns => 1, |
|
238 |
strict_profile => 1, |
|
239 |
class => 'SL::DB::Part', |
|
240 |
profile => { |
|
241 |
lastcost => 'lastcost_as_number', |
|
242 |
} |
|
243 |
); |
|
244 |
$csv->parse; |
|
245 |
is $csv->get_objects->[0]->lastcost, '1221.52', 'strict_profile with ignore'; |
|
246 |
is $csv->get_objects->[0]->sellprice, undef, 'strict profile with ignore 2'; |
|
247 |
|
|
248 |
#### |
|
249 |
|
|
250 |
$csv = SL::Helper::Csv->new( |
|
251 |
file => \<<EOL, |
|
252 |
description;partnumber;sellprice;lastcost;wiener; |
|
253 |
Kaffee;;0.12;1,221.52;ja wiener |
|
254 |
Beer;1123245;0.12;1.5234;nein kein wieder |
|
255 |
EOL |
|
256 |
numberformat => '1,000.00', |
|
257 |
strict_profile => 1, |
|
258 |
class => 'SL::DB::Part', |
|
259 |
profile => { |
|
260 |
lastcost => 'lastcost_as_number', |
|
261 |
} |
|
262 |
); |
|
263 |
$csv->parse; |
|
264 |
|
|
265 |
is_deeply( ($csv->errors)[0], [ 'description', undef, 'header field \'description\' is not recognized', undef, 0 ], 'strict_profile without ignore_columns throws error'); |
|
266 |
|
|
267 |
|
|
228 | 268 |
# vim: ft=perl |
Auch abrufbar als: Unified diff
SL::Helper::Csv: neues flag "strict_profile". Wenn gesetzt werden nur Daten aus dem Profil benutzt, keine DWIM can checks.