You are here

function UserRelationshipsApiSocnetTestCase::testIsPending in User Relationships 6

File

user_relationships_api/tests/user_relationships_api.socnet.test, line 229
Social networking hook API testcase @author Alex Karshakevich http://drupal.org/user/183217

Class

UserRelationshipsApiSocnetTestCase
@file Social networking hook API testcase @author Alex Karshakevich http://drupal.org/user/183217

Code

function testIsPending() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();

  //create an established relationship
  user_relationships_request_relationship($user1, $user2, $this->rtypes['oneway']->rtid, TRUE);

  //these should all be false
  $result = module_invoke_all('socnet_is_pending', $user1->uid, $user2->uid);
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_pending', $user1->uid, $user2->uid, 'one-way');
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_pending', $user1->uid, $user2->uid, 'approval');
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_related', $user2->uid, $user1->uid);
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_related', $user2->uid, $user1->uid, NULL, 'one-way');
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_related', $user2->uid, $user1->uid, NULL, 'two-way');
  $this
    ->assertTrue(count($result) == 0);

  //now add a pending relationship from 1 to 2
  $rel2 = user_relationships_request_relationship($user1, $user2, $this->rtypes['approval']->rtid, FALSE);

  //these should be true
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid);
  $this
    ->assertTrue(count($result) == 1);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, 'approval');
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, NULL, 'two-way');
  $this
    ->assertTrue(count($result) == 0);

  //test other direction
  $result = module_invoke_all('socnet_is_related', $user2->uid, $user1->uid);
  $this
    ->assertTrue(count($result) == 0);

  //approve the pending relationship
  $rel2->approved = TRUE;
  user_relationships_save_relationship($rel2, 'approve');

  //now there should be no pending
  $result = module_invoke_all('socnet_is_pending', $user1->uid, $user2->uid);
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_pending', $user2->uid, $user1->uid);
  $this
    ->assertTrue(count($result) == 0);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, 'approval');
  $this
    ->assertTrue(count($result) == 1);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, NULL, 'two-way');
  $this
    ->assertTrue(count($result) == 1);
}