Move Auth cleanup into a addToCleanup sub.
This commit is contained in:
parent
ab2be62157
commit
d93238d53c
1 changed files with 19 additions and 22 deletions
41
t/Auth.t
41
t/Auth.t
|
|
@ -49,6 +49,25 @@ $auth = WebGUI::Auth->new( $session, $AUTH_METHOD );
|
|||
my $username = $session->id->generate;
|
||||
push @cleanupUsernames, $username;
|
||||
$output = $auth->createAccountSave( $username, { }, "PASSWORD" );
|
||||
WebGUI::Test->addToCleanup(sub {
|
||||
for my $username ( @cleanupUsernames ) {
|
||||
# We don't create actual, real users, so we have to cleanup by hand
|
||||
my $userId = $session->db->quickScalar(
|
||||
"SELECT userId FROM users WHERE username=?",
|
||||
[ $username ]
|
||||
);
|
||||
|
||||
my @tableList
|
||||
= qw{authentication users userProfileData groupings inbox userLoginLog};
|
||||
|
||||
for my $table ( @tableList ) {
|
||||
$session->db->write(
|
||||
"DELETE FROM $table WHERE userId=?",
|
||||
[ $userId ]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
is(
|
||||
$session->http->getRedirectLocation, 'REDIRECT_URL',
|
||||
|
|
@ -83,25 +102,3 @@ is $output, undef, 'login returns undef when showMessageOnLogin is false';
|
|||
# Session Cleanup
|
||||
$session->{_request} = $oldRequest;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
for my $username ( @cleanupUsernames ) {
|
||||
# We don't create actual, real users, so we have to cleanup by hand
|
||||
my $userId = $session->db->quickScalar(
|
||||
"SELECT userId FROM users WHERE username=?",
|
||||
[ $username ]
|
||||
);
|
||||
|
||||
my @tableList
|
||||
= qw{authentication users userProfileData groupings inbox userLoginLog};
|
||||
|
||||
for my $table ( @tableList ) {
|
||||
$session->db->write(
|
||||
"DELETE FROM $table WHERE userId=?",
|
||||
[ $userId ]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue