function OgNodeAccess::testNodeUpdateAudienceField in Organic groups 7.2
Assert a user cannot assign an existing node to a group they don't have "create" permissions.
File
- ./
og.test, line 292
Class
- OgNodeAccess
- Test Group node access. This will test nodes that are groups and group content.
Code
function testNodeUpdateAudienceField() {
// Set Node access strict variable.
variable_set('og_node_access_strict', TRUE);
$editor_user = $this->editor_user;
// Add editor to a single groups.
og_group('node', $this->group1, array(
'entity' => $editor_user,
));
og_group('node', $this->group2, array(
'entity' => $editor_user,
));
// Add group-content to a single group.
og_group('node', $this->group1, array(
'entity_type' => 'node',
'entity' => $this->group_content,
));
// Allow member to update and create.
$og_roles = array_flip(og_roles('node', 'page'));
$permissions = array(
'create article content' => 1,
'update any article content' => 1,
);
og_role_change_permissions($og_roles[OG_AUTHENTICATED_ROLE], $permissions);
// Login and try to edit this node
$this
->drupalLogin($this->editor_user);
$this
->drupalGet('node/' . $this->group_content->nid . '/edit');
$name = 'og_group_ref[und][0][default][]';
$xpath = $this
->buildXPathQuery('//select[@name=:name]', array(
':name' => $name,
));
$fields = $this
->xpath($xpath);
$this
->assertTrue(!empty($fields[0]->option[2]), 'User can assign group-content to a new group.');
// Allow member to update but not create.
$og_roles = array_flip(og_roles('node', 'page'));
$permissions = array(
'create article content' => 0,
'update any article content' => 1,
);
og_role_change_permissions($og_roles[OG_AUTHENTICATED_ROLE], $permissions);
$this
->drupalGet('node/' . $this->group_content->nid . '/edit');
$xpath = $this
->buildXPathQuery('//select[@name=:name]', array(
':name' => $name,
));
$fields = $this
->xpath($xpath);
$this
->assertFalse(!empty($fields[0]->option[2]), 'User cannot assign group-content to a new group.');
// Test for retaining groups on node save.
$this
->drupalPost('node/' . $this->group_content->nid . '/edit', array(), t('Save'));
$entity_groups = og_get_entity_groups('node', $this->group_content->nid);
$this
->assertFalse(in_array($this->group2->nid, $entity_groups['node']), 'Content retains original groups after saving node form.');
}