diff -drup a/user_relationship_privatemsg/user_relationship_privatemsg.test b/user_relationship_privatemsg/user_relationship_privatemsg.test --- a/user_relationship_privatemsg/user_relationship_privatemsg.test Wed Jan 23 05:19:06 2013 +++ b/user_relationship_privatemsg/user_relationship_privatemsg.test Thu Jan 24 10:18:49 2013 @@ -12,7 +12,7 @@ class UserRelationshipsPrivatemsgRecipie /** * Implements getInfo(). */ - function getInfo() { + public static function getInfo() { return array( 'name' => t('User Relationships Privatemsg recipients'), 'description' => t('Check relationship recipient type for privatemsg'), @@ -24,14 +24,14 @@ class UserRelationshipsPrivatemsgRecipie /** * Enable required modules. */ - function setUp() { + public function setUp() { return parent::setUp('privatemsg', 'user_relationships', 'user_relationships_ui', 'user_relationship_privatemsg'); } /** * Tests sending a message to related users. */ - function testSendToRelationship() { + public function testSendToRelationship() { // Create relationship. $relationship = array( @@ -52,7 +52,7 @@ class UserRelationshipsPrivatemsgRecipie $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', 'administer user relationships', $maintain_permission, 'write privatemsg to relationships', 'access user profiles')); $userA = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', 'write privatemsg to relationships')); - $userB = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients')); + $userB = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', $maintain_permission)); $this->drupalLogin($admin); @@ -90,6 +90,16 @@ class UserRelationshipsPrivatemsgRecipie $reply = array('body[value]' => $this->randomName(50)); $this->drupalPost(NULL, $reply, t('Send message')); + // Try to send a message to non-related userB. + $this->drupalGet('messages/new'); + $message_to_b = array( + 'recipient' => $userB->name, + 'subject' => $this->randomName(), + 'body[value]' => $this->randomName(50), + ); + $this->drupalPost(NULL, $message_to_b, t('Send message')); + $this->assertText(t('@name does not have an established relationship with you.', array('@name' => $userB->name)), 'Sending to non-related user should fail.'); + // Login as userB and make sure the original message is displayed but not the message nor the username of userA. $this->drupalLogin($userB); $this->drupalGet('messages'); @@ -132,12 +142,80 @@ class UserRelationshipsPrivatemsgRecipie $this->drupalGet('messages'); $this->clickLink($message['subject']); $this->assertText($message['body[value]']); + + // Allow messages to unrelated users. + $edit = array( + 'user_relationships_restrict_privatemsg' => 'all', + ); + $this->drupalPost('admin/config/people/relationships/settings', $edit, t('Save configuration')); + + // Switch to user A again. + $this->drupalLogin($userA); + // Try to send a message to non-related userB. + $this->drupalGet('messages/new'); + $message_to_b = array( + 'recipient' => $userB->name, + 'subject' => $this->randomName(), + 'body[value]' => $this->randomName(50), + ); + $this->drupalPost(NULL, $message_to_b, t('Send message')); + $this->assertText(t('A message has been sent to @name.', array('@name' => $userB->name)), 'Sending to non-related user should succeed.'); + + // Block messages to unrelated users. + $this->drupalLogin($admin); + $edit = array( + 'user_relationships_restrict_privatemsg' => 'relationships', + ); + $this->drupalPost('admin/config/people/relationships/settings', $edit, t('Save configuration')); + + // Change the relationship to make approval required. + $relationship = user_relationships_type_load(array('name' => $relationship['name'])); + $relationship->requires_approval = TRUE; + user_relationships_type_save($relationship); + // Reset static caches. + user_relationships_types_load(TRUE); + + // Switch to user A again. + $this->drupalLogin($userA); + + // Send a relationship request from userA to userB., + $this->drupalGet('relationship/' . $userB->uid . '/request/' . $userA->uid); + $this->drupalPost(NULL, array(), t('Send')); + + // Try to send a message to not-yet-related userB. + $this->drupalGet('messages/new'); + $message_to_b = array( + 'recipient' => $userB->name, + 'subject' => $this->randomName(), + 'body[value]' => $this->randomName(50), + ); + $this->drupalPost(NULL, $message_to_b, t('Send message')); + $this->assertText(t('@name does not have an established relationship with you.', array('@name' => $userB->name)), 'Sending to non-approved user should fail.'); + + // Switch to user B again to approve the request. + $this->drupalLogin($userB); + $this->drupalGet('user/' . $userB->uid . '/relationships/received'); + $this->clickLink(t('Approve')); + $this->drupalPost(NULL, array(), t('Yes')); + + // Now user A should be able to send a message. + $this->drupalLogin($userA); + // Try to send a message to userB. + $this->drupalGet('messages/new'); + $message_to_b = array( + 'recipient' => $userB->name, + 'subject' => $this->randomName(), + 'body[value]' => $this->randomName(50), + ); + $this->drupalPost(NULL, $message_to_b, t('Send message')); + $this->assertText(t('A message has been sent to @name.', array('@name' => $userB->name)), 'Sending to approved related user should succeed.'); + } /** * Test a relationship with bath api processing. */ - function testManyRelations() { + public function testManyRelations() { // Create relationship. $relationship = array(