function OgUiUserPermissionsTestCase::testOgUiUserPermissionChanges in Organic groups 7.2
Same name and namespace in other branches
- 7 og_ui/og_ui.test \OgUiUserPermissionsTestCase::testOgUiUserPermissionChanges()
Change user permissions and check og_user_access().
File
- og_ui/
og_ui.test, line 23
Class
Code
function testOgUiUserPermissionChanges() {
$permissions = array(
'bypass node access',
'administer content types',
'administer group',
);
$admin_user = $this
->drupalCreateUser($permissions);
$web_user = $this
->drupalCreateUser();
$this
->drupalLogin($admin_user);
// Create a group.
$entity1 = entity_create('entity_test', array(
'name' => 'main',
'uid' => $admin_user->uid,
));
$wrapper = entity_metadata_wrapper('entity_test', $entity1);
$wrapper->{OG_GROUP_FIELD}
->set(1);
$wrapper
->save();
$this
->assertTrue(og_user_access('entity_test', $entity1->pid, 'subscribe', $web_user), t('User has "subscribe" permission.'));
// Remove a permission.
$this
->drupalPost('admin/config/group/permissions/entity_test/main', array(
'1[subscribe]' => FALSE,
), t('Save permissions'));
$this
->assertText(t('The changes have been saved.'), t('Successful save message displayed.'));
// FIXME: There is an og_invalidate_cache() on permissions granting
// and revoking, but somehow, we need to do it manually here.
og_invalidate_cache();
$this
->assertFalse(og_user_access('entity_test', $entity1->pid, 'subscribe', $web_user), t('User now does not have "subscribe" permission.'));
// Re-add permission.
$this
->drupalPost('admin/config/group/permissions/entity_test/main', array(
'1[subscribe]' => TRUE,
), t('Save permissions'));
// FIXME: There is an og_invalidate_cache() on permissions granting
// and revoking, but somehow, we need to do it manually here.
og_invalidate_cache();
$this
->assertTrue(og_user_access('entity_test', $entity1->pid, 'subscribe', $web_user), t('User has "subscribe" permission again.'));
}