public function SchedulerFunctionalTest::testScheduledNodeDelete in Scheduler 7
Tests the deletion of a scheduled node.
File
- tests/
scheduler.test, line 766 - Scheduler module test case file.
Class
- SchedulerFunctionalTest
- Tests the scheduler interface.
Code
public function testScheduledNodeDelete() {
// Log in.
$this
->drupalLogin($this->adminUser);
// 1. Test if it is possible to delete a node that does not have a
// publication date set, when scheduled publishing is required, and likewise
// for unpublishing.
// @see https://drupal.org/node/1614880
//
// Create a published and an unpublished node, both without scheduling.
$published_node = $this
->drupalCreateNode(array(
'type' => 'page',
'status' => 1,
));
$unpublished_node = $this
->drupalCreateNode(array(
'type' => 'page',
'status' => 0,
));
// Make scheduled publishing and unpublishing required.
variable_set('scheduler_publish_required_page', TRUE);
variable_set('scheduler_unpublish_required_page', TRUE);
// Check that deleting the nodes does not throw form validation errors.
// The text 'error message' is used in a header h2 html tag which is
// normally made hidden from browsers but will be in the page source.
// It is also good when testing for the absense of something to also test
// for the presence of text, hence the second assertion for each check.
$this
->drupalPost('node/' . $published_node->nid . '/edit', array(), t('Delete'));
$this
->assertNoText('Error message', 'No error messages are shown when trying to delete a published node with no scheduling information.');
$this
->assertText('Are you sure you want to delete', 'The deletion warning message is shown immediately when trying to delete a published node with no scheduling information.');
$this
->drupalPost('node/' . $unpublished_node->nid . '/edit', array(), t('Delete'));
$this
->assertNoText('Error message', 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
$this
->assertText('Are you sure you want to delete', 'The deletion warning message is shown immediately when trying to delete an unpublished node with no scheduling information.');
// 2. Test that nodes can be deleted with no validation errors if the dates
// are in the past.
// @see http://drupal.org/node/2627370
//
// Create nodes with publish_on and unpublish_on dates in the past.
$values = array(
'type' => 'page',
'status' => TRUE,
'unpublish_on' => strtotime('- 2 day', REQUEST_TIME),
);
$published_node_past = $this
->drupalCreateNode($values);
$values = array(
'type' => 'page',
'status' => FALSE,
'publish_on' => strtotime('- 2 day', REQUEST_TIME),
);
$unpublished_node_past = $this
->drupalCreateNode($values);
// Attempt to delete the published node and check for no validation error.
$this
->drupalPost('node/' . $published_node_past->nid . '/edit', array(), t('Delete'));
$this
->assertNoText('Error message', 'No error messages are shown when trying to delete a node with an unpublish date in the past.');
$this
->assertText('Are you sure you want to delete', 'The deletion warning message is shown immediately when trying to delete a node with an unpublish date in the past.');
// Attempt to delete the unpublished node and check for no validation error.
$this
->drupalPost('node/' . $unpublished_node_past->nid . '/edit', array(), t('Delete'));
$this
->assertNoText('Error message', 'No error messages are shown when trying to delete a node with a publish date in the past.');
$this
->assertText('Are you sure you want to delete', 'The deletion warning message is shown immediately when trying to delete a node with a publish date in the past.');
}