You are here

function OgBehaviorHandlerTestCase::testGroupAudienceField in Organic groups 7.2

Test piping group association via the group-audience field.

File

./og.test, line 1875

Class

OgBehaviorHandlerTestCase

Code

function testGroupAudienceField() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $entity1 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $wrapper = entity_metadata_wrapper('entity_test', $entity1);
  $wrapper->{OG_GROUP_FIELD}
    ->set(1);
  $wrapper
    ->save();
  $settings = array();
  $settings['type'] = $this->group_content;
  $settings['uid'] = $user2->uid;
  $node = $this
    ->drupalCreateNode($settings);
  $wrapper = entity_metadata_wrapper('node', $node);
  $this
    ->assertFalse(og_is_member('entity_test', $entity1->pid, 'node', $node), t('Node is not assigned to group1.'));
  $wrapper->{OG_AUDIENCE_FIELD}[] = $entity1->pid;
  $wrapper
    ->save();
  $og_membership = og_get_membership('entity_test', $entity1->pid, 'node', $node->nid);
  $id = $og_membership->id;
  $this
    ->assertTrue(og_is_member('entity_test', $entity1->pid, 'node', $node), t('Node is assigned to group1 with active state.'));
  $wrapper->{OG_AUDIENCE_FIELD}
    ->set(NULL);
  $wrapper
    ->save();
  $this
    ->assertFalse(og_get_entity_groups('node', $node), t('Node is not associated with any group.'));
}