diff --git a/lib/WebGUI/Inbox.pm b/lib/WebGUI/Inbox.pm index 24d08d699..77d9cc6df 100644 --- a/lib/WebGUI/Inbox.pm +++ b/lib/WebGUI/Inbox.pm @@ -146,10 +146,11 @@ sub deleteMessagesForUser { my $self = shift; my $user = shift; - my $db = $self->session->db; + my $messages = $self->getMessagesForUser($user, 1e10); my $userId = $user->userId; - $db->write("DELETE FROM inbox_messageState WHERE userId=?",[$userId]); - $db->write("DELETE FROM inbox WHERE userId=? AND (groupId IS NULL OR groupId='')",[$userId]); + foreach my $message (@{ $messages }) { + $message->delete($userId); + } } #------------------------------------------------------------------- diff --git a/t/Shop/Transaction.t b/t/Shop/Transaction.t index 925e9c3ea..3981a46e6 100644 --- a/t/Shop/Transaction.t +++ b/t/Shop/Transaction.t @@ -267,6 +267,7 @@ $templateMock->mock('process', sub { push @templateVars, clone $_[1]; } ); $session->setting->set('shopReceiptEmailTemplateId', $templateId); { + WebGUI::Test->addToCleanup(sub { WebGUI::Test->cleanupAdminInbox(); }); WebGUI::Test->mockAssetId($templateId, $templateMock); $trans->sendNotifications; is(@templateVars, 2, '... called template->process twice'); diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 3128d8dae..c08de3b1f 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -697,6 +697,25 @@ sub assetsToPurge { #---------------------------------------------------------------------------- +=head2 cleanupAdminInbox ( ) + +Push a list of Asset objects onto the stack of assets to be automatically purged +at the end of the test. This will also clean-up all version tags associated +with the Asset. + +This is a class method. + +=cut + +sub cleanupAdminInbox { + my $class = shift; + my $admin = WebGUI::User->new($class->session, '3'); + my $inbox = WebGUI::Inbox->new($class->session); + $inbox->deleteMessagesForUser($admin); +} + +#---------------------------------------------------------------------------- + =head2 groupsToDelete ( $group, [$group ] ) Push a list of group objects onto the stack of groups to be automatically deleted