public function SchedulerWorkbenchTestCase::testPublishing in Scheduler Workbench Integration 7
Test publishing and unpublishing of content.
File
- ./
scheduler_workbench.test, line 76 - Automated tests for the scheduler_workbench module.
Class
- SchedulerWorkbenchTestCase
- Tests the scheduling of content.
Code
public function testPublishing() {
// Define some combinations of publishing / unpublishing dates with an
// initial publication state and expected publication status and moderation
// state after scheduling.
$testcases = array(
array(
'description' => 'A published node with unpublication date in the past',
'publish_on' => 0,
'unpublish_on' => strtotime('-1 day'),
'status' => TRUE,
'expected_status' => FALSE,
'expected_state' => 'draft',
),
array(
'description' => 'An unpublished node with publication date in the past and unpublication date in the future',
'publish_on' => strtotime('-1 day'),
'unpublish_on' => strtotime('+1 day'),
'status' => FALSE,
'expected_status' => TRUE,
'expected_state' => 'published',
),
array(
'description' => 'A published node with both dates in the future',
'publish_on' => strtotime('+1 day'),
'unpublish_on' => strtotime('+2 day'),
'status' => TRUE,
'expected_status' => FALSE,
'expected_state' => 'draft',
),
);
// Test each case.
foreach ($testcases as $testcase) {
// Create a node with the settings as defined in the test case.
$settings = $testcase + array(
'type' => $this->contentType->type,
);
$node = $this
->drupalCreateNode($settings);
// Simulate a cron run.
scheduler_cron();
// Retrieve the current publication status of the node and check if it
// matches the expected result.
$current_status = db_select('node', 'n')
->fields('n', array(
'status',
))
->condition('nid', $node->nid)
->execute()
->fetchColumn();
$this
->assertEqual($testcase['expected_status'], $current_status, format_string('@description has its publication state set to %status after scheduling.', array(
'@description' => $testcase['description'],
'%status' => $testcase['expected_status'] ? 'TRUE' : 'FALSE',
)));
// Retrieve the current moderation state of the node and check if it
// matches the expected result.
$current_state = db_select('workbench_moderation_node_history', 'h')
->fields('h', array(
'state',
))
->condition('nid', $node->nid)
->range(0, 1)
->orderBy('hid', 'DESC')
->execute()
->fetchColumn();
$this
->assertEqual($testcase['expected_state'], $current_state, format_string('@description has its moderation state set to %state after scheduling', array(
'@description' => $testcase['description'],
'%state' => $testcase['expected_state'],
)));
}
}