public function ClassifiedTestNotificationsTest::test1441396 in Classified Ads 7.3
Issue #1441396.
Half-life notification emails continue every notification run.
Full test of all notifications.
File
- tests/
classified_test_notifications.test, line 73
Class
- ClassifiedTestNotificationsTest
- Test cases for the Classified Ads notifications submodule.
Code
public function test1441396() {
$this->group = 'setup';
$this
->createUsers(array(
'creator',
));
// 1. Build an ad node expiring in 14 days, grace 7 days (default)
$settings = array(
'uid' => $this->creatorUser->uid,
);
$node = $this
->createNode($settings);
$lifetime = _classified_get('lifetimes');
$lifetime = reset($lifetime);
$grace = _classified_get('grace');
$this
->pass(t('Lifetime %lifetime, grace %grace', array(
'%lifetime' => $lifetime,
'%grace' => $grace,
)), $this->group);
$t0 = time() + 1;
// 2. Cron at t0: nothing should happen.
classified_cron($t0);
$this
->assertFalse($this
->queueGetSize(), t('No initial mail queued.'), $this->group);
$this
->queueFlush();
// 3. Half-life mails.
$this->group = 'half-life';
// 3.1 Cron at t0 + 6 days: nothing should happen.
classified_cron($t0 + ($lifetime / 2 - 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('No mail before half-life.'), $this->group);
$this
->queueFlush();
// 3.2 Cron at t0 + 7 days: HL notification should be sent.
classified_cron($t0 + $lifetime / 2 * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Half-life mail queued.'), $this->group);
$this
->queueFlush();
$node2 = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node2->status, 1, t('Ad still published at half-life.'), $this->group);
// 3.3 Cron in the post-half-life period: nothing should happen.
classified_cron($t0 + $lifetime / 2 * 86400 + 5);
$this
->assertFalse($this
->queueGetSize(), t('Half-life mail not requeued 5 minutes later.'), $this->group);
$this
->queueFlush();
classified_cron($t0 + ($lifetime / 2 + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Half-life mail not requeued 1 day later.'), $this->group);
$this
->queueFlush();
classified_cron($t0 + ($lifetime / 2 + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Half-life mail not requeued 1 day and 5 minutes later.'), $this->group);
$this
->queueFlush();
// 4. Expiration mails.
$this->group = 'expiration';
// 4.1. Cron at t0 + 13 days: 1 day to expire notification should be sent.
classified_cron($t0 + ($lifetime - 1) * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Pre-expiration mail queued.'), $this->group);
$this
->queueFlush();
// 4.2. Cron at t0 + 13.5 days: nothing should happen.
classified_cron($t0 + ($lifetime - 1 + 0.6) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Pre-expiration mail not requeued.'), $this->group);
$this
->queueFlush();
// 4.3. Cron at t0 + 14 days: expiration notification should be sent, ad
// should be unpublished.
classified_cron($t0 + $lifetime * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Expiration mail queued.'), $this->group);
$this
->queueFlush();
$node2 = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node2->status, 0, t('Ad no longer published after expiration.'), $this->group);
// 4.4. Cron at t0 + 15 days: nothing should happen.
classified_cron($t0 + ($lifetime + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Expiration mail not requeued.'), $this->group);
$this
->queueFlush();
// 5. Purge mails.
$this->group = 'purge';
// 5.1 Cron at t0 + 20 days: 1 days to purge notification should be sent.
classified_cron($t0 + ($lifetime + $grace - 1) * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Pre-purge mail queued.'), $this->group);
$this
->queueFlush();
// 5.2 Cron at t0 + 20.5 days: nothing should happen.
classified_cron($t0 + ($lifetime + $grace - 1 + 0.6) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Pre-purge mail not requeued.'), $this->group);
$this
->queueFlush();
// 5.3 Cron at t0 + 21 days: purge notification should be sent, ad should be
// deleted.
classified_cron($t0 + ($lifetime + $grace) * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Purge mail queued.'), $this->group);
$this
->queueFlush();
$node2 = node_load($node->nid, NULL, TRUE);
$this
->assertFalse($node2, t('Ad deleted after purge.'), $this->group);
// 5.4 Cron at t0 + 22 days: ad is deleted, nothing should happen.
classified_cron($t0 + ($lifetime + $grace + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Purge mail not requeued.'), $this->group);
$this
->queueFlush();
}