You are here

public function RevisionSchedulerFunctionalTestCase::testDeletedRevisions in Revision scheduler 7

File

tests/RevisionSchedulerFunctionalTestCase.test, line 107

Class

RevisionSchedulerFunctionalTestCase

Code

public function testDeletedRevisions() {
  $type = $this
    ->drupalCreateContentType()->type;

  // Create a node with two revisions.
  $revision1 = $this
    ->drupalCreateNode(array(
    'type' => $type,
  ));
  $nid = $revision1->nid;
  $revision2 = clone $revision1;
  $revision2->revision = TRUE;
  node_save($revision2);
  $this
    ->assertNotEqual($revision1->vid, $revision2->vid);

  // Schedule the following operations:
  // 1. test revision 1
  // 2. delete revision 1
  // 3. test revision 1 (should be deleted when operation #2 is executed)
  // 4. test revision 2
  $operation = (object) array(
    'entity_type' => 'node',
    'entity_id' => $nid,
    'revision_id' => $revision1->vid,
    'operation' => 'test_existing',
    'time_scheduled' => 1,
  );
  revision_scheduler_operation_save($operation);
  $operation = (object) array(
    'entity_type' => 'node',
    'entity_id' => $nid,
    'revision_id' => $revision1->vid,
    'operation' => 'delete',
    'time_scheduled' => 1,
  );
  revision_scheduler_operation_save($operation);
  $operation = (object) array(
    'entity_type' => 'node',
    'entity_id' => $nid,
    'revision_id' => $revision1->vid,
    'operation' => 'test_existing',
    'time_scheduled' => 1,
  );
  revision_scheduler_operation_save($operation);
  $operation = (object) array(
    'entity_type' => 'node',
    'entity_id' => $nid,
    'revision_id' => $revision2->vid,
    'operation' => 'test_existing',
    'time_scheduled' => 1,
  );
  revision_scheduler_operation_save($operation);
  $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), 3);
  $this
    ->assertIdentical($results[0]['operation']->operation, 'test_existing');
  $this
    ->assertIdentical($results[0]['entity']->vid, $revision1->vid);
  $this
    ->assertIdentical($results[1]['operation']->operation, 'delete');
  $this
    ->assertIdentical($results[1]['entity']->vid, $revision1->vid);
  $this
    ->assertIdentical($results[2]['operation']->operation, 'test_existing');
  $this
    ->assertIdentical($results[2]['entity']->vid, $revision2->vid);
  $this
    ->assertFalse(node_load($nid, $revision1->vid, TRUE));
  $this
    ->assertTrue(node_load($nid, $revision2->vid, TRUE));
  $vids = revision_scheduler_get_all_entity_revision_ids('node', $nid);
  $this
    ->assertIdentical(count($vids), 1);
}