You are here

function ClassifiedBasicTest::test0123396 in Classified Ads 6.3

Bug 123396: Unchecking 'Publish' checkbox doesn't prevent nodes from being published.

Goes much further by testing the expiration dates resulting from all creation and updating scenarios. Already done:

  • creation, default
  • creation, default with explicit lifetime
  • creation, forced

File

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

Class

ClassifiedBasicTest

Code

function test0123396() {
  $this->group = __FUNCTION__;

  // Include seconds in date comparison displays.
  $format = 'Y-m-d H:i:s';

  // 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.
  $this->group = t('new, default');
  $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. Make sure it uses the default taxonomy-derived lifetime.
  $lifetimes = _classified_get('lifetimes');
  $lifetime = isset($lifetimes[$tid]) ? $lifetimes[$tid] : reset($lifetimes);
  $expected_expires = $node->created + $lifetime * 60 * 60 * 24;
  $this
    ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
    '%actual' => format_date($node->expires, 'custom', $format),
    '%expected' => format_date($expected_expires, 'custom', $format),
  )), $this->group);

  // 3a. Assign a specific lifetime to term.
  $this->group = t('new, reset');
  $lifetimes[$tid] = $random = mt_rand(0, 90);
  variable_set('classified-lifetimes', $lifetimes);
  $lifetimes = _classified_get('lifetimes');
  $lifetime = isset($lifetimes[$tid]) ? $lifetimes[$tid] : reset($lifetimes);
  $this
    ->assertEqual($random, $lifetime, t('Lifetime correctly set to @random = @lifetime', array(
    '@random' => $random,
    '@lifetime' => $lifetime,
  )), $this->group);

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

  // 3c. Make sure it uses the explicit taxonomy-derived lifetime.
  $expected_expires = $node->created + $lifetime * 60 * 60 * 24;
  $this
    ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
    '%actual' => format_date($node->expires, 'custom', $format),
    '%expected' => format_date($expected_expires, 'custom', $format),
  )), $this->group);

  // 4a. Create a node bearing that term, but use force mode.
  $this->group = t('new, force');
  $expected_expires = time() + mt_rand(0, 90 * 24 * 60 * 60);
  $this
    ->pass(t('Limit set to @date', array(
    '@date' => format_date($expected_expires, 'custom', $format),
  )), $this->group);
  $node = $this
    ->createNode(array(
    'taxonomy' => array(
      $vid => $tid,
    ),
    'expire_mode' => 'force',
    'expire_date_ts' => $expected_expires,
  ));
  $this
    ->assertTrue(isset($node->expires) && is_numeric($node->expires), t('node has an expires timestamp'), $this->group);

  // 4b. Make sure it uses the explicit taxonomy-derived lifetime.
  $limit = $node->created + $lifetime * 60 * 60 * 24;
  $this
    ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
    '%actual' => format_date($node->expires, 'custom', $format),
    '%expected' => format_date($expected_expires, 'custom', $format),
  )), $this->group);
}