You are here

function MessageSubscribeSubscribersTest::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 166
Test for the Message subscribe module.

Class

MessageSubscribeSubscribersTest
Test getting subscribes from context.

Code

function setUp() {
  parent::setUp('message_subscribe', 'flag', 'taxonomy');

  // Create node-type.
  $node_type = 'article';

  // Enable flags.
  $flags = flag_get_default_flags(TRUE);
  $flag = $flags['subscribe_node'];
  $flag->types[] = $node_type;
  $flag
    ->save();
  $flag
    ->enable();
  $flag = $flags['subscribe_user'];
  $flag
    ->save();
  $flag
    ->enable();

  // Reset our cache so our permissions show up.
  drupal_static_reset('flag_get_flags');

  // Reset permissions so that permissions for this flag are available.
  $this
    ->checkPermissions(array(), TRUE);
  $user1 = $this
    ->drupalCreateUser(array(
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ));
  $user2 = $this
    ->drupalCreateUser(array(
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ));
  $user_blocked = $this
    ->drupalCreateUser(array(
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ));

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

  // User1, User2 and user_blocked flag node1.
  flag('flag', 'subscribe_node', $node->nid, $user1);
  flag('flag', 'subscribe_node', $node->nid, $user2);
  flag('flag', 'subscribe_node', $node->nid, $user_blocked);
  flag('flag', 'subscribe_node', $node1->nid, $user_blocked);

  // User2 flags User1.
  flag('flag', 'subscribe_user', $user1->uid, $user2);

  // Create a dummy message-type.
  $message_type = message_type_create('foo', array(
    'message_text' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Example text.',
        ),
      ),
    ),
  ));
  $message_type
    ->save();
  $this->node = $node;
  $this->node1 = $node1;
  $this->user1 = $user1;
  $this->user2 = $user2;

  // $user_blocked is blocked in order to test
  // $subscribe_options['notify blocked users'].
  $user_blocked->status = 0;
  user_save($user_blocked);
  $this->user_blocked = $user_blocked;

  // Override default notifiers.
  variable_set('message_subscribe_default_notifiers', array());
}