You are here

function Messaging_API_Tests::testMessagingBasicAPI in Messaging 6

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.2 tests/messaging_api.test \Messaging_API_Tests::testMessagingBasicAPI()
  4. 6.3 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->uid = $message->sender = 0;
  $message->method = 'test';
  $message->queue = 1;
  $message = messaging_message_prepare($message, $method);
  $message = messaging_message_render($message, $method);
  $message = messaging_store('save', $message);
  $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');
  $list = messaging_pull_pending('test', 0);
  $this
    ->assertTrue(count($list) == 1 && !empty($list[$message->mqid]), 'The message has been retrieved from queue');
}