You are here

function Messaging_Methods_Tests::testMessagingMethods in Messaging 6.2

Same name and namespace in other branches
  1. 5 tests/messaging_methods.test \Messaging_Methods_Tests::testMessagingMethods()
  2. 6.4 tests/messaging_methods.test \Messaging_Methods_Tests::testMessagingMethods()
  3. 6 tests/messaging_methods.test \Messaging_Methods_Tests::testMessagingMethods()
  4. 6.3 tests/messaging_methods.test \Messaging_Methods_Tests::testMessagingMethods()
  5. 7 tests/messaging_methods.test \Messaging_Methods_Tests::testMessagingMethods()

Test message sending callbacks for enabled plug-ins

File

tests/messaging_methods.test, line 28

Class

Messaging_Methods_Tests

Code

function testMessagingMethods() {
  $this
    ->messagingStartTest();
  $user = $this
    ->drupalCreateUser();

  // First, with debug disabled, check sending method properties
  variable_set('messaging_debug', 0);
  foreach (messaging_method_info() as $method => $info) {

    // Check for some sending method properties
    $this
      ->assertTrue(!empty($info['name']) && !empty($info['type']) && !empty($info['send callback']) && (!empty($info['destination']) || !empty($info['destination callback'])), 'Send method properties seem to be ok for method: ' . $method);

    // Check existing callback functions
    foreach (array(
      'send',
      'user',
      'prepare',
      'render',
      'presend',
      'aftersend',
      'multisend',
    ) as $key) {
      if ($function = _messaging_callback_get($info, $key)) {
        $this
          ->assertTrue(function_exists($function), "Function callback of type {$key} exists for method {$method}");
      }
    }
  }

  // Enable debug mode so messages are not actually sent and create user for testing
  variable_set('messaging_debug', 1);
  foreach (messaging_method_info(NULL, NULL, NULL, TRUE) as $method => $info) {
    $count = 0;
    $name = $info['name'];

    // This should create 3 messages for each method
    $message = $this
      ->randomMessage();
    if (messaging_user_destination($user, $method, $message)) {
      $this
        ->assertEqual(messaging_message_send_user($user, $message, $method, TRUE), TRUE, 'Message sent for user using: ' . $name);
      $count++;
    }

    // Try these fake destinations, it should work as they're finally send through debug
    $message->account = $user;
    $this
      ->assertEqual(messaging_message_send(array(
      'foo1',
      'foo2',
    ), $message, $method, TRUE), TRUE, 'Bulk messages sent using: ' . $name);
    $count++;
    $queued = messaging_store('get', array(
      'uid' => $user->uid,
      'method' => $method,
    ));
    $this
      ->assertEqual(count($queued), $count, 'The right number of messages have been queued for method: ' . $method . ' (' . count($queued) . ')');
  }
}