public function PublicationDateTestCase::testActionSavingOnForms in Publication Date 7.2
Same name and namespace in other branches
- 7 tests/publication_date.test \PublicationDateTestCase::testActionSavingOnForms()
Test automatic saving of variables via forms.
File
- tests/
publication_date.test, line 101 - Publication Date module tests.
Class
- PublicationDateTestCase
- Test publication date functionality.
Code
public function testActionSavingOnForms() {
$langcode = LANGUAGE_NONE;
$edit = array();
$edit["title"] = 'publication test node ' . $this
->randomName(10);
$edit["body[{$langcode}][0][value]"] = 'publication node test body ' . $this
->randomName(32) . ' ' . $this
->randomName(32);
$edit['status'] = 1;
// Hard to test created time == REQUEST_TIME because simpletest launches a
// new HTTP session, so just check it's set.
$this
->drupalPost('node/add/page', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title']);
$this
->drupalGet('node/' . $node->nid . '/edit');
$value = $this
->_getPubdateFieldValue();
// Make sure it was created with Published At set.
$this
->assertNotNull($value, t('Publication date set initially'));
// Unpublish the node and check that the field value is maintained.
$edit['status'] = 0;
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertFieldByName('pubdate', $value, t('Pubdate is maintained when unpublished'));
// Republish the node and check that the field value is maintained.
$edit['status'] = 1;
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertFieldByName('pubdate', $value, t('Pubdate is maintained when republished'));
// Set a custom time and make sure that it is stored correctly.
$ctime = REQUEST_TIME - 180;
$edit['pubdate'] = format_date($ctime, 'custom', 'Y-m-d H:i:s O');
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$custom_value = $this
->_getPubdateFieldValue();
$this
->assertTrue($custom_value == format_date($ctime, 'custom', 'Y-m-d H:i:s O'), t('Custom time/date was set'));
// Set the field to empty and and make sure the published date is reset.
$edit['pubdate'] = '';
sleep(2);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$new_value = $this
->_getPubdateFieldValue();
$this
->assertNotNull($new_value, t('Published time was set automatically when there was no value entered'));
$this
->assertNotNull($new_value != $custom_value, t('The new published-at time is different from the custom time'));
$this
->assertTrue($new_value > $value, t('The new published-at time is greater than the original one'));
// Unpublish the node.
$edit['status'] = 0;
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Set the field to empty and and make sure that it stays empty.
$edit['pubdate'] = '';
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertFieldByName('pubdate', '', t('Publication date field is empty'));
}