X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fhelper%2Fcsv.t;h=e4a625430b6ce836ed06eebc7469716a7cb840c5;hb=220ccac9cc13afd496050420c635c50d4a65c2c5;hp=7ac728f26b05d4a1a1e0ffce2403478abff5ba0f;hpb=90af0ce7f2f0a8b4155d65a89e612bea1631db38;p=kivitendo-erp.git diff --git a/t/helper/csv.t b/t/helper/csv.t index 7ac728f26..e4a625430 100644 --- a/t/helper/csv.t +++ b/t/helper/csv.t @@ -1,4 +1,4 @@ -use Test::More tests => 29; +use Test::More tests => 39; use SL::Dispatcher; use Data::Dumper; use utf8; @@ -125,6 +125,7 @@ EOL ); is $csv->parse, undef, 'broken csv content won\'t get parsed'; is_deeply $csv->errors, [ '"Kaf"fee";;0.12;1,221.52'."\n", 2023, 'EIQ - QUO character not allowed', 5, 2 ], 'error'; +isa_ok( ($csv->errors)[0], 'SL::Helper::Csv::Error', 'Errors get objectified'); #### @@ -208,4 +209,88 @@ is $csv->get_objects->[0]->makemodels->[0]->make, '213', '...check 2'; is $csv->get_objects->[0]->makemodels->[1]->model, 'Table 15', '...check 3'; is $csv->get_objects->[0]->makemodels->[1]->make, '523', '...check 4'; +###### + +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + class => 'SL::DB::Part', + profile => { + buchungsgruppe => "buchungsgruppen.1.description", + } +); +is $csv->parse, undef, 'wrong profile gets rejected'; +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'; +isa_ok( ($csv->errors)[0], 'SL::Helper::Csv::Error', 'Errors get objectified'); + +#### + +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + ignore_unknown_columns => 1, + strict_profile => 1, + class => 'SL::DB::Part', + profile => { + lastcost => 'lastcost_as_number', + } +); +$csv->parse; +is $csv->get_objects->[0]->lastcost, '1221.52', 'strict_profile with ignore'; +is $csv->get_objects->[0]->sellprice, undef, 'strict profile with ignore 2'; + +#### + +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + strict_profile => 1, + class => 'SL::DB::Part', + profile => { + lastcost => 'lastcost_as_number', + } +); +$csv->parse; + +is_deeply( ($csv->errors)[0], [ 'description', undef, 'header field \'description\' is not recognized', undef, 0 ], 'strict_profile without ignore_columns throws error'); + +##### + +$csv = SL::Helper::Csv->new( + file => \"Kaffee", + header => [ 'description' ], + class => 'SL::DB::Part', +); +$csv->parse; +is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'eol bug at the end of files'; + +##### + +$csv = SL::Helper::Csv->new( + file => \"Description\nKaffee", + class => 'SL::DB::Part', +); +$csv->parse; +is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works'; + +##### + +$csv = SL::Helper::Csv->new( + file => \"Kaffee", + header => [ 'Description' ], + class => 'SL::DB::Part', +); +$csv->parse; +is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works'; + # vim: ft=perl