Add coverage tests for more bad CSV file handling,

and two files to exercise the header checks in importTaxData
This commit is contained in:
Colin Kuskie 2008-03-05 21:31:29 +00:00
parent 7fa4e945b5
commit cd55ff1a9e
3 changed files with 46 additions and 3 deletions

View file

@ -34,7 +34,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 73;
my $tests = 80;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -357,7 +357,7 @@ eval {
};
ok (!$failure, 'Tax data not imported');
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a ');
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with an error on 1 line');
cmp_deeply(
$e,
methods(
@ -365,7 +365,41 @@ cmp_deeply(
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badTaxTable.csv'),
brokenLine => 1,
),
'importTaxData: error handling for file that that cannot be read',
'importTaxData: error handling for file with errors in the CSV data',
);
eval {
$failure = $taxer->importTaxData(
WebGUI::Test->getTestCollateralPath('taxTables/missingHeaders.csv')
);
};
ok (!$failure, 'Tax data not imported when headers are missing');
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a missing header column');
cmp_deeply(
$e,
methods(
error => 'Bad header found in the CSV file',
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/missingHeaders.csv'),
),
'importTaxData: error handling for a file with a missing header',
);
eval {
$failure = $taxer->importTaxData(
WebGUI::Test->getTestCollateralPath('taxTables/badHeaders.csv')
);
};
ok (!$failure, 'Tax data not imported when headers are wrong');
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a bad header column');
cmp_deeply(
$e,
methods(
error => 'Bad header found in the CSV file',
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badHeaders.csv'),
),
'importTaxData: error handling for a file with a bad header',
);
#######################################################################
@ -433,6 +467,9 @@ is($e->error, 'Must pass in a WebGUI::Shop::Cart object', 'calculate: error hand
##Build a cart, add some Donation SKUs to it. Set one to be taxable.
my $cart = WebGUI::Shop::Cart->create($session);
is($taxer->calculate($cart), 0, 'calculate returns 0 if there is no shippingAddressId in the cart');
$cart->update({ shippingAddressId => $taxingAddress->getId});
##Set up the tax information

View file

@ -0,0 +1,3 @@
where,value,taxRates
state,5.0
code,53701,0.5
1 where,value,taxRates
2 state,5.0
3 code,53701,0.5

View file

@ -0,0 +1,3 @@
field,taxRate
state,5.0
code,53701,0.5
1 field,taxRate
2 state,5.0
3 code,53701,0.5