You are here

function UserRelationshipsApiSocnetTestCase::testIsRelated in User Relationships 6

File

user_relationships_api/tests/user_relationships_api.socnet.test, line 280
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 testIsRelated() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();

  //one way from 1 to 2
  user_relationships_request_relationship($user1, $user2, $this->rtypes['oneway']->rtid, TRUE);

  //a pending relationship from 1 to 2
  user_relationships_request_relationship($user1, $user2, $this->rtypes['approval-oneway']->rtid, FALSE);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid);
  $this
    ->assertTrue(is_array($result));
  $this
    ->assertTrue($result[0] === TRUE);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, 'oneway');
  $this
    ->assertTrue(is_array($result));
  $this
    ->assertTrue($result[0] === TRUE);
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, NULL, 'one-way');
  $this
    ->assertTrue(is_array($result));
  $this
    ->assertTrue($result[0] === TRUE);

  //these should be false
  $result = module_invoke_all('socnet_is_related', $user1->uid, $user2->uid, 'missing');
  $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);
}