You are here

function Messaging_API_Tests::testMessagingBasicAPI in Messaging 6.3

Same name and namespace in other branches
  1. 5 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()
  2. 6.4 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()
  3. 6 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()
  4. 6.2 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()
  5. 7 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()

Exercise basic API functions

File

tests/messaging_api.test, line 29

Class

Messaging_API_Tests

Code

function testMessagingBasicAPI() {

  // Try simple callback functions
  $testall = _messaging_callback('messaging_test_foo_getargs_callback');
  $test123 = _messaging_callback('messaging_test_foo_getargs_callback', 1, 2, 3);
  $this
    ->assertEqual(_messaging_callback_invoke($testall, 0, 1, 2), array(
    0,
    1,
    2,
  ), 'Simple callback returns right parameters');
  $this
    ->assertEqual(_messaging_callback_invoke($test123, 4, 5, 6), array(
    1,
    2,
    3,
    4,
    5,
    6,
  ), 'Parameters callback returns right parameters');

  // Test chained message callbacks
  $msgcall = _messaging_callback('messaging_test_foo_message_callback');
  $callbacks = array();
  _messaging_callback_add($callbacks, 'test1', $msgcall);
  _messaging_callback_add($callbacks, 'test2', $msgcall);
  $message = $this
    ->randomMessage();
  $result = messaging_message_callbacks(array(
    'test1',
    'test2',
  ), $message, $callbacks);
  $this
    ->assertEqual($message, $result, 'Message callback returns right parameters');

  // Try messaging store functions, build foo method info for rendering
  $message = $this
    ->randomMessage();
  $method = array(
    'type' => MESSAGING_TYPE_PULL,
  );
  $message->method = 'simple';

  // Set sender and destination user
  $user = $this
    ->drupalCreateUser();
  $sender = $this
    ->drupalCreateUser();
  $message
    ->set_user($user);
  $message
    ->set_sender($sender);

  // Process message through simple sending so it will be stored in the table
  $message
    ->queue();
  $this
    ->assertTrue($message->mqid, 'The message has been stored successfully');
  $load = messaging_message_load($message->mqid);
  $this
    ->assertTrue($message->mqid == $load->mqid && $message->subject == $load->subject, 'The message has been retrieved successfully');

  // Delete the message, delete cache and try to reload
  $load
    ->delete();
  messaging_static('messaging_message_load', NULL, TRUE);
  $this
    ->assertFalse(messaging_message_load($message->mqid), 'The message has been deleted');
}