View source
<?php
require_once __DIR__ . '/classified_basic.test';
class ClassifiedNotificationsTest extends ClassifiedAbstractTest {
public static function getInfo() {
return array(
'name' => t('Notifications'),
'description' => t('Notifications tests for Classified.'),
'group' => t('Classified'),
);
}
public function queueFlush() {
db_query('TRUNCATE {job_queue}');
}
public function queueGetSize() {
$ret = db_result(db_query('SELECT count(*) FROM {job_queue}'));
return $ret;
}
public function setUp() {
$this->group = __FUNCTION__;
parent::setUp('job_queue', 'classified', 'classified_notifications');
}
public function test1441396() {
$this->group = 'setup';
$this
->createUsers(array(
'creator',
));
$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;
classified_cron($t0);
$this
->assertFalse($this
->queueGetSize(), t('No initial mail queued.'), $this->group);
$this
->queueFlush();
$this->group = 'half-life';
classified_cron($t0 + ($lifetime / 2 - 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('No mail before half-life.'), $this->group);
$this
->queueFlush();
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);
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();
$this->group = 'expiration';
classified_cron($t0 + ($lifetime - 1) * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Pre-expiration mail queued.'), $this->group);
$this
->queueFlush();
classified_cron($t0 + ($lifetime - 1 + 0.6) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Pre-expiration mail not requeued.'), $this->group);
$this
->queueFlush();
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);
classified_cron($t0 + ($lifetime + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Expiration mail not requeued.'), $this->group);
$this
->queueFlush();
$this->group = 'purge';
classified_cron($t0 + ($lifetime + $grace - 1) * 86400);
$this
->assertTrue($this
->queueGetSize(), t('Pre-purge mail queued.'), $this->group);
$this
->queueFlush();
classified_cron($t0 + ($lifetime + $grace - 1 + 0.6) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Pre-purge mail not requeued.'), $this->group);
$this
->queueFlush();
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);
classified_cron($t0 + ($lifetime + $grace + 1) * 86400);
$this
->assertFalse($this
->queueGetSize(), t('Purge mail not requeued.'), $this->group);
$this
->queueFlush();
}
public function test1491880() {
$this
->createUsers(array(
'creator',
));
$key = $this
->randomName(8);
$message = array();
$params = array(
'account' => $this->creatorUser,
);
foreach (_classified_get_notify_kinds() as $kind) {
classified_notifications_mail($kind, $message, $params);
}
}
}