Add cleanup for Shop::Vendors. More end block removal.

This commit is contained in:
Colin Kuskie 2010-06-07 18:45:59 -07:00
parent 41b7413d01
commit b728eabd7b
4 changed files with 10 additions and 43 deletions

View file

@ -33,8 +33,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 18;
plan tests => 1 + $tests;
plan tests => 18;
#----------------------------------------------------------------------------
# put your tests here
@ -45,10 +44,6 @@ my $storage;
my $newDriver;
my $anotherDriver;
SKIP: {
skip 'Unable to load module WebGUI::Shop::Pay', $tests unless $loaded;
#######################################################################
#
# new
@ -127,6 +122,7 @@ my $options = {
label => 'Cold, stone hard cash',
};
$newDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $options);
WebGUI::Test->addToCleanup($newDriver);
isa_ok($newDriver, 'WebGUI::Shop::PayDriver::Cash', 'added a new, configured Cash driver');
is($newDriver->get('label'), 'Cold, stone hard cash', 'label passed correctly to paydriver');
@ -207,6 +203,7 @@ my $otherOptions = {
label => 'Even harder cash',
};
$anotherDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $otherOptions);
WebGUI::Test->addToCleanup($anotherDriver);
my $gateways = $pay->getPaymentGateways;
my @returnedIds = map {$_->get('label')} @{ $gateways };
@ -232,14 +229,3 @@ cmp_bag(
#
#######################################################################
}
#----------------------------------------------------------------------------
# Cleanup
END {
defined $newDriver and $newDriver->delete;
defined $newDriver and $anotherDriver->delete;
my $count = $session->db->quickScalar('select count(*) from paymentGateway');
is($count, 2, 'WebGUI ships with two drivers by default');
}

View file

@ -43,10 +43,6 @@ my $loaded = use_ok('WebGUI::Shop::ShipDriver');
my $storage;
SKIP: {
skip 'Unable to load module WebGUI::Shop::ShipDriver', $tests unless $loaded;
#######################################################################
#
# definition
@ -163,6 +159,7 @@ my $options = {
};
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
WebGUI::Test->addToCleanup($driver);
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
@ -398,11 +395,3 @@ my $count = $session->db->quickScalar('select count(*) from shipper where shippe
is($count, 0, 'delete deleted the object');
undef $driver;
}
#----------------------------------------------------------------------------
# Cleanup
END {
}

View file

@ -31,8 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 49;
plan tests => 1 + $tests;
plan tests => 49;
#----------------------------------------------------------------------------
# put your tests here
@ -47,10 +46,6 @@ my $guardUser = WebGUI::User->new($session, 'new');
$guardUser->username('guard');
WebGUI::Test->usersToDelete($fenceUser, $guardUser);
SKIP: {
skip 'Unable to load module WebGUI::Shop::Vendor', $tests unless $loaded;
$numberOfVendors = scalar @{ WebGUI::Shop::Vendor->getVendors($session) };
#######################################################################
@ -130,6 +125,7 @@ cmp_deeply(
my $now = WebGUI::DateTime->new($session, time);
eval { $fence = WebGUI::Shop::Vendor->create($session, { userId => $fenceUser->userId, }); };
WebGUI::Test->addToCleanup($fence);
$e = Exception::Class->caught();
ok(!$e, 'No exception thrown by create');
isa_ok($vendor, 'WebGUI::Shop::Vendor', 'create returns correct type of object');
@ -251,6 +247,7 @@ my $defaultVendor = WebGUI::Shop::Vendor->newByUserId($session, 3);
#######################################################################
$guard = WebGUI::Shop::Vendor->create($session, { userId => $guardUser->userId, name => q|Warden Norton|});
WebGUI::Test->addToCleanup($guard);
my $vendorsList = WebGUI::Shop::Vendor->getVendors($session);
cmp_deeply(
$vendorsList,
@ -307,11 +304,4 @@ foreach (keys %completeProps ) {
undef $guard;
}
#----------------------------------------------------------------------------
# Cleanup
END {
$fence->delete;
is( scalar @{ WebGUI::Shop::Vendor->getVendors($session) }, $numberOfVendors, 'No vendors leaked');
}
#vim:ft=perl

View file

@ -796,6 +796,7 @@ were passed in. Currently able to destroy:
WebGUI::Shop::ShipDriver
WebGUI::Shop::PayDriver
WebGUI::Shop::Transaction
WebGUI::Shop::Vendor
WebGUI::Shop::AddressBook
WebGUI::DatabaseLink
WebGUI::LDAPLink
@ -888,6 +889,7 @@ Example call:
'WebGUI::Shop::Transaction' => 'delete',
'WebGUI::Shop::ShipDriver' => 'delete',
'WebGUI::Shop::PayDriver' => 'delete',
'WebGUI::Shop::Vendor' => 'delete',
'WebGUI::Inbox::Message' => 'purge',
'WebGUI::Shop::Cart' => sub {
my $cart = shift;