You are here

function MessageCron::testPurgeGlobalSettings in Message 7

Test global purge settings and overriding them.

File

tests/message.test, line 591

Class

MessageCron
Test the Message cron functionallity.

Code

function testPurgeGlobalSettings() {

  // Set global purge settings.
  variable_set('message_purge_enable', TRUE);
  variable_set('message_purge_quota', 1);
  variable_set('message_purge_days', 2);
  $web_user = $this
    ->drupalCreateUser();
  $message_type = message_type_create('type1');
  $message_type
    ->save();

  // Create an overriding type.
  $values = array(
    'data' => array(
      'purge' => array(
        'override' => TRUE,
        'enabled' => FALSE,
        'quota' => 1,
        'days' => 1,
      ),
    ),
  );
  $message_type = message_type_create('type2', $values);
  $message_type
    ->save();
  $values = array(
    // Set messages creation time to three days ago.
    'timestamp' => time() - 3 * 86400,
  );
  for ($i = 0; $i < 2; $i++) {
    $message = message_create('type1', $values, $web_user);
    $message
      ->save();
    $message = message_create('type2', $values, $web_user);
    $message
      ->save();
  }

  // Trigger message's hook_cron().
  message_cron();
  $messages = message_load_multiple(FALSE, array(
    'type' => 'type1',
  ));
  $this
    ->assertEqual(count($messages), 0, t('All type1 messages deleted.'));
  $messages = message_load_multiple(FALSE, array(
    'type' => 'type2',
  ));
  $this
    ->assertEqual(count($messages), 2, t('Type2 messages were not deleted due to settings override.'));
}