From 397783f15ddc6d802a82d58d9105332dfb8854be Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 31 Oct 2007 21:15:49 +0000 Subject: [PATCH] final coverage tests to bring User.pm up to 100% --- t/User.t | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/t/User.t b/t/User.t index e1f4265a2..66e45ba5c 100644 --- a/t/User.t +++ b/t/User.t @@ -20,7 +20,7 @@ use WebGUI::Cache; use WebGUI::User; use WebGUI::ProfileField; -use Test::More tests => 127; # increment this value for each test you create +use Test::More tests => 129; # increment this value for each test you create use Test::Deep; my $session = WebGUI::Test->session; @@ -457,29 +457,13 @@ $dude->deleteFromGroups([12]); $dudeGroups = $dude->getGroups(1); cmp_bag($dudeGroups, ['2', '7'], 'Dude belongs to Registered Users, Everyone as unexpired group memberships'); -################################################################ -# -# acceptsPrivateMessages -# -################################################################ - -my $friend = WebGUI::User->new($session, 'new'); -$friend->profileField('allowPrivateMessages', 'all'); -is ($friend->acceptsPrivateMessages(1), 1, 'when allowPrivateMessages=all, anyone can send messages'); -$friend->profileField('allowPrivateMessages', 'none'); -is ($friend->acceptsPrivateMessages($friend->userId), 0, 'when allowPrivateMessages=all, no one can send messages'); - -TODO: { - local $TODO = "Tests that need to be written"; - ok(0, 'Test allowPrivateMessages=friends, with various userIds'); -} - ################################################################ # # getFirstName # ################################################################ +my $friend = WebGUI::User->new($session, 'new'); is($friend->getFirstName, undef, 'with no profile settings, getFirstName returns undef'); $friend->username('friend'); @@ -552,6 +536,26 @@ undef $friendsGroup2; undef $friendsGroup3; undef $neighborClone; +################################################################ +# +# acceptsPrivateMessages +# +################################################################ + +$friend->profileField('allowPrivateMessages', 'all'); +is ($friend->acceptsPrivateMessages(1), 1, 'acceptsPrivateMessages: when allowPrivateMessages=all, anyone can send messages'); +$friend->profileField('allowPrivateMessages', 'none'); +is ($friend->acceptsPrivateMessages($friend->userId), 0, 'acceptsPrivateMessages: when allowPrivateMessages=none, no one can send messages'); + +$neighbor->profileField('allowPrivateMessages', 'friends'); +is ($neighbor->acceptsPrivateMessages($friend->userId), 0, 'acceptsPrivateMessages: when allowPrivateMessages=friends, only friends can send me messages'); +$friend->addToGroups([$neighbor->friends->getId]); +is ($neighbor->acceptsPrivateMessages($friend->userId), 1, 'acceptsPrivateMessages: add $friend to $neighbor friendsGroup, now he can send me messages'); + +$friend->deleteFromGroups([$neighbor->friends->getId]); +$neighbor->profileField('allowPrivateMessages', 'not a valid choice'); +is ($neighbor->acceptsPrivateMessages($friend->userId), 1, 'acceptsPrivateMessages: illegal profile field allows messages to be received from anyone'); + END { foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend) { (defined $account and ref $account eq 'WebGUI::User') and $account->delete;