From 77061a7b4a39fe5fedbc1186bf9f048e78627cde Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 28 Apr 2015 18:19:40 +0200 Subject: [PATCH] =?utf8?q?Aufr=C3=A4umen=20der=20DB=20am=20Ende=20der=20in?= =?utf8?q?dividuellen=20Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit die Tests sollten am Ende ihre eigenen angelegten Daten löschen, damit andere Tests beim Löschen ihrer Daten keine Abhängigkeitsprobleme bekommen: create_periodic_invoices.t price_tax_calculator.t record_links.t sales_orders.t --- t/background_job/create_periodic_invoices.t | 8 +++++++- .../financial_overview/sales_orders.t | 8 +++++++- t/db_helper/price_tax_calculator.t | 15 ++++++++++----- t/db_helper/record_links.t | 19 +++++++++++++------ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/t/background_job/create_periodic_invoices.t b/t/background_job/create_periodic_invoices.t index 8d1c17076..9f55a0c94 100644 --- a/t/background_job/create_periodic_invoices.t +++ b/t/background_job/create_periodic_invoices.t @@ -45,13 +45,17 @@ sub init_common_state { $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; } +sub clear_up { + "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); +}; + sub create_invoices { my %params = @_; $params{$_} ||= {} for qw(customer part tax order orderitem periodic_invoices_config); # Clean up: remove invoices, orders, parts and customers - "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); + clear_up(); $customer = SL::DB::Customer->new( name => 'Test Customer', @@ -237,4 +241,6 @@ are_invoices 'p=b ovp=5',[ '01.01.2009', 33.33 ], [ '01.07.2009', 33.33 ], create_invoices(periodic_invoices_config => { periodicity => 'y', order_value_periodicity => '5', start_date => DateTime->from_kivitendo('01.01.2009') }); are_invoices 'p=y ovp=5',[ '01.01.2009', 66.67 ], [ '01.01.2010', 66.67 ], [ '01.01.2011', 66.67 ], [ '01.01.2012', 66.67 ], [ '01.01.2013', 66.65 ], [ '01.01.2014', 66.67 ]; +clear_up(); + done_testing(); diff --git a/t/controllers/financial_overview/sales_orders.t b/t/controllers/financial_overview/sales_orders.t index 9b278be26..8994faddf 100644 --- a/t/controllers/financial_overview/sales_orders.t +++ b/t/controllers/financial_overview/sales_orders.t @@ -37,6 +37,10 @@ Support::TestSetup::login(); our ($ar_chart, $buchungsgruppe, $ctrl, $currency_id, $customer, $employee, $order, $part, $tax_zone, $unit, @invoices); +sub clear_up { + "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); +}; + sub init_common_state { $ar_chart = SL::DB::Manager::Chart->find_by(accno => '1400') || croak "No AR chart"; $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || croak "No accounting group"; @@ -52,7 +56,7 @@ sub create_sales_order { $params{$_} ||= {} for qw(customer part tax order orderitem); # Clean up: remove invoices, orders, parts and customers - "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); + clear_up(); $customer = SL::DB::Customer->new( name => 'Test Customer', @@ -203,4 +207,6 @@ create_sales_order( is_deeply($ctrl->data->{$_}, { months => [ (0) x 12 ], quarters => [ 0, 0, 0, 0 ], year => 0 }, "periodic conf p=q ovp=y, no invoices, starting and ending before current year, data for $_") for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_orders sales_orders_per_inv sales_quotations); +clear_up(); + done_testing(); diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index 220cd42b5..98462641d 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -24,16 +24,20 @@ use SL::DB::TaxZone; my ($customer, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $taxzone); -sub reset_state { - my %params = @_; - - $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax); - +sub clear_up { SL::DB::Manager::Order->delete_all(all => 1); SL::DB::Manager::DeliveryOrder->delete_all(all => 1); SL::DB::Manager::Invoice->delete_all(all => 1); SL::DB::Manager::Part->delete_all(all => 1); SL::DB::Manager::Customer->delete_all(all => 1); +}; + +sub reset_state { + my %params = @_; + + $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax); + + clear_up(); $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group"; $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || croak "No accounting group for 7\%"; @@ -376,4 +380,5 @@ test_default_invoice_one_item_19_tax_not_included(); test_default_invoice_two_items_19_7_tax_not_included(); test_default_invoice_three_items_sellprice_rounding_discount(); +clear_up(); done_testing(); diff --git a/t/db_helper/record_links.t b/t/db_helper/record_links.t index edfcf72fd..5df89a405 100644 --- a/t/db_helper/record_links.t +++ b/t/db_helper/record_links.t @@ -25,16 +25,21 @@ use SL::DB::TaxZone; my ($customer, $currency_id, $buchungsgruppe, $employee, $vendor, $taxzone); my ($link, $links, $o1, $o2, $d, $i); -sub reset_state { - my %params = @_; - - $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax); - +sub clear_up { SL::DB::Manager::DeliveryOrder->delete_all(all => 1); SL::DB::Manager::Order->delete_all(all => 1); SL::DB::Manager::Invoice->delete_all(all => 1); + SL::DB::Manager::Part->delete_all(all => 1); SL::DB::Manager::Customer->delete_all(all => 1); SL::DB::Manager::Vendor->delete_all(all => 1); +}; + +sub reset_state { + my %params = @_; + + $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax); + + clear_up(); $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group"; $employee = SL::DB::Manager::Employee->current || croak "No employee"; @@ -104,7 +109,6 @@ Support::TestSetup::login(); reset_state(); - $o1 = new_order(); $i = new_invoice(); @@ -313,4 +317,7 @@ is @$links, 3, 'recursive from i finds 3 (not i)'; $links = $o1->linked_records(direction => 'both', recursive => 1, save_path => 1); is @$links, 4, 'recursive dir=both does not give duplicates'; + +clear_up(); + 1; -- 2.20.1