From: Bernd Bleßmann Date: Fri, 11 Aug 2017 14:48:24 +0000 (+0200) Subject: Tests CsvImport: run-Methode der Worker verwenden X-Git-Tag: release-3.5.4~897 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=cdc396f5543250ac2cd9ad5b9b45bd2806c8e6c5;p=kivitendo-erp.git Tests CsvImport: run-Methode der Worker verwenden Vorher wurden der Code der run-Methode aus den Basis-Klassen der Worker (copy/paste) hier einzeln aufgerufen. --- diff --git a/t/controllers/csvimport/artransactions.t b/t/controllers/csvimport/artransactions.t index dd0a8f1e3..c4df0a78b 100644 --- a/t/controllers/csvimport/artransactions.t +++ b/t/controllers/csvimport/artransactions.t @@ -65,7 +65,16 @@ reset_state(customer => {id => 960, customernumber => 2}); sub test_import { my $file = shift; - my $controller = SL::Controller::CsvImport->new(); + my $controller = SL::Controller::CsvImport->new( + type => 'ar_transactions' + ); + $controller->load_default_profile; + $controller->profile->set( + encoding => 'utf-8', + sep_char => ',', + quote_char => '"', + numberformat => $::myconfig{numberformat}, + ); my $csv_artransactions_import = SL::Controller::CsvImport::ARTransaction->new( settings => {'ar_column' => 'Rechnung', @@ -77,56 +86,7 @@ sub test_import { ); # $csv_artransactions_import->init_vc_by; - $csv_artransactions_import->test_run(0); - $csv_artransactions_import->csv(SL::Helper::Csv->new(file => $csv_artransactions_import->file, - profile => $csv_artransactions_import->profile, - encoding => 'utf-8', - ignore_unknown_columns => 1, - strict_profile => 1, - case_insensitive_header => 1, - sep_char => ',', - quote_char => '"', - ignore_unknown_columns => 1, - )); - - $csv_artransactions_import->csv->parse; - - $csv_artransactions_import->controller->errors([ $csv_artransactions_import->csv->errors ]) if $csv_artransactions_import->csv->errors; - - return if ( !$csv_artransactions_import->csv->header || $csv_artransactions_import->csv->errors ); - - my $headers; - my $i = 0; - foreach my $header (@{ $csv_artransactions_import->csv->header }) { - - my $profile = $csv_artransactions_import->csv->profile->[$i]->{profile}; - my $row_ident = $csv_artransactions_import->csv->profile->[$i]->{row_ident}; - - my $h = { headers => [ grep { $profile->{$_} } @{ $header } ] }; - $h->{methods} = [ map { $profile->{$_} } @{ $h->{headers} } ]; - $h->{used} = { map { ($_ => 1) } @{ $h->{headers} } }; - - $headers->{$row_ident} = $h; - $i++; - } - - $csv_artransactions_import->controller->headers($headers); - - my $raw_data_headers; - my $info_headers; - foreach my $p (@{ $csv_artransactions_import->csv->profile }) { - my $ident = $p->{row_ident}; - $raw_data_headers->{$ident} = { used => { }, headers => [ ] }; - $info_headers->{$ident} = { used => { }, headers => [ ] }; - } - $csv_artransactions_import->controller->raw_data_headers($raw_data_headers); - $csv_artransactions_import->controller->info_headers($info_headers); - - my $objects = $csv_artransactions_import->csv->get_objects; - my @raw_data = @{ $csv_artransactions_import->csv->get_data }; - - $csv_artransactions_import->controller->data([ pairwise { no warnings 'once'; { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @$objects, @raw_data ]); - $csv_artransactions_import->check_objects; + $csv_artransactions_import->run({test => 0}); # don't try and save objects that have errors $csv_artransactions_import->save_objects unless scalar @{$csv_artransactions_import->controller->data->[0]->{errors}}; diff --git a/t/controllers/csvimport/parts.t b/t/controllers/csvimport/parts.t index b7f1a9c61..2d5898e9c 100644 --- a/t/controllers/csvimport/parts.t +++ b/t/controllers/csvimport/parts.t @@ -96,8 +96,17 @@ reset_state(); ##### sub test_import { my ($file,$settings) = @_; - my @profiles; - my $controller = SL::Controller::CsvImport->new(); + + my $controller = SL::Controller::CsvImport->new( + type => 'parts' + ); + $controller->load_default_profile; + $controller->profile->set( + encoding => 'utf-8', + sep_char => ';', + quote_char => '"', + numberformat => $::myconfig{numberformat}, + ); my $csv_part_import = SL::Controller::CsvImport::Part->new( settings => $settings, @@ -106,39 +115,7 @@ sub test_import { ); #print "profile param type=".$csv_part_import->settings->{parts_type}."\n"; - $csv_part_import->test_run(0); - $csv_part_import->csv(SL::Helper::Csv->new(file => $csv_part_import->file, - profile => [{ profile => $csv_part_import->profile, - class => $csv_part_import->class, - mapping => $csv_part_import->controller->mappings_for_profile }], - encoding => 'utf-8', - ignore_unknown_columns => 1, - strict_profile => 1, - case_insensitive_header => 1, - sep_char => ';', - quote_char => '"', - ignore_unknown_columns => 1, - )); - - $csv_part_import->csv->parse; - - $csv_part_import->controller->errors([ $csv_part_import->csv->errors ]) if $csv_part_import->csv->errors; - - return if ( !$csv_part_import->csv->header || $csv_part_import->csv->errors ); - - my $headers = { headers => [ grep { $csv_part_import->csv->dispatcher->is_known($_, 0) } @{ $csv_part_import->csv->header } ] }; - $headers->{methods} = [ map { $_->{path} } @{ $csv_part_import->csv->specs->[0] } ]; - $headers->{used} = { map { ($_ => 1) } @{ $headers->{headers} } }; - $csv_part_import->controller->headers($headers); - $csv_part_import->controller->raw_data_headers({ used => { }, headers => [ ] }); - $csv_part_import->controller->info_headers({ used => { }, headers => [ ] }); - - my $objects = $csv_part_import->csv->get_objects; - my @raw_data = @{ $csv_part_import->csv->get_data }; - - $csv_part_import->controller->data([ pairwise { no warnings 'once'; { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @$objects, @raw_data ]); - - $csv_part_import->check_objects; + $csv_part_import->run({test => 0}); # don't try and save objects that have errors $csv_part_import->save_objects unless scalar @{$csv_part_import->controller->data->[0]->{errors}};