diff --git a/message.module b/message.module index 2edfef2..59b2aa0 100644 --- a/message.module +++ b/message.module @@ -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. diff --git a/tests/message.test b/tests/message.test index f590b94..e5d1679 100644 --- a/tests/message.test +++ b/tests/message.test @@ -585,6 +585,47 @@ class MessageCron extends DrupalWebTestCase { $this->assertEqual(count($messages), 8, t('Eight messages of type 2 left.')); } + /** + * Test purging messgaes. + * + * Test purging one message type when there're messages more than the cron + * 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. */