public function ClassifiedTestTestBasicTest::test0123396And0143680 in Classified Ads 7.3
Bug 123396: Unchecking Publish doesn't prevent nodes from being published.
Also catches bug 143680: Expiration date by term is not correctly applied.
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_test_basic.test, line 49
Class
- ClassifiedTestTestBasicTest
- Basic test for known bugs in previous versions.
Code
public function test0123396And0143680() {
$this->group = __FUNCTION__;
// Include seconds in date comparison displays.
$format = 'Y-m-d H:i:s';
// 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.
$this->group = t('new, default');
$node = $this
->createNode(array(
$category_field_name => array(
LANGUAGE_NONE => array(
0 => array(
'tid' => $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(
$category_field_name => array(
LANGUAGE_NONE => array(
0 => array(
'tid' => $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 = REQUEST_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(
$category_field_name => array(
LANGUAGE_NONE => array(
0 => array(
'tid' => $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.
$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);
}