You are here

public function OgUserCanPublishGroupContentTypeOnlyInGroup::testGroupUserCanPostGroupContentOnlyInGroup in Organic groups 7.2

Grant to a user the permission to publish a node of a group content and verify that he can't create a node of that content type outside a group.

File

./og.test, line 2316

Class

OgUserCanPublishGroupContentTypeOnlyInGroup
Verify that users only with OG permissions can post only inside a group

Code

public function testGroupUserCanPostGroupContentOnlyInGroup() {
  $node_title = $this
    ->randomName();
  $this
    ->drupalLogin($this->group_user);
  $this
    ->drupalPost('node/add', array(
    'title' => $node_title,
  ), t('Save'));
  $this
    ->assertText("You must select one or more groups for this content", "The user can't publish a content outside a group");

  // Check the user can publish node inside the group.
  $edit = array(
    'title' => $node_title,
    'og_group_ref[und][0][default][]' => array(
      $this->group->nid,
    ),
  );
  $this
    ->drupalPost('node/add', $edit, t('Save'));
  $this
    ->assertText($this->group_content->type . " " . $node_title . " has been created.", "The user can create content inside a group.");

  // Check the user can edit the node.
  $query = new entityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'node')
    ->propertyCondition('title', $node_title)
    ->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $this->group->nid)
    ->execute();
  $node_title = $this
    ->randomName();
  $edit = array(
    'title' => $node_title,
    'og_group_ref[und][0][default][]' => array(),
  );
  $this
    ->drupalPost('node/' . reset($result['node'])->nid . '/edit', $edit, t('Save'));
  $this
    ->assertText("You must select one or more groups for this content", "The user can't edit a content outside a group");
  $edit = array(
    'title' => $node_title,
    'og_group_ref[und][0][default][]' => array(
      $this->group->nid,
    ),
  );
  $this
    ->drupalPost('node/' . reset($result['node'])->nid . '/edit', $edit, t('Save'));
  $this
    ->assertText($this->group_content->type . " " . $node_title . " has been updated.", "The user can edit content inside a group.");
}