You are here

public function ClassifiedTestTestBasicTest::test1733594 in Classified Ads 7.3

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

File

tests/classified_test_basic.test, line 611

Class

ClassifiedTestTestBasicTest
Basic test for known bugs in previous versions.

Code

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

  // 1. Get the Classified vocabulary id and field name.
  $vid = _classified_get('vid');
  $category_field_name = _classified_get('field-category');

  // 2a. Create a term in it, do not assign a specific lifetime.
  $term = (object) array(
    'name' => $this
      ->randomName(8),
    'description' => $this
      ->randomString(20),
    'vid' => $vid,
  );
  $status = taxonomy_term_save($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(
    $category_field_name => array(
      LANGUAGE_NONE => array(
        0 => array(
          'tid' => $tid,
        ),
      ),
    ),
  ));

  // 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.
  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);
}