You are here

function OgSelectAccessibleGroupsValidation::testAuthenticatedUserCantReferenceToPrivateGroup in Organic groups 7.2

Verify that a user can't publish content into group that he isn't a member of (either admin or not).

File

./og.test, line 2530

Class

OgSelectAccessibleGroupsValidation
Test for publishing content using a select widget.

Code

function testAuthenticatedUserCantReferenceToPrivateGroup() {
  $this
    ->drupalLogin($this->group_member);

  // Try to publish content into group the user is not a member.
  $this
    ->drupalGet('node/add/group_content');
  $this
    ->assertNoRaw('<option value="' . $this->group_node_2->nid . '">' . $this->group_node_2->title . '</option>', 'The reference to group the user is not a member of cannot be selected.');
  $this
    ->assertRaw('<option value="' . $this->group_node_1->nid . '">' . $this->group_node_1->title . '</option>', 'The reference to group the user is a member of can be selected.');

  // Try to publish content into the group the user is a member of.
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content 2',
    'og_group_ref[und][0][default][]' => array(
      $this->group_node_1->nid,
    ),
  ), 'Save');
  $this
    ->assertText('Group content New group content 2 has been created.', 'The group content created successfully');

  // Testing the widgets my group and other groups.
  $this
    ->drupalLogin($this->group_owner);
  $this
    ->drupalGet('node/add/group_content');
  $this
    ->assertNoRaw('<option value="' . $this->group_node_2->nid . '">' . $this->group_node_2->title . '</option>', 'The reference to group the user is not a member of cannot be selected.');
  $this
    ->assertRaw('<option value="' . $this->group_node_1->nid . '">' . $this->group_node_1->title . '</option>', 'The reference to group the user is a member of can be selected.');

  // Try to publish content into the group the user is a member of.
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content 4',
    'og_group_ref[und][0][default][]' => array(
      $this->group_node_1->nid,
    ),
  ), 'Save');
  $this
    ->assertText('Group content New group content 4 has been created.', 'The group content created successfully');
}