Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions message.module
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,11 @@ function _message_delete_messages($field_names, $entity_id, $last_mid = 0, $rang
*
* @return array
* Messages of the given type(s) that should be purged according to the given
* settings.
* settings or an empty array if purge limit has been reached.
*/
function message_get_purgeable_by_type(&$purge_limit, $message_type_name, $purge_settings) {
if ($purge_limit <= 0) {
return;
return array();
}

// Messages to be deleted.
Expand Down
39 changes: 39 additions & 0 deletions tests/message.test
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,45 @@ class MessageCron extends DrupalWebTestCase {
$this->assertEqual(count($messages), 8, t('Eight messages of type 2 left.'));
}

/**
* Test purging one message type when there're messages more than the cron

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First line of the php doc block need to in a single line.

* allows.
*/
function testPurgeRequestTypeLimit() {
// Set maximal amount of messages to delete.
variable_set('message_delete_cron_limit', 10);

$web_user = $this->drupalCreateUser();

// Create a purgeable message type with max quota 2 and max days 0.
$values = array(
'data' => array(
'purge' => array(
'override' => TRUE,
'enabled' => TRUE,
'quota' => 2,
'days' => 0,
),
),
);
$message_type = message_type_create('big_type', $values);
$message_type->save();

// Create more messages than may be deleted in one request.
for ($i = 0; $i < 20; $i++) {
$message = message_create('big_type', array(), $web_user);
$message->save();
}

// Trigger message's hook_cron().
message_cron();

// There are 20 messages to be deleted and 10 deletions allowed, so 10
// messages of big_type should be deleted.
$messages = message_load_multiple(FALSE, array('type' => 'big_type'));
$this->assertEqual(count($messages), 10, t('@count messages of big type left.', array('@count' => count($messages))));
}

/**
* Test global purge settings and overriding them.
*/
Expand Down