function NotificationsLiteTests::testNotificationsLite in Notifications 6.3
Same name and namespace in other branches
- 6.4 tests/notifications_lite.test \NotificationsLiteTests::testNotificationsLite()
- 6.2 tests/notifications_lite.test \NotificationsLiteTests::testNotificationsLite()
- 7 tests/notifications_lite.test \NotificationsLiteTests::testNotificationsLite()
Test simple sending cases
File
- tests/
notifications_lite.test, line 33
Class
Code
function testNotificationsLite() {
$user = $this
->drupalCreateUser();
// Test immediate sending
foreach (array(
1,
2,
) as $index) {
notifications_lite_send($user->uid, "Subject {$index}", "Body {$index}");
}
// There should be two queued rows and two queued events
$this
->assertUserRows('notifications_queue', 2, $user->uid, 'Two queued notifications');
$this
->assertTableRows('notifications_event', 2, NULL, 'Two queued events');
//$this->dumpTable('notifications_queue');
// Send, and check again
$sqid = notifications_process_prepare();
$count = notifications_process_queue(0, $sqid);
$this
->assertEqual($count, 2, "Processed two rows in queue ({$count})");
$this
->assertTableRows('notifications_event', 2, array(
'type' => 'lite',
'counter' => 0,
));
//$this->dumpTable('notifications_event');
$this
->assertUserRows('notifications_queue', 0, $user->uid, 'No queued notifications');
// Retrieve messages and check formatting
$messages = messaging_store('get', array(
'method' => 'debug',
'uid' => $user->uid,
));
$this
->assertEqual(count($messages), 2, 'Retrieved two messages from store');
foreach (array(
1,
2,
) as $index) {
$message = array_shift($messages);
$this
->assertEqual("Subject {$index}", $message->subject, "Right subject for message {$index}: {$message->subject}");
}
// Now test short digesting for notifications lite messages. Set digests and refresh cache.
db_query("DELETE FROM {messaging_store}");
variable_set('notifications_build_methods', array(
0 => 'short',
));
messaging_static('notifications_build_method_intervals', NULL, TRUE);
// Again, send two messages but this time check they're digested into one.
$sent = $this
->sendLiteMessages($user->uid, 4);
/*
foreach (array(3, 4) as $index) {
notifications_lite_send($user->uid, "Subject $index", "Body $index");
}*/
//$count = notifications_process_rows(array('uid' => $user->uid));
// $this->assertEqual($count, count($sent), "Processed all rows in queue ($count)");
$messages = messaging_store('get', array(
'method' => 'debug',
'uid' => $user->uid,
));
$this
->assertEqual($count = count($messages), 1, "Retrieved just one message from store ({$count})");
$message = array_shift($messages);
// Check that all messages are in the message body
foreach ($sent as $index => $msg) {
$this
->assertTrue(strpos($message->body, $msg->subject), "The message {$index} is contained in the digest");
}
// Same for long digesting, both subject and body should be there
db_query("DELETE FROM {messaging_store}");
variable_set('notifications_build_methods', array(
0 => 'long',
));
messaging_static('notifications_build_method_intervals', NULL, TRUE);
// We try three messages this time
$sent = $this
->sendLiteMessages($user->uid, 2);
$messages = messaging_store('get', array(
'method' => 'debug',
'uid' => $user->uid,
));
$this
->assertEqual($count = count($messages), 1, "Retrieved just one message from store ({$count})");
// Check that all messages are in the message body
$message = array_shift($messages);
foreach ($sent as $index => $msg) {
$this
->assertTrue(strpos($message->body, $msg->subject), "The message {$index} subject is contained in the digest");
$this
->assertTrue(strpos($message->body, $msg->body), "The message {$index} body is contained in the digest");
}
// Dump for test debugging
//$this->printDebug($message, 'Message');
//$this->dumpTable('messaging_store');
//$this->dumpLogs();
}