You are here

function OgAccessTestCase::testAccessChangeBatchApi in Organic groups 7.2

Test if group content privacy is changing when group privacy is changed.

File

og_access/og_access.test, line 50
Test organic groups access module.

Class

OgAccessTestCase
Test OG access.

Code

function testAccessChangeBatchApi() {
  $settings = array(
    'type' => $this->group_content_type,
    'uid' => $this->user1->uid,
  );

  // Create group content.
  $node1 = $this
    ->drupalCreateNode($settings);
  $values = array(
    'entity_type' => 'node',
    'entity' => $node1,
  );
  og_group('node', $this->group_node, $values);
  $node1 = node_load($node1->nid);
  $this
    ->assertFalse(node_access('view', $this->group_node, $this->user2), 'Other user should not see the group');

  // Group is private. We are changing it to public.
  $this
    ->drupalLogin($this->user1);
  $edit = array(
    'group_access[und]' => 0,
  );
  $this
    ->drupalPost('node/' . $this->group_node->nid . '/edit', $edit, 'Save');
  drupal_static_reset();
  $this
    ->assertTrue(node_access('view', $node1, $this->user2), 'Other user should be able to see the node');
  $this
    ->assertTrue(node_access('view', $this->group_node, $this->user2), 'Other user should be able to see the group');

  // Group is public. We are changing it to private.
  $this
    ->drupalLogin($this->user1);
  $edit = array(
    'group_access[und]' => 1,
  );
  $this
    ->drupalPost('node/' . $this->group_node->nid . '/edit', $edit, 'Save');
  $this->group_node = node_load($this->group_node->nid);
  drupal_static_reset();
  $this
    ->assertFalse(node_access('view', $node1, $this->user2), 'Other user should not see the node');
  $this
    ->assertFalse(node_access('view', $this->group_node, $this->user2), 'Other user should not see the group');
}