Skip to content

Commit

Permalink
END block cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Jun 15, 2010
1 parent 6c3369d commit 9469941
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
15 changes: 4 additions & 11 deletions t/Asset/Wobject/Survey/Test.t
Expand Up @@ -23,15 +23,9 @@ my $session = WebGUI::Test->session;
# Tests
plan tests => 94;

my ( $s, $t1 );

my $tp = use_ok('TAP::Parser');
my $tpa = use_ok('TAP::Parser::Aggregator');

SKIP: {

skip "Unable to load TAP::Parser and TAP::Parser::Aggregator", 88 unless $tp && $tpa;

#----------------------------------------------------------------------------
# put your tests here
use_ok('WebGUI::Asset::Wobject::Survey::Test');
Expand All @@ -44,8 +38,9 @@ WebGUI::Test->originalConfig('enableSurveyExpressionEngine');
$session->config->set('enableSurveyExpressionEngine', 1);

# Create a Survey
$s = $import_node->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } );
my $s = $import_node->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } );
isa_ok( $s, 'WebGUI::Asset::Wobject::Survey' );
WebGUI::Test->addToCleanup($s);

my $sJSON = $s->surveyJSON;

Expand Down Expand Up @@ -155,7 +150,8 @@ cmp_deeply(
'surveyOrderIndex correct'
);

$t1 = WebGUI::Asset::Wobject::Survey::Test->create( $session, { assetId => $s->getId } );
my $t1 = WebGUI::Asset::Wobject::Survey::Test->create( $session, { assetId => $s->getId } );
WebGUI::Test->addToCleanup(sub {$t1->delete();});
my $spec;

# No tests
Expand Down Expand Up @@ -725,11 +721,8 @@ Hashes differ on element: a
got : '1'
expect : '2'
END_CMP
}

#----------------------------------------------------------------------------
# Cleanup
END {
$s->purge() if $s;
$t1->delete() if $t1;
}
8 changes: 1 addition & 7 deletions t/Crud.t
Expand Up @@ -34,6 +34,7 @@ plan tests => 55; # Increment this number for each test you create

# check table structure
WebGUI::Crud->crud_createTable($session);
WebGUI::Test->addToCleanup(sub { WebGUI::Crud->crud_dropTable($session); });
my $sth = $session->db->read("describe unnamed_crud_table");
my ($col, $type) = $sth->array();
is($col, 'id', "structure: id name");
Expand Down Expand Up @@ -139,11 +140,4 @@ is(WebGUI::Crud->crud_getTableKey($session), 'id', 'default key is id');
is(WebGUI::Crud->crud_getTableName($session), 'unnamed_crud_table', 'default table is unnamed_crud_table');
is(WebGUI::Crud->crud_getSequenceKey($session), '', 'default sequence key is blank');

#----------------------------------------------------------------------------
# Cleanup
END {

WebGUI::Crud->crud_dropTable($session);

}
#vim:ft=perl
36 changes: 13 additions & 23 deletions t/Workflow/Activity/NotifyAboutLowStock.t
Expand Up @@ -23,11 +23,13 @@ use Test::More;
use Test::Exception;
use URI;

plan tests => 20; # increment this value for each test you create
plan tests => 19; # increment this value for each test you create

my $session = WebGUI::Test->session;
$session->user({userId => 3});
my $admin = $session->user;
WebGUI::Test->addToCleanup(sub { WebGUI::Test->cleanupAdminInbox; });
WebGUI::Test->addToCleanup(SQL => "delete from mailQueue where message like '%Threshold=15%'");
my $inbox = WebGUI::Inbox->new($session);

my $import = WebGUI::Asset->getImportNode($session);
Expand Down Expand Up @@ -121,7 +123,7 @@ my $uri = URI->new($url);
is($uri->path, $posters->getUrl, 'Link in message has correct URL path');
is($uri->query, 'func=editVariant;vid='.$marilynVarId, 'Link in message has function and variant id');

wipeMessages($inbox, $admin);
WebGUI::Test->cleanupAdminInbox;
is(scalar @{$inbox->getMessagesForUser($admin)}, 0, 'All messages deleted');
$instance1->delete;

Expand All @@ -147,6 +149,13 @@ $message = $inbox->getMessagesForUser($admin)->[0];
note "Test that the workflow does not die when encountering bad assets";

my $otherPosters = $posters->duplicate;
WebGUI::Test->addToCleanup(sub {
$session->db->write("delete from asset where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from assetData where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from sku where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from Product where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from assetIndex where assetId=?",[$otherPosters->getId]);
});
my $movie_posters = $import->addChild({
className => 'WebGUI::Asset::Sku::Product',
url => 'movie_posters',
Expand Down Expand Up @@ -180,7 +189,7 @@ is($retVal, 'done', 'Workflow is done');

$messages = $inbox->getMessagesForUser($admin);
is(scalar @{$messages}, 1, 'Received one message');
wipeMessages($inbox, $admin);
WebGUI::Test->cleanupAdminInbox;

my $instance4 = WebGUI::Workflow::Instance->create($session,
{
Expand All @@ -198,24 +207,5 @@ is($retVal, 'done', 'Workflow is done');

$messages = $inbox->getMessagesForUser($admin);
is(scalar @{$messages}, 1, 'Still received one message');
wipeMessages($inbox, $admin);

END {
wipeMessages($inbox, $admin);
$messages = $inbox->getMessagesForUser($admin);
is(scalar @{$messages}, 0, 'Inbox cleaned up');
$session->db->write("delete from mailQueue where message like '%Threshold=15%'");
$session->db->write("delete from asset where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from assetData where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from sku where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from Product where assetId=?",[$otherPosters->getId]);
$session->db->write("delete from assetIndex where assetId=?",[$otherPosters->getId]);
}

sub wipeMessages {
my ($inbox, $user) = @_;
foreach my $message (@{ $inbox->getMessagesForUser($user) }) {
$message->delete;
}

}
#vim:ft=perl

0 comments on commit 9469941

Please sign in to comment.