You are here

public function OgUserCanPublishGroupContentTypeOnlyInGroup::setUp in Organic groups 7.2

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

./og.test, line 2276

Class

OgUserCanPublishGroupContentTypeOnlyInGroup
Verify that users only with OG permissions can post only inside a group

Code

public function setUp() {
  parent::setUp('og');

  // Create a group content type.
  $group = $this
    ->drupalCreateContentType();
  og_create_field(OG_GROUP_FIELD, 'node', $group->type);

  // Create the group.
  $settings = array(
    'type' => $group->type,
    OG_GROUP_FIELD . '[und][0][value]' => 1,
    'uid' => 1,
  );
  $this->group = $this
    ->drupalCreateNode($settings);

  // Create the group content content type.
  $this->group_content = $this
    ->drupalCreateContentType();

  // Attach the audience field.
  og_create_field(OG_AUDIENCE_FIELD, 'node', $this->group_content->type);

  // Add permission to the group.
  $og_roles = og_roles('node', $group->type);
  $rid = array_search(OG_AUTHENTICATED_ROLE, $og_roles);
  og_role_change_permissions($rid, array(
    'create ' . $this->group_content->type . ' content' => 1,
    'update own ' . $this->group_content->type . ' content' => 1,
  ));

  // Creating users.
  $this->group_user = $this
    ->drupalCreateUser();
  $this->site_user = $this
    ->drupalCreateUser(array(
    'create ' . $this->group_content->type . ' content',
    'edit own ' . $this->group_content->type . ' content',
  ));
  og_group('node', $this->group->nid, array(
    'entity' => $this->group_user,
  ));
}