public function SchedulerFunctionalTest::testValidationDuringEdit in Scheduler 7
Tests the validation when editing a node.
The 'required' checks and 'dates in the past' checks are handled in other tests. This test checks validation when the two fields interact.
File
- tests/
scheduler.test, line 727 - Scheduler module test case file.
Class
- SchedulerFunctionalTest
- Tests the scheduler interface.
Code
public function testValidationDuringEdit() {
$this
->drupalLogin($this->adminUser);
// Set unpublishing to be required.
variable_set('scheduler_unpublish_required_page', TRUE);
// Create an unpublished page node, then edit the node and check that if a
// publish-on date is entered then an unpublish-on date is also needed.
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'status' => FALSE,
));
$edit = array(
'publish_on' => date('Y-m-d H:i:s', strtotime('+1 day', REQUEST_TIME)),
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->assertText("If you set a 'publish-on' date then you must also set an 'unpublish-on' date.", 'Validation prevents entering a publish-on date with no unpublish-on date if unpublishing is required.');
// Create an unpublished page node, then edit the node and check that if the
// status is changed to published, then an unpublish-on date is also needed.
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'status' => FALSE,
));
$edit = array(
'status' => TRUE,
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->assertText("To publish this node you must also set an 'unpublish-on' date.", 'Validation prevents publishing the node directly without an unpublish-on date if unpublishing is required.');
// Create an unpublished page node, edit the node and check that if both
// dates are entered then the unpublish date is later than the publish date.
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'status' => FALSE,
));
$edit = array(
'publish_on' => date('Y-m-d H:i:s', strtotime('+2 day', REQUEST_TIME)),
'unpublish_on' => date('Y-m-d H:i:s', strtotime('+1 day', REQUEST_TIME)),
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->assertText("The 'unpublish on' date must be later than the 'publish on' date.", 'Validation prevents entering an unpublish-on date which is earlier than the publish-on date.');
}