You are here

function OgAutoCompleteAccessibleGroupsValidation::testAuthenticatedUserCantReferenceToPrivateGroup in Organic groups 7.2

Verify that a user can't publish content into group that he isn't a member.

File

./og.test, line 2447

Class

OgAutoCompleteAccessibleGroupsValidation
Test for publishing content into group the user is not a member.

Code

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

  // Try to publish content into group the user is not a member.
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content',
    'og_group_ref[und][0][default][0][target_id]' => $this->group_node_2->title . '(' . $this->group_node_2->nid . ')',
  ), 'Save');
  $this
    ->assertText('The referenced group (node: ' . $this->group_node_2->nid . ') is invalid.', 'The reference to group the user is not accessible has achieved');

  // Try to publish content into group that doesn't exist.
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content',
    'og_group_ref[und][0][default][0][target_id]' => 'foo (900)',
  ), 'Save');
  $this
    ->assertText('The referenced group (node: 900) is invalid.', 'The reference to group the user is not accessible has achieved');

  // 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][0][target_id]' => $this->group_node_1->title . '(' . $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
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content 3',
    'og_group_ref[und][0][default][0][target_id]' => $this->group_node_2->title . '(' . $this->group_node_2->nid . ')',
  ), 'Save');
  $this
    ->assertText('The referenced group (node: ' . $this->group_node_2->nid . ') is invalid.', 'The reference to group the user is not accessible has achieved');
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content 3',
    'og_group_ref[und][0][admin][0][target_id]' => $this->group_node_2->title . '(' . $this->group_node_2->nid . ')',
  ), 'Save');
  $this
    ->assertText('Group content New group content 3 has been created.', 'The group content created successfully');
  $this
    ->drupalPost('node/add/group_content', array(
    'title' => 'New group content 3',
    'og_group_ref[und][0][admin][0][target_id]' => 'foo (900)',
  ), 'Save');
  $this
    ->assertText('The referenced group (node: 900) is invalid.', 'The reference to group the user is not accessible has achieved');

  // 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][0][target_id]' => $this->group_node_1->title . '(' . $this->group_node_1->nid . ')',
  ), 'Save');
  $this
    ->assertText('Group content New group content 4 has been created.', 'The group content created successfully');
}