You are here

public function ClassifiedBasicTest::test1733594 in Classified Ads 6.3

Bug 1733594: Infinite grace (-1) being handled like a normal duration.

File

tests/classified_basic.test, line 714
Basic test for known bugs in previous versions.

Class

ClassifiedBasicTest

Code

public function test1733594() {
  $this->group = 'Infinite';

  // 1. Get the Classified vocabulary id.
  $vid = _classified_get('vid');

  // 2a. Create a term in it, do not assign a specific lifetime.
  $term = array(
    'name' => $this
      ->randomName(8),
    'description' => $this
      ->randomString(20),
    'vid' => $vid,
  );
  $status = taxonomy_save_term($term);
  $tid = $term['tid'];
  $this
    ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
    '@tid' => $tid,
  )), 'setup');

  // 2b. Create a node bearing that term.
  $node = $this
    ->createNode(array(
    'taxonomy' => array(
      $vid => $tid,
    ),
  ));
  $this
    ->assertTrue(isset($node->expires) && is_numeric($node->expires), t('node has an expires timestamp'), $this->group);

  // 2c. Get lifetimes information.
  $lifetimes = _classified_get('lifetimes');
  $default_lifetime = reset($lifetimes);

  // 2d. Validate lifetime.
  $this
    ->assertTrue(isset($node->expires) && is_numeric($node->expires) && $node->expires - $node->created == $default_lifetime * 24 * 60 * 60, t('node has correct timestamp'), $this->group);

  // 3. Try purge one year beyond expiration with infinite grace.
  module_load_include('scheduled.inc', 'classified');
  variable_set('classified-grace', -1);
  $future = $node->expires + 365 * 24 * 60 * 60;
  $ads = _classified_scheduled_build_purge($future);

  // 4. Ensure purge did not happen.
  $this
    ->assertTrue(empty($ads), "No ad has been reported as deleted upon purge.", $this->group);
  $node2 = node_load($node->nid, NULL, TRUE);
  $this
    ->assertTrue(isset($node2->nid) && $node2->nid == $node->nid, 'Node is still present in database after purge.', $this->group);

  // 5. Try purge one week beyond expiration with normal one day grace.
  $this->group = "Finite";
  variable_set('classified-grace', 1);
  $future = $node->expires + 7 * 24 * 60 * 60;
  $ads = _classified_scheduled_build_purge($future);

  // 6. Ensure purge was performed. Format: {uid: {nid: title, ...}, ...}.
  $this
    ->assertTrue(count($ads) == 1, "Purges happened for one account.", $this->group);
  $purges = reset($ads);
  $this
    ->assertTrue(count($purges) == 1, "One node was purged", $this->group);
  $this
    ->assertEqual(key($purges), $node->nid, "Nid of purged node is correct", $this->group);
  $this
    ->assertEqual(current($purges), $node->title, "Title of purged node is correct", $this->group);
  $node2 = node_load($node->nid, NULL, TRUE);
  $this
    ->assertFalse($node2, "Node is no longer in database", $this->group);
}