You are here

function PathRedirectFunctionalTest::testInactivePurging in Path redirect 6

File

./path_redirect.test, line 223
Tests for the path_redirect module.

Class

PathRedirectFunctionalTest

Code

function testInactivePurging() {

  // Add two inactive redirects to the database.
  $time = time();
  $r1 = $this
    ->addRedirect('test1', 'node', array(
    'last_used' => $time - 620000,
  ));
  $r2 = $this
    ->addRedirect('test2', 'node', array(
    'last_used' => $time - 620000,
  ));

  // Purging is disabled by default, so after running cron both redirects should not be removed.
  $this
    ->cronRun();
  $this
    ->assertTrue(path_redirect_load($r1['rid']), t('Inactive redirect not removed.'));
  $this
    ->assertTrue(path_redirect_load($r2['rid']), t('Inactive redirect not removed.'));

  // Enable purging of inactive redirects.
  $edit = array(
    'path_redirect_purge_inactive' => 604800,
  );
  $this
    ->drupalPost('admin/build/path-redirect/settings', $edit, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));

  // Run one of the redirects and test that the last used timestamp was updated.
  $this
    ->drupalGet('test1');
  $this
    ->assertTrue(db_result(db_query("SELECT last_used FROM {path_redirect} WHERE source = 'test1'")) >= $time, t('Last used timestamp was updated.'));

  // Run cron and test that the inactive redirect was removed.
  $this
    ->cronRun();
  $this
    ->assertTrue(path_redirect_load($r1['rid']), t('Active redirect not removed.'));
  $this
    ->assertFalse(path_redirect_load($r2['rid']), t('Inactive redirect removed.'));
}