public function RevisionSchedulerFunctionalTestCase::testNodeRevisionScheduling in Revision scheduler 7
File
- tests/
RevisionSchedulerFunctionalTestCase.test, line 18
Class
Code
public function testNodeRevisionScheduling() {
$type = $this
->drupalCreateContentType()->type;
$account = $this
->drupalCreateUser(array(
'bypass node access',
'administer nodes',
'schedule revisions',
));
$this
->drupalLogin($account);
$vids = revision_scheduler_get_all_entity_revision_ids('node', 0);
$this
->assertIdentical(count($vids), 0);
$options = revision_scheduler_entity_revision_operation_get_options('node', NULL, $account);
$this
->assertIdentical(array_keys($options), array(
'test_new',
'test_permission',
));
$options = revision_scheduler_entity_revision_operation_get_options('node', NULL, drupal_anonymous_user());
$this
->assertIdentical(array_keys($options), array(
'test_new',
'test_anonymous',
));
$this
->drupalGet('node/add/' . $type);
$edit = array(
'title' => 'First revision',
'revision_scheduler[operation]' => 'test_new',
'revision_scheduler[time_scheduled]' => '',
);
$this
->drupalPost('node/add/' . $type, $edit, 'Save');
$this
->assertText('The revision scheduled date field is required.');
$edit['revision_scheduler[time_scheduled]'] = format_date(0, 'custom', 'Y-m-d H:i');
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertText('You cannot set a revision scheduled date in the past.');
$first_time = time();
$edit['revision_scheduler[time_scheduled]'] = format_date($first_time + 3600, 'custom', 'Y-m-d H:i');
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertText('First revision has been created.');
$node = $this
->drupalGetNodeByTitle('First revision', TRUE);
$vids = revision_scheduler_get_all_entity_revision_ids('node', $node->nid);
$this
->assertIdentical(count($vids), 1);
$options = revision_scheduler_entity_revision_operation_get_options('node', $node, $account);
$this
->assertIdentical(array_keys($options), array(
'test_existing',
'test_permission',
));
$options = revision_scheduler_entity_revision_operation_get_options('node', $node, drupal_anonymous_user());
$this
->assertIdentical(array_keys($options), array(
'test_existing',
'test_anonymous',
));
$second_time = time();
$edit = array(
'title' => 'Second revision',
'revision' => TRUE,
'revision_scheduler[operation]' => 'test_existing',
'revision_scheduler[time_scheduled]' => format_date($second_time + 3000, 'custom', 'Y-m-d H:i'),
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
$this
->assertText('Second revision has been updated.');
$node = $this
->drupalGetNodeByTitle('Second revision', TRUE);
$vids = revision_scheduler_get_all_entity_revision_ids('node', $node->nid);
$this
->assertIdentical(count($vids), 2);
$options = revision_scheduler_entity_revision_operation_get_options('node', $node, $account);
$this
->assertIdentical(array_keys($options), array(
'test_existing',
'test_permission',
));
$options = revision_scheduler_entity_revision_operation_get_options('node', $node, drupal_anonymous_user());
$this
->assertIdentical(array_keys($options), array(
'test_existing',
'test_anonymous',
));
// Set the scheduled time for all currently scheduled operations back one
// day so they can be run on cron now.
$this
->pushBackOperations();
$results = drupal_static('revision_scheduler_test', array());
$this
->assertIdentical(count($results), 0);
drupal_cron_run();
$results = drupal_static('revision_scheduler_test', array());
$this
->assertIdentical(count($results), 2);
$this
->assertIdentical($results[0]['operation']->operation, 'test_existing');
$this
->assertIdentical($results[1]['operation']->operation, 'test_new');
//$this->drupalGet('node/' . $node->nid . '/revisions');
//$this->drupalGet('node/' . $node->nid . '/revisions/schedule');
// Add a manual scheduled operation.
/*$edit = array(
'revision_id' => min($vids),
'operation' => 'test_permission',
);
$this->drupalPostAJAX('node/' . $node->nid . '/revisions/schedule/add', $edit, 'revision_id');
$third_time = time();
$edit += array(
'operation' => 'revert',
'time_scheduled' => format_date($third_time + 3600, 'custom', 'Y-m-d H:i'),
);
$this->drupalPost(NULL, $edit, 'Schedule');*/
}