function UserRelationshipsApiSocnetTestCase::testGetRelatedUsers in User Relationships 6
File
- user_relationships_api/
tests/ user_relationships_api.socnet.test, line 182 - 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 testGetRelatedUsers() {
$u1 = $this
->drupalCreateUser();
$u2 = $this
->drupalCreateUser();
$u3 = $this
->drupalCreateUser();
$u4 = $this
->drupalCreateUser();
//some relationships
//1 knows 2 and 3, with 4 pending, 2 knows 3 and 4
user_relationships_request_relationship($u1, $u2, $this->rtypes['oneway']->rtid, TRUE);
user_relationships_request_relationship($u1, $u3, $this->rtypes['twoway']->rtid, TRUE);
user_relationships_request_relationship($u2, $u3, $this->rtypes['oneway']->rtid, TRUE);
user_relationships_request_relationship($u4, $u2, $this->rtypes['twoway']->rtid, TRUE);
user_relationships_request_relationship($u1, $u4, $this->rtypes['approval']->rtid, FALSE);
//test 1's relationships
$result = module_invoke_all('socnet_get_related_users', $u1->uid);
$this
->assertTrue(count($result) == 2);
$this
->assertTrue(in_array($u2->uid, $result));
$this
->assertTrue(in_array($u3->uid, $result));
$this
->assertFalse(in_array($u1->uid, $result));
$this
->assertFalse(in_array($u4->uid, $result));
//this is pending
$result = module_invoke_all('socnet_get_related_users', $u1->uid, 'oneway');
$this
->assertTrue(count($result) == 1);
$this
->assertTrue(in_array($u2->uid, $result));
$result = module_invoke_all('socnet_get_related_users', $u1->uid, 'approval');
$this
->assertTrue(count($result) == 0);
$result = module_invoke_all('socnet_get_related_users', $u1->uid, NULL, 'one-way');
$this
->assertTrue(count($result) == 1);
$this
->assertTrue(in_array($u2->uid, $result));
$result = module_invoke_all('socnet_get_related_users', $u1->uid, NULL, 'two-way');
$this
->assertTrue(count($result) == 1);
$this
->assertTrue(in_array($u3->uid, $result));
//test 2's relationships
$result = module_invoke_all('socnet_get_related_users', $u2->uid);
$this
->assertTrue(count($result) == 2);
$this
->assertTrue(in_array($u3->uid, $result));
$this
->assertTrue(in_array($u4->uid, $result));
}