File
- modules/poll/poll.test, line 716
- Tests for poll.module.
Code
function testAutoExpire() {
$title = $this->randomName();
$choices = $this->_generateChoices(2);
$poll_nid = $this->pollCreate($title, $choices, FALSE);
$this->assertTrue($poll_nid, t('Poll for auto-expire test created.'));
$this->drupalGet("node/$poll_nid/edit");
$this->assertField('runtime', t('Poll expiration setting found.'));
$elements = $this->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
$this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == 0, t('Poll expiration set to unlimited.'));
$edit = array();
$poll_expiration = 604800; $edit['runtime'] = $poll_expiration;
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('Poll %title has been updated.', array('%title' => $title)), t('Poll expiration settings saved.'));
$this->drupalGet("node/$poll_nid/edit");
$elements = $this->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
$this->assertTrue(isset($elements[0]['value']) && $elements[0]['value'] == $poll_expiration, t('Poll expiration set to unlimited.'));
drupal_cron_run();
$this->drupalGet("node/$poll_nid/edit");
$elements = $this->xpath('//input[@id="edit-active-1"]');
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll is still active.'));
$created = db_query('SELECT created FROM {node} WHERE nid = :nid', array(':nid' => $poll_nid))->fetchField();
db_update('node')
->fields(array('created' => $created - ($poll_expiration * 1.01)))
->condition('nid', $poll_nid)
->execute();
drupal_cron_run();
$this->drupalGet("node/$poll_nid/edit");
$elements = $this->xpath('//input[@id="edit-active-0"]');
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Poll has expired.'));
}
Login or
register to post comments