function OgGroupAndUngroup::testGroupAndUngroup in Organic groups 7
Same name and namespace in other branches
- 7.2 og.test \OgGroupAndUngroup::testGroupAndUngroup()
Test group and ungroup of content.
File
- ./
og.test, line 547
Class
- OgGroupAndUngroup
- Test Group content handeling.
Code
function testGroupAndUngroup() {
$admin_user = $this
->drupalCreateUser();
$web_user = $this
->drupalCreateUser();
$this
->drupalLogin($web_user);
// Create a group.
$entity = entity_create('entity_test', array(
'name' => 'main',
'uid' => $admin_user->uid,
));
$entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
$entity
->save();
$group1 = og_get_group('entity_test', $entity->pid);
// Create another group.
$entity = entity_create('entity_test', array(
'name' => 'main',
'uid' => $admin_user->uid,
));
$entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
$entity
->save();
$group2 = og_get_group('entity_test', $entity->pid);
// Create a group content.
$node = entity_create('node', array(
'type' => 'article',
'title' => $this
->randomName(),
'uid' => $web_user->uid,
));
entity_save('node', $node);
$this
->assertFalse(og_is_member($group1->gid, 'node', $node), t('Node is not assigned to group1.'));
$values = array(
'entity type' => 'node',
'entity' => $node,
);
og_group($group1->gid, $values);
$this
->assertTrue(og_is_member($group1->gid, 'node', $node), t('Node is now assigned to group1.'));
$this
->assertFalse(og_is_member($group2->gid, 'node', $node), t('Node is not assigned to group2.'));
$values = array(
'entity type' => 'node',
'entity' => $node,
);
og_group($group1->gid, $values);
og_group($group2->gid, $values);
$this
->assertTrue(og_is_member($group1->gid, 'node', $node), t('Node is still assigned to group1.'));
$this
->assertTrue(og_is_member($group2->gid, 'node', $node), t('Node is now assigned to group2.'));
og_ungroup($group2->gid, 'node', $node);
$this
->assertFalse(og_is_member($group2->gid, 'node', $node), t('Node is no longer assigned to group2.'));
}