You are here

function OgDefaultAccessFieldTestCase::testOgDefaultAccessField in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og.test \OgDefaultAccessFieldTestCase::testOgDefaultAccessField()

Test groups with default access field enabled or disabled.

  • Group without default access field.
  • Group with default access field enabled.
  • Previous group with field disabled.

File

./og.test, line 842

Class

OgDefaultAccessFieldTestCase

Code

function testOgDefaultAccessField() {

  // Create user.
  $web_user = $this
    ->drupalCreateUser();

  // Add OG group field to the entity_test's "main" bundle.
  og_create_field(OG_GROUP_FIELD, 'entity_test', 'main');

  // Group without default access field.
  $entity = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $web_user->uid,
  ));
  $entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
  $entity
    ->save();
  $group = og_get_group('entity_test', $entity->pid);
  $this
    ->assertEqual(og_get_global_roles(), og_roles($group->gid), t('Group without default access field is assigned to the global roles and permissions settings.'));

  // Add default access field to the entity_test's "main" bundle.
  og_create_field(OG_DEFAULT_ACCESS_FIELD, 'entity_test', 'main');

  // Group with default access field disabled.
  $entity = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $web_user->uid,
  ));
  $entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
  $entity->{OG_DEFAULT_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'] = 0;
  $entity
    ->save();
  $group = og_get_group('entity_test', $entity->pid);
  $this
    ->assertEqual(og_get_global_roles(), og_roles($group->gid), t('Group with default access field disabled is assigned to the global roles and permissions settings.'));

  // Group with default access field enabled.
  $entity = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $web_user->uid,
  ));
  $entity->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
  $entity->{OG_DEFAULT_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
  $entity
    ->save();
  $group = og_get_group('entity_test', $entity->pid);
  $this
    ->assertNotEqual(og_get_global_roles(), og_roles($group->gid), t('Group with default access field enabled has own roles and permissions settings.'));

  // Disable existing group's default access field.
  $entity->{OG_DEFAULT_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'] = 0;
  $entity
    ->save();
  $this
    ->assertEqual(og_get_global_roles(), og_roles($group->gid), t('Group with enabled default access field that was disabled is assigned to the global roles and permissions settings.'));
}