You are here

function MessageSubscribeContextTest::setUp in Message Subscribe 7

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

./message_subscribe.test, line 22
Test for the Message subscribe module.

Class

MessageSubscribeContextTest
Test getting context from entity.

Code

function setUp() {
  parent::setUp('message_subscribe', 'taxonomy', 'og');
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $user3 = $this
    ->drupalCreateUser();

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

  // Create node-type.
  $type = $this
    ->drupalCreateContentType();
  $node_type = $type->type;
  og_create_field(OG_AUDIENCE_FIELD, 'node', $node_type);

  // Create vocabulary and terms.
  $vocabulary = new stdClass();
  $vocabulary->name = 'Terms';
  $vocabulary->machine_name = 'terms';
  taxonomy_vocabulary_save($vocabulary);

  // Create terms.
  $tids = array();
  for ($i = 1; $i <= 3; $i++) {
    $term = new stdClass();
    $term->name = "term {$i}";
    $term->vid = $vocabulary->vid;
    taxonomy_term_save($term);
    $tids[] = $term->tid;
  }

  // Create a multiple terms-reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'node',
    ),
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => 'terms',
          'parent' => 0,
        ),
      ),
    ),
    'field_name' => 'field_terms_ref',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'field_terms_ref',
    'bundle' => $node_type,
    'entity_type' => 'node',
  );
  field_create_instance($instance);

  // Create OG group.
  $settings = array();
  $settings['type'] = $group_type;
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $settings['uid'] = $user3->uid;
  $group = $this
    ->drupalCreateNode($settings);

  // Create node.
  $settings = array();
  $settings['type'] = $node_type;
  $settings['uid'] = $user1->uid;
  $node = $this
    ->drupalCreateNode($settings);

  // Assign node to terms.
  $wrapper = entity_metadata_wrapper('node', $node);
  $wrapper->field_terms_ref
    ->set($tids);
  $wrapper
    ->save();

  // Assign node to group.
  og_group('node', $group->nid, array(
    'entity_type' => 'node',
    'entity' => $node,
  ));

  // Add comment.
  $comment = (object) array(
    'subject' => 'topic',
    'nid' => $node->nid,
    'uid' => $user2->uid,
    'cid' => FALSE,
    'pid' => 0,
    'homepage' => '',
    'language' => LANGUAGE_NONE,
  );
  comment_save($comment);
  $this->node = $node;
  $this->group = $group;
  $this->comment = $comment;
  $this->tids = $tids;
}