You are here

function MessageEntityDelete::setUp in Message 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

tests/message.test, line 652

Class

MessageEntityDelete
Test the Message delete on entity delete functionallity.

Code

function setUp() {
  parent::setUp('message', 'entityreference');
  variable_set('message_delete_on_entity_delete', array(
    'node',
    'taxonomy_term',
    'user',
  ));

  // Create a term reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'message',
    ),
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => 'terms',
          'parent' => 0,
        ),
      ),
    ),
    'field_name' => 'field_term_ref',
    'type' => 'taxonomy_term_reference',
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'field_term_ref',
    'bundle' => 'mt1',
    'entity_type' => 'message',
  );
  field_create_instance($instance);

  // Create an multiple-entities-reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'message',
    ),
    'settings' => array(
      'handler' => 'base',
      'target_type' => 'node',
      'handler_settings' => array(
        'target_bundles' => array(),
      ),
    ),
    'field_name' => 'field_nodes_ref',
    'type' => 'entityreference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'field_nodes_ref',
    'bundle' => 'mt1',
    'entity_type' => 'message',
  );
  field_create_instance($instance);

  // Create a multiple-terms-reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'message',
    ),
    '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' => 'mt1',
    'entity_type' => 'message',
  );
  field_create_instance($instance);

  // Create an entity reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'message',
    ),
    'settings' => array(
      'handler' => 'base',
      'target_type' => 'node',
      'handler_settings' => array(
        'target_bundles' => array(),
      ),
    ),
    'field_name' => 'field_node_ref',
    'type' => 'entityreference',
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'field_node_ref',
    'bundle' => 'mt1',
    'entity_type' => 'message',
  );
  field_create_instance($instance);

  // Create an user entity reference field.
  $field = array(
    'translatable' => FALSE,
    'entity_types' => array(
      'message',
    ),
    'settings' => array(
      'handler' => 'base',
      'target_type' => 'user',
      'handler_settings' => array(
        'target_bundles' => array(),
      ),
    ),
    'field_name' => 'field_user_ref',
    'type' => 'entityreference',
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'field_user_ref',
    'bundle' => 'mt1',
    'entity_type' => 'message',
  );
  field_create_instance($instance);

  // Create a terms vocobulary.
  $vocabulary = new stdClass();
  $vocabulary->name = 'Terms';
  $vocabulary->machine_name = 'terms';
  taxonomy_vocabulary_save($vocabulary);
  $message_type = message_type_create('mt1', array());
  $message_type
    ->save();

  // Create nodes and terms.
  for ($i = 1; $i <= 5; $i++) {
    $node = new stdClass();
    $node->type = 'article';
    node_object_prepare($node);
    $node->title = "node {$i}";
    $node->language = LANGUAGE_NONE;
    node_save($node);
    $term = new stdClass();
    $term->name = "term {$i}";
    $term->vid = 1;
    taxonomy_term_save($term);
  }
}