X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fhelper%2Fcsv.t;h=99da3d38d466df451a1e0b0ac7540d59b90219b0;hb=0084e295cf384c8c13001923f20de278d74435ea;hp=bab3825df595fd24586336c86d0ea3aa2d2d5e70;hpb=fa7fc7eeb3ca718914affee06c0629a08d571288;p=kivitendo-erp.git diff --git a/t/helper/csv.t b/t/helper/csv.t index bab3825df..99da3d38d 100644 --- a/t/helper/csv.t +++ b/t/helper/csv.t @@ -1,4 +1,4 @@ -use Test::More tests => 75; +use Test::More tests => 84; use lib 't'; use utf8; @@ -726,6 +726,88 @@ ok $csv->get_objects->[0], 'multiplex: empty path gets ignored in object creatio ##### +# Mappings +# simple case +$csv = SL::Helper::Csv->new( + file => \< ',', + quote_char => "'", + profile => [ + { + profile => { listprice => 'listprice_as_number' }, + mapping => { purchaseprice => 'listprice' }, + class => 'SL::DB::Part', + } + ], +); +ok $csv->parse, 'simple mapping parses'; +is $csv->get_objects->[0]->listprice, 1.5234, 'simple mapping works'; + +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + ignore_unknown_columns => 1, + strict_profile => 1, + profile => [{ + profile => { lastcost => 'lastcost_as_number' }, + mapping => { purchaseprice => 'lastcost' }, + class => 'SL::DB::Part', + }] +); +ok $csv->parse, 'strict mapping parses'; +is $csv->get_objects->[0]->lastcost, 1221.52, 'strict mapping works'; + +# swapping +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + ignore_unknown_columns => 1, + strict_profile => 1, + profile => [{ + mapping => { partnumber => 'description', description => 'partnumber' }, + class => 'SL::DB::Part', + }] +); +ok $csv->parse, 'swapping parses'; +is $csv->get_objects->[0]->partnumber, 'Kaffee', 'strict mapping works 1'; +is $csv->get_objects->[0]->description, '1', 'strict mapping works 2'; + +# case insensitive shit +$csv = SL::Helper::Csv->new( + file => \"Description\nKaffee", # " # make emacs happy + case_insensitive_header => 1, + profile => [{ + mapping => { description => 'description' }, + class => 'SL::DB::Part' + }], +); +$csv->parse; +is $csv->get_objects->[0]->description, 'Kaffee', 'case insensitive mapping without profile works'; + +# case insensitive shit +$csv = SL::Helper::Csv->new( + file => \"Price\n4,99", # " # make emacs happy + case_insensitive_header => 1, + profile => [{ + profile => { sellprice => 'sellprice_as_number' }, + mapping => { price => 'sellprice' }, + class => 'SL::DB::Part', + }], +); +$csv->parse; +is $csv->get_objects->[0]->sellprice, 4.99, 'case insensitive mapping with profile works'; + # vim: ft=perl # set emacs to perl mode