You are here

function OgEntityFieldQueryTestCase::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 1420

Class

OgEntityFieldQueryTestCase
Test queying group-audience fields using entityFieldQuery.

Code

function setUp() {
  parent::setUp('og', 'entity_feature');
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $type = $this
    ->drupalCreateContentType();
  $group_type = $type->type;
  $type = $this
    ->drupalCreateContentType();
  $group_content_type = $type->type;
  og_create_field(OG_GROUP_FIELD, 'node', $group_type);
  og_create_field(OG_GROUP_FIELD, 'entity_test', 'main');

  // Add audience field to reference node.
  $og_field = og_fields_info(OG_AUDIENCE_FIELD);
  og_create_field('og_node', 'node', $group_content_type, $og_field);
  og_create_field('og_node', 'entity_test', 'test', $og_field);

  // Add audience field to reference entity-test.
  $og_field['field']['settings']['target_type'] = 'entity_test';
  og_create_field('og_entity_test', 'node', $group_content_type, $og_field);
  og_create_field('og_entity_test', 'user', 'user', $og_field);

  // Create a non-group audience, entity reference field.
  $field = array(
    'entity_types' => array(
      'node',
    ),
    'settings' => array(
      'handler' => 'base',
      'target_type' => 'node',
      'handler_settings' => array(
        'target_bundles' => array(),
      ),
    ),
    'field_name' => 'node_reference',
    'type' => 'entityreference',
    'cardinality' => 1,
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'node_reference',
    'bundle' => $group_content_type,
    'entity_type' => 'node',
  );
  field_create_instance($instance);

  // Create two groups.
  $group1 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $wrapper = entity_metadata_wrapper('entity_test', $group1);
  $wrapper->{OG_GROUP_FIELD}
    ->set(1);
  $wrapper
    ->save();
  $settings = array(
    'type' => $group_type,
    'uid' => $user1->uid,
  );
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $group2 = $this
    ->drupalCreateNode($settings);

  // Create group-content.
  $settings = array(
    'type' => $group_content_type,
    'uid' => $user1->uid,
  );
  $node = $this
    ->drupalCreateNode($settings);
  $wrapper = entity_metadata_wrapper('node', $node);
  $wrapper->node_reference
    ->set($group2);
  $wrapper
    ->save();
  $values = array(
    'entity_type' => 'node',
    'entity' => $node,
  );
  og_group('entity_test', $group1, $values);
  og_group('node', $group2, $values);
  $entity_test = entity_create('entity_test', array(
    'name' => 'test',
    'uid' => $user1->uid,
  ));
  $entity_test
    ->save();
  $values = array(
    'entity_type' => 'entity_test',
    'entity' => $entity_test,
  );
  og_group('node', $group2, $values);
  $values = array(
    'entity_type' => 'user',
    'entity' => $user2,
  );
  og_group('node', $group2, $values);
  $this->group1 = $group1;
  $this->group2 = $group2;
  $this->node = $node;
  $this->user1 = $user1;
  $this->user2 = $user2;
  $this->entity_test = $entity_test;
}