View source
<?php
require_once 'messaging_test_case.inc';
class Messaging_Methods_Tests extends MessagingTestCase {
function getInfo() {
return array(
'name' => 'Sending methods',
'group' => 'Messaging',
'description' => 'API compatibility for sending method plug-ins',
);
}
function setUp() {
parent::setUp('messaging_simple', 'messaging_mail', 'messaging_mime_mail', 'messaging_phpmailer', 'messaging_privatemsg', 'messaging_sms');
}
function testMessagingMethods() {
$user = $this
->drupalCreateUser();
$user->sms_user[0] = array(
'status' => 2,
'number' => 1234,
);
foreach (messaging_method_info() as $method => $info) {
$send_method = messaging_send_method($method, $info);
$this
->assertTrue(!empty($send_method->name) && isset($send_method->type), 'Send method properties seem to be ok for method: ' . $method);
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}");
}
}
$message = $this
->randomMessage();
$message->method = $method;
$message
->prepare();
$message
->render();
$this
->assertTrue($message->rendered && $message->prepared, 'A message has been prepared and rendered for method: ' . $method);
}
foreach (messaging_method_info(NULL, NULL, NULL, TRUE) as $method => $info) {
$count = 0;
$name = $info['name'];
$message = $this
->randomMessage($method);
$message->log = 1;
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++;
}
$message = $this
->randomMessage($method);
$message->log = 1;
$message->account = $user;
$result = messaging_message_send(array(
'foo1',
'foo2',
), $message, $method, TRUE);
$this
->assertEqual($result, TRUE, 'Bulk messages sent using: ' . $name);
$count++;
$queued = messaging_store()
->get_messages(array(
'uid' => $user->uid,
'method' => $method,
));
$this
->assertEqual(count($queued), $count, 'The right number of messages have been queued for method: ' . $method . ' (Expected=' . $count . ' Real= ' . count($queued) . ')');
}
$user2 = $this
->drupalCreateUser();
$user2->sms_user[0] = array(
'status' => 2,
'number' => 3456,
);
$users = array(
$user,
$user2,
);
foreach (messaging_method_info() as $method => $info) {
$send_method = messaging_send_method($method);
foreach ($users as $account) {
$dest = messaging_account_build_destination($account, $method);
$destinations[$dest->type][$dest->mdid] = $dest;
}
}
foreach (messaging_address_info() as $type => $info) {
$this
->assertTableRows('messaging_destination', 2, array(
'type' => $send_method->address_type,
));
$this
->assertEqual(count($destinations[$type]), 2, "We have two destinations of type {$type}");
}
foreach (array(
'mail' => 'simple',
'simple' => 'mail',
) as $method => $replace) {
$type = messaging_send_method($replace)->address_type;
foreach ($destinations[$type] as $dest) {
$dest
->delete();
}
$this
->assertTableRows('messaging_destination', 0, array(
'type' => $type,
), "We have successfully deleted destinations of type {$type}");
Messaging_Method::method_disable($method, $replace);
$old_type = messaging_method_info($method, 'address_type');
$new_type = messaging_method_info($replace, 'address_type');
$this
->assertTableRows('messaging_destination', 2, array(
'type' => $type,
), "We got back destinations of type {$type} after method replace: from {$method}({$old_type}) to {$replace}({$new_type})");
}
}
}