Fix these tests. They no longer die.

This commit is contained in:
Colin Kuskie 2010-05-23 15:54:03 -07:00
parent 9a2b3bfd19
commit a95ebdf5de
2 changed files with 520 additions and 548 deletions

View file

@ -109,6 +109,9 @@ my $singlePage = $bible->setCollateral('variantsJSON', 'variantId', 'new',
$versionTag->commit; $versionTag->commit;
addToCleanup($versionTag); addToCleanup($versionTag);
foreach my $asset ($rockHammer, $bible) {
$asset = $asset->cloneFromDb;
}
####################################################################### #######################################################################
# #

View file

@ -26,6 +26,7 @@ use WebGUI::Session;
use WebGUI::Text; use WebGUI::Text;
use WebGUI::Shop::Cart; use WebGUI::Shop::Cart;
use WebGUI::Shop::AddressBook; use WebGUI::Shop::AddressBook;
use WebGUI::Shop::TaxDriver::Generic;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Init # Init
@ -36,21 +37,16 @@ my $session = WebGUI::Test->session;
my $addExceptions = getAddExceptions($session); my $addExceptions = getAddExceptions($session);
my $tests = 78 + 2*scalar(@{$addExceptions}); plan tests => 78
plan tests => 1 + $tests; + 2*scalar(@{$addExceptions});
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# put your tests here # put your tests here
my $loaded = use_ok('WebGUI::Shop::TaxDriver::Generic');
my $storage; my $storage;
my ($taxableDonation, $taxFreeDonation); my ($taxableDonation, $taxFreeDonation);
SKIP: {
skip 'Unable to load module WebGUI::Shop::TaxDriver::Generic', $tests unless $loaded;
####################################################################### #######################################################################
# #
# new # new
@ -231,7 +227,8 @@ SKIP: {
## ##
######################################################################## ########################################################################
$storage = $taxer->exportTaxData(); my $storage = $taxer->exportTaxData();
WebGUI::Test->addToCleanup($storage);
isa_ok($storage, 'WebGUI::Storage', 'exportTaxData returns a WebGUI::Storage object'); isa_ok($storage, 'WebGUI::Storage', 'exportTaxData returns a WebGUI::Storage object');
is(substr($storage->getPathFrag, 0, 5), 'temp/', 'The storage object is in the temporary area'); is(substr($storage->getPathFrag, 0, 5), 'temp/', 'The storage object is in the temporary area');
ok(-e $storage->getPath('siteTaxData.csv'), 'siteTaxData.csv file exists in the storage object'); ok(-e $storage->getPath('siteTaxData.csv'), 'siteTaxData.csv file exists in the storage object');
@ -542,6 +539,7 @@ SKIP: {
##Build a cart, add some Donation SKUs to it. Set one to be taxable. ##Build a cart, add some Donation SKUs to it. Set one to be taxable.
my $cart = WebGUI::Shop::Cart->newBySession($session); my $cart = WebGUI::Shop::Cart->newBySession($session);
WebGUI::Test->addToCleanup($cart);
# is($taxer->calculate($cart), 0, 'calculate returns 0 if there is no shippingAddressId in the cart'); # is($taxer->calculate($cart), 0, 'calculate returns 0 if there is no shippingAddressId in the cart');
@ -552,59 +550,43 @@ SKIP: {
WebGUI::Test->getTestCollateralPath('taxTables/largeTaxTable.csv') WebGUI::Test->getTestCollateralPath('taxTables/largeTaxTable.csv')
), ),
$taxableDonation = WebGUI::Asset->getRoot($session)->addChild({ my $taxableDonation = WebGUI::Asset->getRoot($session)->addChild({
className => 'WebGUI::Asset::Sku::Donation', className => 'WebGUI::Asset::Sku::Donation',
title => 'Taxable donation', title => 'Taxable donation',
defaultPrice => 100.00, defaultPrice => 100.00,
}); });
my $tag1 = WebGUI::VersionTag->getWorking($session);
$tag1->commit;
WebGUI::Test->addToCleanup($tag1);
$taxableDonation = $taxableDonation->cloneFromDb;
is($taxer->getTaxRate($taxableDonation), 0, 'calculate returns 0 if there is no shippingAddressId in the cart'); is($taxer->getTaxRate($taxableDonation), 0, 'calculate returns 0 if there is no shippingAddressId in the cart');
# $cart->addItem($taxableDonation);
# foreach my $item (@{ $cart->getItems }) {
# $item->setQuantity(1);
# }
my $tax = $taxer->getTaxRate( $taxableDonation, $taxingAddress ); my $tax = $taxer->getTaxRate( $taxableDonation, $taxingAddress );
is($tax, 5.5, 'calculate: simple tax calculation on 1 item in the cart'); is($tax, 5.5, 'calculate: simple tax calculation on 1 item in the cart');
$cart->update({ shippingAddressId => $taxFreeAddress->getId}); $cart->update({ shippingAddressId => $taxFreeAddress->getId});
is($taxer->getTaxRate( $taxableDonation, $taxFreeAddress ), 0, 'calculate: simple tax calculation on 1 item in the cart, tax free location'); is($taxer->getTaxRate( $taxableDonation, $taxFreeAddress ), 0, 'calculate: simple tax calculation on 1 item in the cart, tax free location');
# foreach my $item (@{ $cart->getItems }) { my $taxFreeDonation = WebGUI::Asset->getRoot($session)->addChild({
# $item->setQuantity(2);
# }
#
# $cart->update({ shippingAddressId => $taxingAddress->getId});
# is($taxer->calculate($cart), 11, 'calculate: simple tax calculation on 1 item in the cart, qty 2');
$taxFreeDonation = WebGUI::Asset->getRoot($session)->addChild({
className => 'WebGUI::Asset::Sku::Donation', className => 'WebGUI::Asset::Sku::Donation',
title => 'Tax Free Donation', title => 'Tax Free Donation',
defaultPrice => 100.00, defaultPrice => 100.00,
}); });
my $tag2 = WebGUI::VersionTag->getWorking($session);
$tag2->commit;
WebGUI::Test->addToCleanup($tag2);
$taxFreeDonation = $taxFreeDonation->cloneFromDb;
$taxFreeDonation->setTaxConfiguration( 'WebGUI::Shop::TaxDriver::Generic', { $taxFreeDonation->setTaxConfiguration( 'WebGUI::Shop::TaxDriver::Generic', {
overrideTaxRate => 1, overrideTaxRate => 1,
taxRateOverride => 0, taxRateOverride => 0,
}); });
# $cart->addItem($taxFreeDonation);
# foreach my $item (@{ $cart->getItems }) {
# $item->setQuantity(1);
# }
is($taxer->getTaxRate( $taxFreeDonation, $taxingAddress), 0, 'getTaxRate: tax rate override should override tax derived from address'); is($taxer->getTaxRate( $taxFreeDonation, $taxingAddress), 0, 'getTaxRate: tax rate override should override tax derived from address');
# my $remoteItem = $cart->addItem($taxableDonation);
# $remoteItem->update({shippingAddressId => $taxFreeAddress->getId});
#
# foreach my $item (@{ $cart->getItems }) {
# $item->setQuantity(1);
# }
# is($taxer->calculate($cart), 5.5, 'calculate: simple tax calculation on 2 items in the cart, 1 without taxes, 1 shipped to a location with no taxes');
####################################################################### #######################################################################
# #
# www_getTaxesAsJson # www_getTaxesAsJson
@ -648,7 +630,6 @@ SKIP: {
$book->delete; $book->delete;
$taxableDonation->purge; $taxableDonation->purge;
$taxFreeDonation->purge; $taxFreeDonation->purge;
}
sub getAddExceptions { sub getAddExceptions {
my $session = shift; my $session = shift;
@ -690,16 +671,4 @@ sub getAddExceptions {
# Cleanup # Cleanup
END { END {
$session->db->write('delete from tax_generic_rates'); $session->db->write('delete from tax_generic_rates');
$session->db->write('delete from cart');
$session->db->write('delete from addressBook');
$session->db->write('delete from address');
$storage->delete;
if (defined $taxableDonation and ref $taxableDonation eq 'WebGUI::Sku::Donation') {
$taxableDonation->purge;
}
if (defined $taxFreeDonation and ref $taxFreeDonation eq 'WebGUI::Sku::Donation') {
$taxFreeDonation->purge;
}
} }